Skip to content

Commit 9b60bda

Browse files
authored
Refactor integration tests to use Verify.Http (#82)
1 parent 5f58521 commit 9b60bda

File tree

78 files changed

+9040
-12454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+9040
-12454
lines changed

example/ExampleApi/Endpoints/Todos/GetExport/GetExportEndpoint.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task<Results<FileContentHttpResult, NoContent>> Handle(Cancellation
3838
return TypedResults.NoContent();
3939
}
4040

41-
string fileName = $"todos-{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}.html";
41+
string fileName = $"todos.html";
4242
string htmlContent = ExportToHtml(result);
4343

4444
byte[] fileBytes = Encoding.UTF8.GetBytes(htmlContent);
@@ -54,8 +54,6 @@ static string ExportToHtml(IEnumerable<Todo> todo)
5454
<td>{WebUtility.HtmlEncode(t.Title)}</td>
5555
<td>{WebUtility.HtmlEncode(t.Description)}</td>
5656
<td>{(t.IsCompleted ? "Yes" : "No")}</td>
57-
<td>{t.CreatedAt:yyyy-MM-dd HH:mm:ss}</td>
58-
<td>{(t.UpdatedAt.HasValue ? t.UpdatedAt.Value.ToString("yyyy-MM-dd HH:mm-ss") : "")}</td>
5957
</tr>"));
6058

6159
return $$"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
Status: 200 OK,
3+
Headers: {
4+
api-supported-versions: 1, 2
5+
},
6+
Content: {
7+
Headers: {
8+
Content-Type: application/json; charset=utf-8
9+
},
10+
Value: [
11+
{
12+
fileName: file1.txt,
13+
propertyName: property1,
14+
size: 6
15+
},
16+
{
17+
fileName: file2.txt,
18+
propertyName: property2,
19+
size: 6
20+
}
21+
]
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
Status: 200 OK,
3+
Headers: {
4+
api-supported-versions: 1, 2
5+
},
6+
Content: {
7+
Headers: {
8+
Content-Type: application/json; charset=utf-8
9+
},
10+
Value: []
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
Status: 200 OK,
3+
Headers: {
4+
api-supported-versions: 1, 2
5+
},
6+
Content: {
7+
Headers: {
8+
Content-Type: application/json; charset=utf-8
9+
},
10+
Value: [
11+
{
12+
fileName: empty1.txt,
13+
propertyName: files,
14+
size: 0
15+
},
16+
{
17+
fileName: empty2.txt,
18+
propertyName: files,
19+
size: 0
20+
}
21+
]
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
Status: 200 OK,
3+
Headers: {
4+
api-supported-versions: 1, 2
5+
},
6+
Content: {
7+
Headers: {
8+
Content-Type: application/json; charset=utf-8
9+
},
10+
Value: [
11+
{
12+
fileName: document1.pdf,
13+
propertyName: files,
14+
size: 18
15+
},
16+
{
17+
fileName: document2.txt,
18+
propertyName: files,
19+
size: 19
20+
},
21+
{
22+
fileName: image.png,
23+
propertyName: files,
24+
size: 18
25+
}
26+
]
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
Status: 200 OK,
3+
Headers: {
4+
api-supported-versions: 1, 2
5+
},
6+
Content: {
7+
Headers: {
8+
Content-Type: application/json; charset=utf-8
9+
},
10+
Value: [
11+
{
12+
fileName: single.txt,
13+
propertyName: file,
14+
size: 11
15+
}
16+
]
17+
}
18+
}

tests/ExampleApi.IntegrationTests/Endpoints/FileHandling/PostListOfFilesTests.cs

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
using System.Net;
2-
using System.Net.Http.Json;
3-
using ListOfFiles = ExampleApi.Endpoints.FileHandling.PostListOfFiles;
4-
51
namespace ExampleApi.IntegrationTests.Endpoints.FileHandling;
62

73
/// <summary>
@@ -41,19 +37,8 @@ public async Task PostListOfFiles_WithMultipleFiles_ReturnsAllFileDetails()
4137
HttpResponseMessage response = await _client.PostAsync("/api/v1/FileHandling/ListOfFiles", content, TestContext.Current.CancellationToken);
4238

4339
// Assert
44-
response.StatusCode.ShouldBe(HttpStatusCode.OK);
45-
ListOfFiles.ResponseModel[]? result = await response.Content.ReadFromJsonAsync<ListOfFiles.ResponseModel[]>(TestContext.Current.CancellationToken);
46-
result.ShouldNotBeNull();
47-
result.Length.ShouldBe(3);
48-
49-
result[0].FileName.ShouldBe("document1.pdf");
50-
result[0].Size.ShouldBe(18); // "First file content"
51-
52-
result[1].FileName.ShouldBe("document2.txt");
53-
result[1].Size.ShouldBe(19); // "Second file content"
54-
55-
result[2].FileName.ShouldBe("image.png");
56-
result[2].Size.ShouldBe(18); // "Third file content"
40+
await Verify(response)
41+
.IgnoreMember("Content-Length");
5742
}
5843

5944
[Fact]
@@ -70,12 +55,8 @@ public async Task PostListOfFiles_WithSingleFile_ReturnsSingleFileDetails()
7055
HttpResponseMessage response = await _client.PostAsync("/api/v1/FileHandling/ListOfFiles", content, TestContext.Current.CancellationToken);
7156

7257
// Assert
73-
response.StatusCode.ShouldBe(HttpStatusCode.OK);
74-
ListOfFiles.ResponseModel[]? result = await response.Content.ReadFromJsonAsync<ListOfFiles.ResponseModel[]>(TestContext.Current.CancellationToken);
75-
result.ShouldNotBeNull();
76-
result.Length.ShouldBe(1);
77-
result[0].FileName.ShouldBe("single.txt");
78-
result[0].Size.ShouldBe(11); // "Single file"
58+
await Verify(response)
59+
.IgnoreMember("Content-Length");
7960
}
8061

8162
[Fact]
@@ -91,10 +72,8 @@ public async Task PostListOfFiles_WithEmptyCollection_ReturnsEmptyArray()
9172
HttpResponseMessage response = await _client.PostAsync("/api/v1/FileHandling/ListOfFiles", content, TestContext.Current.CancellationToken);
9273

9374
// Assert
94-
response.StatusCode.ShouldBe(HttpStatusCode.OK);
95-
ListOfFiles.ResponseModel[]? result = await response.Content.ReadFromJsonAsync<ListOfFiles.ResponseModel[]>(TestContext.Current.CancellationToken);
96-
result.ShouldNotBeNull();
97-
result.ShouldBeEmpty();
75+
await Verify(response)
76+
.IgnoreMember("Content-Length");
9877
}
9978

10079
[Fact]
@@ -115,12 +94,8 @@ public async Task PostListOfFiles_WithDifferentPropertyNames_PreservesPropertyNa
11594
HttpResponseMessage response = await _client.PostAsync("/api/v1/FileHandling/ListOfFiles", content, TestContext.Current.CancellationToken);
11695

11796
// Assert
118-
response.StatusCode.ShouldBe(HttpStatusCode.OK);
119-
ListOfFiles.ResponseModel[]? result = await response.Content.ReadFromJsonAsync<ListOfFiles.ResponseModel[]>(TestContext.Current.CancellationToken);
120-
result.ShouldNotBeNull();
121-
result.Length.ShouldBe(2);
122-
result[0].PropertyName.ShouldBe("property1");
123-
result[1].PropertyName.ShouldBe("property2");
97+
await Verify(response)
98+
.IgnoreMember("Content-Length");
12499
}
125100

126101
[Fact]
@@ -141,11 +116,7 @@ public async Task PostListOfFiles_WithEmptyFiles_ReturnsZeroSizes()
141116
HttpResponseMessage response = await _client.PostAsync("/api/v1/FileHandling/ListOfFiles", content, TestContext.Current.CancellationToken);
142117

143118
// Assert
144-
response.StatusCode.ShouldBe(HttpStatusCode.OK);
145-
ListOfFiles.ResponseModel[]? result = await response.Content.ReadFromJsonAsync<ListOfFiles.ResponseModel[]>(TestContext.Current.CancellationToken);
146-
result.ShouldNotBeNull();
147-
result.Length.ShouldBe(2);
148-
result[0].Size.ShouldBe(0);
149-
result[1].Size.ShouldBe(0);
119+
await Verify(response)
120+
.IgnoreMember("Content-Length");
150121
}
151122
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
Status: 200 OK,
3+
Headers: {
4+
api-supported-versions: 1, 2
5+
},
6+
Content: {
7+
Headers: {
8+
Content-Length: 510,
9+
Content-Type: application/json; charset=utf-8
10+
},
11+
Value: {
12+
someData: Property Name Test,
13+
singleFile: {
14+
fileName: single.pdf,
15+
propertyName: SingleFile,
16+
size: 7
17+
},
18+
totalFileCount: 3,
19+
readOnlyList1: [
20+
{
21+
fileName: list1.txt,
22+
propertyName: ReadOnlyList1,
23+
size: 5
24+
}
25+
],
26+
readOnlyList2: [
27+
{
28+
fileName: list2.txt,
29+
propertyName: ReadOnlyList2,
30+
size: 5
31+
}
32+
],
33+
fileCollectionList: [
34+
{
35+
fileName: single.pdf,
36+
propertyName: SingleFile,
37+
size: 7
38+
},
39+
{
40+
fileName: list1.txt,
41+
propertyName: ReadOnlyList1,
42+
size: 5
43+
},
44+
{
45+
fileName: list2.txt,
46+
propertyName: ReadOnlyList2,
47+
size: 5
48+
}
49+
]
50+
}
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
Status: 200 OK,
3+
Headers: {
4+
api-supported-versions: 1, 2
5+
},
6+
Content: {
7+
Headers: {
8+
Content-Type: application/json; charset=utf-8
9+
},
10+
Value: {
11+
someData: Test Data,
12+
singleFile: {
13+
fileName: single.pdf,
14+
propertyName: SingleFile,
15+
size: 19
16+
},
17+
totalFileCount: 6,
18+
readOnlyList1: [
19+
{
20+
fileName: list1_file1.txt,
21+
propertyName: ReadOnlyList1,
22+
size: 12
23+
},
24+
{
25+
fileName: list1_file2.txt,
26+
propertyName: ReadOnlyList1,
27+
size: 12
28+
}
29+
],
30+
readOnlyList2: [
31+
{
32+
fileName: list2_file1.doc,
33+
propertyName: ReadOnlyList2,
34+
size: 12
35+
}
36+
],
37+
fileCollectionList: [
38+
{
39+
fileName: single.pdf,
40+
propertyName: SingleFile,
41+
size: 19
42+
},
43+
{
44+
fileName: list1_file1.txt,
45+
propertyName: ReadOnlyList1,
46+
size: 12
47+
},
48+
{
49+
fileName: list1_file2.txt,
50+
propertyName: ReadOnlyList1,
51+
size: 12
52+
},
53+
{
54+
fileName: list2_file1.doc,
55+
propertyName: ReadOnlyList2,
56+
size: 12
57+
},
58+
{
59+
fileName: collection1.png,
60+
propertyName: FileCollectionList,
61+
size: 12
62+
},
63+
{
64+
fileName: collection2.jpg,
65+
propertyName: FileCollectionList,
66+
size: 12
67+
}
68+
]
69+
}
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
Status: 200 OK,
3+
Headers: {
4+
api-supported-versions: 1, 2
5+
},
6+
Content: {
7+
Headers: {
8+
Content-Type: application/json; charset=utf-8
9+
},
10+
Value: {
11+
someData: Minimal Data,
12+
singleFile: {
13+
fileName: single.pdf,
14+
propertyName: SingleFile,
15+
size: 7
16+
},
17+
totalFileCount: 2,
18+
readOnlyList1: [
19+
{
20+
fileName: required.txt,
21+
propertyName: ReadOnlyList1,
22+
size: 8
23+
}
24+
],
25+
fileCollectionList: [
26+
{
27+
fileName: single.pdf,
28+
propertyName: SingleFile,
29+
size: 7
30+
},
31+
{
32+
fileName: required.txt,
33+
propertyName: ReadOnlyList1,
34+
size: 8
35+
}
36+
]
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)