generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProductFunctionTest.cs
More file actions
85 lines (76 loc) · 3.27 KB
/
ProductFunctionTest.cs
File metadata and controls
85 lines (76 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Timers;
using Moq;
using NUnit.Framework;
using System;
using System.Net;
using System.Net.Http;
using UnitTestEx.Expectations;
using UnitTestEx.Function;
namespace UnitTestEx.NUnit.Test
{
[TestFixture]
public class ProductFunctionTest
{
[Test]
public void Notfound()
{
var mcf = MockHttpClientFactory.Create();
mcf.CreateClient("XXX", new Uri("https://d365test"))
.Request(HttpMethod.Get, "products/xyz").Respond.With(HttpStatusCode.NotFound);
using var test = FunctionTester.Create<Startup>();
test.ReplaceHttpClientFactory(mcf)
.HttpTrigger<ProductFunction>()
.Run(f => f.Run(test.CreateHttpRequest(HttpMethod.Get, "product/xyz"), "xyz", test.Logger))
.AssertNotFound();
}
[Test]
public void Success()
{
var mcf = MockHttpClientFactory.Create();
mcf.CreateClient("XXX", new Uri("https://d365test"))
.Request(HttpMethod.Get, "products/abc").Respond.WithJson(new { id = "Abc", description = "A blue carrot" });
using var test = FunctionTester.Create<Startup>();
test.ReplaceHttpClientFactory(mcf)
.HttpTrigger<ProductFunction>()
.ExpectLogContains("C# HTTP trigger function processed a request.")
.Run(f => f.Run(test.CreateHttpRequest(HttpMethod.Get, "product/abc"), "abc", test.Logger))
.AssertOK()
.AssertValue(new { id = "Abc", description = "A blue carrot" });
}
[Test]
public void Success2()
{
var mcf = MockHttpClientFactory.Create();
mcf.CreateClient("XXX", new Uri("https://d365test"))
.Request(HttpMethod.Get, "products/abc").Respond.WithJson(new { id = "Abc", description = "A blue carrot" });
using var test = FunctionTester.Create<Startup>();
test.ReplaceHttpClientFactory(mcf)
.Type<ProductFunction>()
.Run(f => f.Run(test.CreateHttpRequest(HttpMethod.Get, "person/abc"), "abc", test.Logger))
.ToActionResultAssertor()
.AssertOK()
.AssertValue(new { id = "Abc", description = "A blue carrot" });
}
[Test]
public void Exception()
{
var mcf = MockHttpClientFactory.Create();
using var test = FunctionTester.Create<Startup>();
test.ReplaceHttpClientFactory(mcf)
.HttpTrigger<ProductFunction>()
.Run(f => f.Run(test.CreateHttpRequest(HttpMethod.Get, "product/exception"), "exception", test.Logger))
.AssertException<InvalidOperationException>("An unexpected exception occured.");
}
[Test]
public void TimerTriggered()
{
using var test = FunctionTester.Create<Startup>();
test.Type<ProductFunction>()
.ExpectLogContains("(DI)")
.ExpectLogContains("(method)")
.Run(f => f.DailyRun(new TimerInfo(new DailySchedule("2:00:00"), It.IsAny<ScheduleStatus>(), false), test.Logger))
.AssertSuccess();
}
}
}