-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47912da
commit eca75f0
Showing
5 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Testing/Acceptance/Modules/ErrorHandling/HtmlErrorMapperTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Net; | ||
using GenHTTP.Api.Content; | ||
using GenHTTP.Api.Protocol; | ||
using GenHTTP.Modules.ErrorHandling; | ||
using GenHTTP.Modules.Functional; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GenHTTP.Testing.Acceptance.Modules.ErrorHandling; | ||
|
||
[TestClass] | ||
public class HtmlErrorMapperTest | ||
{ | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestNotFound(TestEngine engine) | ||
{ | ||
await using var host = await TestHost.RunAsync(Inline.Create().Add(ErrorHandler.Html()), engine: engine); | ||
|
||
using var response = await host.GetResponseAsync(); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.NotFound); | ||
} | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestGeneralError(TestEngine engine) | ||
{ | ||
var handler = Inline.Create() | ||
.Get(() => DoThrow(new Exception("Oops"))) | ||
.Add(ErrorHandler.Html()); | ||
|
||
await using var host = await TestHost.RunAsync(handler, engine: engine); | ||
|
||
using var response = await host.GetResponseAsync(); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.InternalServerError); | ||
} | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestProviderError(TestEngine engine) | ||
{ | ||
var handler = Inline.Create() | ||
.Get(() => DoThrow(new ProviderException(ResponseStatus.Locked, "Locked up!"))) | ||
.Add(ErrorHandler.Html()); | ||
|
||
await using var host = await TestHost.RunAsync(handler, engine: engine); | ||
|
||
using var response = await host.GetResponseAsync(); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.Locked); | ||
} | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestNoTraceInProduction(TestEngine engine) | ||
{ | ||
var handler = Inline.Create() | ||
.Get(() => DoThrow(new Exception("Oops"))) | ||
.Add(ErrorHandler.Html()); | ||
|
||
await using var host = await TestHost.RunAsync(handler, development: false, engine: engine); | ||
|
||
using var response = await host.GetResponseAsync(); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.InternalServerError); | ||
} | ||
|
||
private static void DoThrow(Exception e) | ||
{ | ||
throw e; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters