|
8 | 8 | using Microsoft.AspNetCore.Builder;
|
9 | 9 | using Microsoft.AspNetCore.Hosting;
|
10 | 10 | using Microsoft.AspNetCore.Http;
|
| 11 | +using Microsoft.AspNetCore.Mvc; |
11 | 12 | using Microsoft.AspNetCore.TestHost;
|
12 | 13 | using Microsoft.Extensions.DependencyInjection;
|
13 | 14 | using Microsoft.Extensions.Hosting;
|
@@ -283,4 +284,38 @@ public async Task Reexecute_WorksAfterUseRoutingWithGlobalRouteBuilder()
|
283 | 284 | var content = await response.Content.ReadAsStringAsync();
|
284 | 285 | Assert.Equal("errorPage", content);
|
285 | 286 | }
|
| 287 | + |
| 288 | + [Fact] |
| 289 | + public async Task SkipStatusCodePages_SupportsEndpoints() |
| 290 | + { |
| 291 | + var builder = WebApplication.CreateBuilder(); |
| 292 | + builder.WebHost.UseTestServer(); |
| 293 | + await using var app = builder.Build(); |
| 294 | + |
| 295 | + app.UseRouting(); |
| 296 | + |
| 297 | + app.UseStatusCodePages(); |
| 298 | + |
| 299 | + app.UseEndpoints(endpoints => |
| 300 | + { |
| 301 | + endpoints.MapGet("/", [SkipStatusCodePages] (c) => |
| 302 | + { |
| 303 | + c.Response.StatusCode = 404; |
| 304 | + return Task.CompletedTask; |
| 305 | + }); |
| 306 | + }); |
| 307 | + |
| 308 | + app.Run((context) => |
| 309 | + { |
| 310 | + throw new InvalidOperationException("Invalid input provided."); |
| 311 | + }); |
| 312 | + |
| 313 | + await app.StartAsync(); |
| 314 | + |
| 315 | + using var server = app.GetTestServer(); |
| 316 | + var client = server.CreateClient(); |
| 317 | + var response = await client.GetAsync("/"); |
| 318 | + var content = await response.Content.ReadAsStringAsync(); |
| 319 | + Assert.Empty(content); |
| 320 | + } |
286 | 321 | }
|
0 commit comments