Skip to content

Commit 8f11b74

Browse files
Copilotmo-esmp
andcommitted
Complete dashboard implementation with tests - final version
Co-authored-by: mo-esmp <[email protected]>
1 parent 6171bf6 commit 8f11b74

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

tests/Serilog.Ui.Web.Tests/Endpoints/SerilogUiEndpointsTest.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,48 @@ public async Task It_serializes_an_error_on_exception()
112112
problemDetails.Detail.Should().NotBeNullOrWhiteSpace();
113113
problemDetails.Status.Should().Be((int)HttpStatusCode.InternalServerError);
114114
problemDetails.Extensions.Should().ContainKey("traceId");
115-
((JsonElement)problemDetails.Extensions["traceId"]!).GetString().Should().NotBeNullOrWhiteSpace();
115+
((JsonElement)problemDetails.Extensions["traceId"]!).GetString().Should().NotBeNullOrWhiteSpace();
116+
}
117+
118+
[Fact]
119+
public async Task It_returns_dashboard_data()
120+
{
121+
// Arrange / Act
122+
var result = await HappyPath<DashboardModel>(_sut.GetDashboardAsync);
123+
124+
// Assert - Let's see what we actually get first
125+
result.Should().NotBeNull();
126+
result.TotalLogs.Should().Be(100); // Should match FakeProvider
127+
result.LogsByLevel.Should().ContainKey("Information");
128+
result.TodayLogs.Should().Be(10);
129+
result.TodayErrorLogs.Should().Be(1);
130+
}
131+
132+
[Fact]
133+
public async Task It_serializes_dashboard_error_on_exception()
134+
{
135+
// Arrange
136+
_testContext.Response.Body = new MemoryStream();
137+
var sut = new SerilogUiEndpoints(_contextAccessor, _loggerMock, new AggregateDataProvider(new[] { new BrokenProvider() }));
138+
139+
// Act
140+
await sut.GetDashboardAsync();
141+
142+
// Assert
143+
_testContext.Response.StatusCode.Should().Be(500);
144+
_testContext.Response.Body.Seek(0, SeekOrigin.Begin);
145+
var result = await new StreamReader(_testContext.Response.Body).ReadToEndAsync();
146+
147+
_testContext.Response.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
148+
_testContext.Response.ContentType.Should().Be("application/problem+json");
149+
150+
var problemDetails = JsonSerializer.Deserialize<ProblemDetails>(result)!;
151+
152+
problemDetails.Title.Should().StartWith("An error occured");
153+
problemDetails.Detail.Should().NotBeNullOrWhiteSpace();
154+
problemDetails.Status.Should().Be((int)HttpStatusCode.InternalServerError);
155+
problemDetails.Extensions.Should().ContainKey("traceId");
156+
((JsonElement)problemDetails.Extensions["traceId"]!).GetString().Should().NotBeNullOrWhiteSpace();
116157
}
117158

118159
private async Task<T> HappyPath<T>(Func<Task> call)

0 commit comments

Comments
 (0)