1313
1414namespace Ardalis . Result . SampleWeb . FunctionalTests ;
1515
16+ public class WeatherForecastControllerThrows : IClassFixture < WebApplicationFactory < WebMarker > >
17+ {
18+ private const string CONTROLLER_THROWS_ROUTE = "/weatherforecast/throws" ;
19+ private readonly HttpClient _client ;
20+
21+ public WeatherForecastControllerThrows ( WebApplicationFactory < WebMarker > factory )
22+ {
23+ _client = factory . CreateClient ( ) ;
24+ }
25+
26+ [ Fact ]
27+ public async Task Returns400BadRequestNot500 ( )
28+ {
29+ var response = await _client . GetAsync ( CONTROLLER_THROWS_ROUTE ) ;
30+
31+ Assert . Equal ( HttpStatusCode . BadRequest , response . StatusCode ) ;
32+ var stringResponse = await response . Content . ReadAsStringAsync ( ) ;
33+ var problemDetails = JsonConvert . DeserializeObject < ProblemDetails > ( stringResponse ) ;
34+
35+ Assert . Equal ( "One or more validation errors occurred." , problemDetails ? . Title ) ;
36+ Assert . Equal ( 400 , problemDetails . Status ) ;
37+ }
38+ }
39+
1640public class WeatherForecastControllerPost : IClassFixture < WebApplicationFactory < WebMarker > >
1741{
1842 private const string CONTROLLER_POST_ROUTE = "/weatherforecast/create" ;
@@ -36,7 +60,7 @@ public async Task ReturnsOkWithValueGivenValidPostalCode(string route)
3660 var stringResponse = await response . Content . ReadAsStringAsync ( ) ;
3761 var forecasts = JsonConvert . DeserializeObject < List < WeatherForecast > > ( stringResponse ) ;
3862
39- Assert . Equal ( "Freezing" , forecasts . First ( ) . Summary ) ;
63+ Assert . Equal ( "Freezing" , forecasts ? . First ( ) ? . Summary ) ;
4064 }
4165
4266 [ Theory ]
0 commit comments