Skip to content

Commit 247a948

Browse files
committed
adjust functional test name and better isolate sample changes
1 parent dca15d7 commit 247a948

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/Middleware/Diagnostics/test/FunctionalTests/ProblemDetailsExceptionHandlerSampleTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public async Task ExceptionHandlerPage_ProducesProblemDetails()
3737
}
3838

3939
[Fact]
40-
public async Task StatusCodeSelector_ProducesProblemDetailsWith403()
40+
public async Task StatusCodeSelector_ProducesProblemDetailsWithCustomStatusCode()
4141
{
4242
// Arrange
43-
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/throw/conflict");
43+
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/throw2/conflict");
4444
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
4545

4646
// Act

src/Middleware/Diagnostics/test/testassets/ExceptionHandlerSample/StartupWithProblemDetails.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,28 @@ public void ConfigureServices(IServiceCollection services)
1616

1717
public void Configure(IApplicationBuilder app)
1818
{
19-
// Configure the error handler to produces a ProblemDetails.
20-
app.UseExceptionHandler(new ExceptionHandlerOptions
19+
// The broken section of our application.
20+
app.Map("/throw", throwApp =>
2121
{
22-
StatusCodeSelector = ex => ex is ConflictException
23-
? StatusCodes.Status409Conflict
24-
: StatusCodes.Status500InternalServerError,
22+
// Configure the error handler to produce ProblemDetails.
23+
throwApp.UseExceptionHandler();
24+
throwApp.Run(_ => throw new Exception("Application Exception"));
2525
});
2626

27-
// The broken section of our application.
28-
app.Map("/throw", throwApp =>
27+
app.Map("/throw2", throwApp =>
2928
{
29+
// Configure the error handler to produce ProblemDetails with a mapped status code
30+
throwApp.UseExceptionHandler(new ExceptionHandlerOptions
31+
{
32+
StatusCodeSelector = ex => ex is ConflictException
33+
? StatusCodes.Status409Conflict
34+
: StatusCodes.Status500InternalServerError,
35+
});
36+
3037
throwApp.Map("/conflict", throwConflictApp =>
3138
{
3239
throwConflictApp.Run(_ => throw new ConflictException("Conflict Exception"));
3340
});
34-
35-
throwApp.Run(_ => throw new Exception("Application Exception"));
3641
});
3742

3843
app.UseStaticFiles();
@@ -43,7 +48,7 @@ public void Configure(IApplicationBuilder app)
4348
context.Response.ContentType = "text/html";
4449
await context.Response.WriteAsync("<html><body>Welcome to the sample<br><br>\r\n");
4550
await context.Response.WriteAsync("Click here to throw an exception: <a href=\"/throw\">throw</a><br>\r\n");
46-
await context.Response.WriteAsync("Click here to throw a conflict exception: <a href=\"/throw/conflict\">throw conflict</a>\r\n");
51+
await context.Response.WriteAsync("Click here to throw a conflict exception: <a href=\"/throw2/conflict\">throw conflict</a>\r\n");
4752
await context.Response.WriteAsync("</body></html>\r\n");
4853
});
4954
}

0 commit comments

Comments
 (0)