@@ -313,4 +313,80 @@ public async Task SkipStatusCodePages_SupportsEndpoints()
313
313
var content = await response . Content . ReadAsStringAsync ( ) ;
314
314
Assert . Empty ( content ) ;
315
315
}
316
+
317
+ [ Fact ]
318
+ public async Task SkipStatusCodePages_SupportsSkipIfUsedBeforeRouting ( )
319
+ {
320
+ using var host = new HostBuilder ( )
321
+ . ConfigureWebHost ( builder =>
322
+ {
323
+ builder . UseTestServer ( )
324
+ . ConfigureServices ( services => services . AddRouting ( ) )
325
+ . Configure ( app =>
326
+ {
327
+ app . UseStatusCodePagesWithReExecute ( "/status" ) ;
328
+ app . UseRouting ( ) ;
329
+
330
+ app . UseEndpoints ( endpoints =>
331
+ {
332
+ endpoints . MapGet ( "/skip" , [ SkipStatusCodePages ] ( c ) =>
333
+ {
334
+ c . Response . StatusCode = 400 ;
335
+ return Task . CompletedTask ;
336
+ } ) ;
337
+
338
+ endpoints . MapGet ( "/status" , ( HttpResponse response ) => $ "Status: { response . StatusCode } ") ;
339
+ } ) ;
340
+
341
+ app . Run ( _ => throw new InvalidOperationException ( "Invalid input provided." ) ) ;
342
+ } ) ;
343
+ } ) . Build ( ) ;
344
+
345
+ await host . StartAsync ( ) ;
346
+
347
+ using var server = host . GetTestServer ( ) ;
348
+ var client = server . CreateClient ( ) ;
349
+ var response = await client . GetAsync ( "/skip" ) ;
350
+ var content = await response . Content . ReadAsStringAsync ( ) ;
351
+
352
+ Assert . Empty ( content ) ;
353
+ }
354
+
355
+ [ Fact ]
356
+ public async Task SkipStatusCodePages_WorksIfUsedBeforeRouting ( )
357
+ {
358
+ using var host = new HostBuilder ( )
359
+ . ConfigureWebHost ( builder =>
360
+ {
361
+ builder . UseTestServer ( )
362
+ . ConfigureServices ( services => services . AddRouting ( ) )
363
+ . Configure ( app =>
364
+ {
365
+ app . UseStatusCodePagesWithReExecute ( "/status" ) ;
366
+ app . UseRouting ( ) ;
367
+
368
+ app . UseEndpoints ( endpoints =>
369
+ {
370
+ endpoints . MapGet ( "/" , ( c ) =>
371
+ {
372
+ c . Response . StatusCode = 400 ;
373
+ return Task . CompletedTask ;
374
+ } ) ;
375
+
376
+ endpoints . MapGet ( "/status" , ( HttpResponse response ) => $ "Status: { response . StatusCode } ") ;
377
+ } ) ;
378
+
379
+ app . Run ( _ => throw new InvalidOperationException ( "Invalid input provided." ) ) ;
380
+ } ) ;
381
+ } ) . Build ( ) ;
382
+
383
+ await host . StartAsync ( ) ;
384
+
385
+ using var server = host . GetTestServer ( ) ;
386
+ var client = server . CreateClient ( ) ;
387
+ var response = await client . GetAsync ( "/" ) ;
388
+ var content = await response . Content . ReadAsStringAsync ( ) ;
389
+
390
+ Assert . Equal ( "Status: 400" , content ) ;
391
+ }
316
392
}
0 commit comments