-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathDeveloperModeTests.cs
More file actions
55 lines (40 loc) · 1.68 KB
/
DeveloperModeTests.cs
File metadata and controls
55 lines (40 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using GenHTTP.Api.Content;
using GenHTTP.Api.Protocol;
using GenHTTP.Modules.Layouting;
namespace GenHTTP.Testing.Acceptance.Engine;
[TestClass]
public sealed class DeveloperModeTests
{
/// <summary>
/// As a developer of a web project, I would like to see exceptions rendered
/// in the browser, so that I can trace an error more quickly
/// </summary>
[TestMethod]
[MultiEngineTest]
public async Task TestExceptionsWithTrace(TestEngine engine)
{
await using var runner = new TestHost(Layout.Create().Build(), engine: engine);
var router = Layout.Create().Index(new ThrowingProvider().Wrap());
await runner.Host.Handler(router).Development().StartAsync();
using var response = await runner.GetResponseAsync();
Assert.Contains("at GenHTTP", await response.GetContentAsync());
}
/// <summary>
/// As a devops member, I do not want an web application to leak internal
/// implementation detail with exception messages
/// </summary>
[TestMethod]
[MultiEngineTest]
public async Task TestExceptionsWithNoTrace(TestEngine engine)
{
var router = Layout.Create().Index(new ThrowingProvider().Wrap());
await using var runner = await TestHost.RunAsync(router, development: false, engine: engine);
using var response = await runner.GetResponseAsync();
Assert.DoesNotContain("at GenHTTP", await response.GetContentAsync());
}
private class ThrowingProvider : IHandler
{
public ValueTask PrepareAsync() => ValueTask.CompletedTask;
public ValueTask<IResponse?> HandleAsync(IRequest request) => throw new InvalidOperationException("Nope!");
}
}