forked from IntelliTect/EssentialCSharp.Web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListingSourceCodeControllerTests.cs
More file actions
107 lines (84 loc) · 3.52 KB
/
ListingSourceCodeControllerTests.cs
File metadata and controls
107 lines (84 loc) · 3.52 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
using System.Net;
using System.Net.Http.Json;
using EssentialCSharp.Web.Models;
namespace EssentialCSharp.Web.Tests;
public class ListingSourceCodeControllerTests
{
[Fact]
public async Task GetListing_WithValidChapterAndListing_Returns200WithContent()
{
// Arrange
using WebApplicationFactory factory = new();
HttpClient client = factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/1/listing/1");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
ListingSourceCodeResponse? result = await response.Content.ReadFromJsonAsync<ListingSourceCodeResponse>();
Assert.NotNull(result);
Assert.Equal(1, result.ChapterNumber);
Assert.Equal(1, result.ListingNumber);
Assert.NotEmpty(result.FileExtension);
Assert.NotEmpty(result.Content);
}
[Fact]
public async Task GetListing_WithInvalidChapter_Returns404()
{
// Arrange
using WebApplicationFactory factory = new();
HttpClient client = factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/999/listing/1");
// Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
[Fact]
public async Task GetListing_WithInvalidListing_Returns404()
{
// Arrange
using WebApplicationFactory factory = new();
HttpClient client = factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/1/listing/999");
// Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
[Fact]
public async Task GetListingsByChapter_WithValidChapter_ReturnsMultipleListings()
{
// Arrange
using WebApplicationFactory factory = new();
HttpClient client = factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/1");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
List<ListingSourceCodeResponse>? results = await response.Content.ReadFromJsonAsync<List<ListingSourceCodeResponse>>();
Assert.NotNull(results);
Assert.NotEmpty(results);
// Verify all results are from chapter 1
Assert.All(results, r => Assert.Equal(1, r.ChapterNumber));
// Verify results are ordered by listing number
Assert.Equal(results.OrderBy(r => r.ListingNumber).ToList(), results);
// Verify each listing has required properties
Assert.All(results, r =>
{
Assert.NotEmpty(r.FileExtension);
Assert.NotEmpty(r.Content);
});
}
[Fact]
public async Task GetListingsByChapter_WithInvalidChapter_ReturnsEmptyList()
{
// Arrange
using WebApplicationFactory factory = new();
HttpClient client = factory.CreateClient();
// Act
using HttpResponseMessage response = await client.GetAsync("/api/ListingSourceCode/chapter/999");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
List<ListingSourceCodeResponse>? results = await response.Content.ReadFromJsonAsync<List<ListingSourceCodeResponse>>();
Assert.NotNull(results);
Assert.Empty(results);
}
}