@@ -1447,6 +1447,62 @@ public void ConfigurationCanBeReloaded()
1447
1447
Assert . NotEqual ( value0 , value1 ) ;
1448
1448
}
1449
1449
1450
+ [ Fact ]
1451
+ public async Task DeveloperExceptionPageIsOnByDefaltInDevelopment ( )
1452
+ {
1453
+ var builder = WebApplication . CreateBuilder ( new WebApplicationOptions ( ) { EnvironmentName = Environments . Development } ) ;
1454
+ builder . WebHost . UseTestServer ( ) ;
1455
+ await using var app = builder . Build ( ) ;
1456
+
1457
+ app . MapGet ( "/" , void ( ) => throw new InvalidOperationException ( "BOOM" ) ) ;
1458
+
1459
+ await app . StartAsync ( ) ;
1460
+
1461
+ var client = app . GetTestClient ( ) ;
1462
+
1463
+ var response = await client . GetAsync ( "/" ) ;
1464
+
1465
+ Assert . False ( response . IsSuccessStatusCode ) ;
1466
+ Assert . Equal ( HttpStatusCode . InternalServerError , response . StatusCode ) ;
1467
+ Assert . Contains ( "BOOM" , await response . Content . ReadAsStringAsync ( ) ) ;
1468
+ Assert . Contains ( "text/plain" , response . Content . Headers . ContentType . MediaType ) ;
1469
+ }
1470
+
1471
+ [ Fact ]
1472
+ public async Task DeveloperExceptionPageDoesNotGetCaughtByStartupFilters ( )
1473
+ {
1474
+ var builder = WebApplication . CreateBuilder ( new WebApplicationOptions ( ) { EnvironmentName = Environments . Development } ) ;
1475
+ builder . WebHost . UseTestServer ( ) ;
1476
+ builder . Services . AddSingleton < IStartupFilter , ThrowingStartupFilter > ( ) ;
1477
+ await using var app = builder . Build ( ) ;
1478
+
1479
+ await app . StartAsync ( ) ;
1480
+
1481
+ var client = app . GetTestClient ( ) ;
1482
+
1483
+ var ex = await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => client . GetAsync ( "/" ) ) ;
1484
+
1485
+ Assert . Equal ( "BOOM Filter" , ex . Message ) ;
1486
+ }
1487
+
1488
+ [ Fact ]
1489
+ public async Task DeveloperExceptionPageIsNotOnInProduction ( )
1490
+ {
1491
+ var builder = WebApplication . CreateBuilder ( new WebApplicationOptions ( ) { EnvironmentName = Environments . Production } ) ;
1492
+ builder . WebHost . UseTestServer ( ) ;
1493
+ await using var app = builder . Build ( ) ;
1494
+
1495
+ app . MapGet ( "/" , void ( ) => throw new InvalidOperationException ( "BOOM" ) ) ;
1496
+
1497
+ await app . StartAsync ( ) ;
1498
+
1499
+ var client = app . GetTestClient ( ) ;
1500
+
1501
+ var ex = await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => client . GetAsync ( "/" ) ) ;
1502
+
1503
+ Assert . Equal ( "BOOM" , ex . Message ) ;
1504
+ }
1505
+
1450
1506
public class RandomConfigurationSource : IConfigurationSource
1451
1507
{
1452
1508
public IConfigurationProvider Build ( IConfigurationBuilder builder )
0 commit comments