-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTests.cs
More file actions
97 lines (78 loc) · 2.39 KB
/
Tests.cs
File metadata and controls
97 lines (78 loc) · 2.39 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
[TestFixture]
public class Tests
{
#region VerifyGetRequest
[Test]
public async Task VerifyGetRequest()
{
var mock = new HttpMock();
mock.ForGet()
.ForHttps()
.ForHost("api.example.com")
.WithPath("/api/users/123")
.RespondsWithJsonContent(new { id = 123, name = "John" });
var client = mock.GetClient();
await client.GetAsync("https://api.example.com/api/users/123");
await Verify(mock);
}
#endregion
#region VerifyPostRequest
[Test]
public async Task VerifyPostRequest()
{
var mock = new HttpMock();
mock.ForPost()
.ForHttps()
.ForHost("api.example.com")
.WithPath("/api/users")
.RespondsWithStatus(System.Net.HttpStatusCode.Created);
var client = mock.GetClient();
await client.PostAsync(
"https://api.example.com/api/users",
new StringContent(
"""{"name":"Jane"}""",
Encoding.UTF8,
"application/json"));
await Verify(mock);
}
#endregion
#region VerifyRequestCollection
[Test]
public async Task VerifyRequestCollection()
{
var mock = new HttpMock();
var requests = new RequestCollection();
mock.ForGet()
.ForHttps()
.ForHost("api.example.com")
.WithPath("/api/users/*")
.CollectingRequestsIn(requests)
.RespondsWithJsonContent(new { id = 1, name = "John" });
var client = mock.GetClient();
await client.GetAsync("https://api.example.com/api/users/1");
await client.GetAsync("https://api.example.com/api/users/2");
await Verify(requests);
}
#endregion
#region ScrubBody
[Test]
public async Task ScrubBody()
{
var mock = new HttpMock();
mock.ForPost()
.ForHttps()
.ForHost("api.example.com")
.WithPath("/api/users")
.RespondsWithStatus(System.Net.HttpStatusCode.Created);
var client = mock.GetClient();
await client.PostAsync(
"https://api.example.com/api/users",
new StringContent(
"""{"name":"Jane"}""",
Encoding.UTF8,
"application/json"));
await Verify(mock)
.ScrubMember("Body");
}
#endregion
}