generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPersonFunctionTest.cs
More file actions
131 lines (120 loc) · 5.18 KB
/
PersonFunctionTest.cs
File metadata and controls
131 lines (120 loc) · 5.18 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using NUnit.Framework;
using System.Net.Http;
using System.Threading.Tasks;
using UnitTestEx.Function;
namespace UnitTestEx.NUnit.Test
{
[TestFixture]
public class PersonFunctionTest
{
[Test]
public async Task NoData()
{
using var test = FunctionTester.Create<Startup>();
(await test.HttpTrigger<PersonFunction>()
.WithNoRouteCheck()
.RunAsync(f => f.Run(test.CreateHttpRequest(HttpMethod.Get, "person"), test.Logger)))
.AssertOK()
.AssertValue("This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.");
}
[Test]
public void QueryString()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.WithNoRouteCheck()
.Run(f => f.Run(test.CreateHttpRequest(HttpMethod.Get, "person?name=Trevor"), test.Logger))
.AssertOK()
.AssertValue("Hello, Trevor. This HTTP triggered function executed successfully.");
}
[Test]
public void WithBody()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.WithNoRouteCheck()
.Run(f => f.Run(test.CreateJsonHttpRequest(HttpMethod.Get, "person", new { name = "Jane" }), test.Logger))
.AssertOK()
.AssertValue("Hello, Jane. This HTTP triggered function executed successfully.");
}
[Test]
public void BadRequest1()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.WithNoMethodCheck()
.WithNoRouteCheck()
.Run(f => f.Run(test.CreateJsonHttpRequest(HttpMethod.Delete, "person", new { name = "Brian" }), test.Logger))
.AssertBadRequest()
.AssertErrors("Name cannot be Brian.");
}
[Test]
public void BadRequest2()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.WithNoRouteCheck()
.Run(f => f.Run(test.CreateJsonHttpRequest(HttpMethod.Post, "person", new { name = "Brian" }), test.Logger))
.AssertBadRequest()
.AssertErrors(new ApiError("name", "Name cannot be Brian."));
}
[Test]
public void ValidJson()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.WithNoRouteCheck()
.Run(f => f.Run(test.CreateJsonHttpRequest(HttpMethod.Get, "person", new { name = "Rachel" }), test.Logger))
.AssertOK()
.AssertValue(new { FirstName = "Rachel", LastName = "Smith" });
}
[Test]
public void ValidJsonResource()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.WithNoRouteCheck()
.Run(f => f.Run(test.CreateJsonHttpRequest(HttpMethod.Get, "person", new { name = "Rachel" }), test.Logger))
.AssertOK()
.AssertValueFromJsonResource<Person>("FunctionTest-ValidJsonResource.json");
}
[Test]
public void ValueVsHttpRequestObject()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.Run(f => f.RunWithValue(new Person { FirstName = "Rachel", LastName = "Smith" }, test.Logger))
.AssertOK()
.AssertValue(new { first = "Rachel", last = "Smith" });
}
[Test]
public void ValueVsHttpRequestContent()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.Run(f => f.RunWithContent(new Person { FirstName = "Rachel", LastName = "Smith" }, test.Logger))
.AssertOK()
.AssertValue(new { first = "Rachel", last = "Smith" });
}
[Test]
public void WithPathAndQueryCheck()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.WithRouteCheck(Azure.Functions.RouteCheckOption.Query)
.Run(f => f.RunWithQuery(test.CreateHttpRequest(HttpMethod.Get, "https://blah/api/persons?name=Damien"), "Damien", test.Logger))
.AssertOK()
.AssertValue(new { name = "Damien" });
}
[Test]
public void WithPathAndQueryStartsWithCheck()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<PersonFunction>()
.WithRouteCheck(Azure.Functions.RouteCheckOption.QueryStartsWith)
.Run(f => f.RunWithQuery(test.CreateHttpRequest(HttpMethod.Get, "https://blah/api/persons?name=Damien&$order=name"), "Damien", test.Logger))
.AssertOK()
.AssertValue(new { name = "Damien" });
}
}
}