-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathListingSourceCodeControllerTests.cs
More file actions
106 lines (84 loc) · 3.57 KB
/
ListingSourceCodeControllerTests.cs
File metadata and controls
106 lines (84 loc) · 3.57 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
using System.Net;
using System.Net.Http.Json;
using EssentialCSharp.Web.Models;
namespace EssentialCSharp.Web.Tests;
public class ListingSourceCodeControllerTests : IntegrationTestBase
{
[Test]
public async Task GetListing_WithValidChapterAndListing_Returns200WithContent()
{
// Arrange
HttpClient client = Factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/1/listing/1");
// Assert
await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK);
ListingSourceCodeResponse? result = await response.Content.ReadFromJsonAsync<ListingSourceCodeResponse>();
await Assert.That(result).IsNotNull();
using (Assert.Multiple())
{
await Assert.That(result.ChapterNumber).IsEqualTo(1);
await Assert.That(result.ListingNumber).IsEqualTo(1);
await Assert.That(result.FileExtension).IsNotEmpty();
await Assert.That(result.Content).IsNotEmpty();
}
}
[Test]
public async Task GetListing_WithInvalidChapter_Returns404()
{
// Arrange
HttpClient client = Factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/999/listing/1");
// Assert
await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.NotFound);
}
[Test]
public async Task GetListing_WithInvalidListing_Returns404()
{
// Arrange
HttpClient client = Factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/1/listing/999");
// Assert
await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.NotFound);
}
[Test]
public async Task GetListingsByChapter_WithValidChapter_ReturnsMultipleListings()
{
// Arrange
HttpClient client = Factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/1");
// Assert
await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK);
List<ListingSourceCodeResponse>? results = await response.Content.ReadFromJsonAsync<List<ListingSourceCodeResponse>>();
await Assert.That(results).IsNotNull();
await Assert.That(results).IsNotEmpty();
// Verify results are ordered by listing number
await Assert.That(results).IsOrderedBy(r => r.ListingNumber);
// Verify all results are from chapter 1 and have required properties
foreach (var r in results)
{
using (Assert.Multiple())
{
await Assert.That(r.ChapterNumber).IsEqualTo(1);
await Assert.That(r.FileExtension).IsNotEmpty();
await Assert.That(r.Content).IsNotEmpty();
}
}
}
[Test]
public async Task GetListingsByChapter_WithInvalidChapter_ReturnsEmptyList()
{
// Arrange
HttpClient client = Factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/999");
// Assert
await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK);
List<ListingSourceCodeResponse>? results = await response.Content.ReadFromJsonAsync<List<ListingSourceCodeResponse>>();
await Assert.That(results).IsNotNull();
await Assert.That(results).IsEmpty();
}
}