-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPersonFunctionTest.cs
More file actions
108 lines (99 loc) · 4.28 KB
/
PersonFunctionTest.cs
File metadata and controls
108 lines (99 loc) · 4.28 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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net.Http;
using System.Threading.Tasks;
using UnitTestEx.Function;
namespace UnitTestEx.MSTest.Test
{
[TestClass]
public class PersonFunctionTest
{
[TestMethod]
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.");
}
[TestMethod]
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.");
}
[TestMethod]
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.");
}
[TestMethod]
public void BadRequest1()
{
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("Name cannot be Brian.");
}
[TestMethod]
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."));
}
[TestMethod]
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" });
}
[TestMethod]
public void ValidJsonResource()
{
using var test = FunctionTester.Create<Startup>().UseJsonSerializer(new Json.JsonSerializer());
test.HttpTrigger<PersonFunction>()
.WithNoRouteCheck()
.Run(f => f.Run(test.CreateJsonHttpRequest(HttpMethod.Get, "person", new { name = "Rachel" }), test.Logger))
.AssertOK()
.AssertValueFromJsonResource<Person>("FunctionTest-ValidJsonResource.json");
}
[TestMethod]
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" });
}
[TestMethod]
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" });
}
}
}