@@ -112,7 +112,48 @@ public async Task It_serializes_an_error_on_exception()
112
112
problemDetails . Detail . Should ( ) . NotBeNullOrWhiteSpace ( ) ;
113
113
problemDetails . Status . Should ( ) . Be ( ( int ) HttpStatusCode . InternalServerError ) ;
114
114
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 ( ) ;
116
157
}
117
158
118
159
private async Task < T > HappyPath < T > ( Func < Task > call )
0 commit comments