-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathMainHandlerTests.cs
More file actions
61 lines (44 loc) · 1.61 KB
/
MainHandlerTests.cs
File metadata and controls
61 lines (44 loc) · 1.61 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
56
57
58
59
60
61
using GenHTTP.Api.Content;
using GenHTTP.Api.Protocol;
using GenHTTP.Modules.Layouting;
using StringContent = GenHTTP.Modules.IO.Strings.StringContent;
namespace GenHTTP.Testing.Acceptance.Engine;
[TestClass]
public class MainHandlerTests
{
#region Supporting data structures
public class PreparationHandler : IHandler
{
private bool _Prepared;
public ValueTask PrepareAsync()
{
_Prepared = true;
return new();
}
public ValueTask<IResponse?> HandleAsync(IRequest request)
{
var response = request.Respond()
.Content(new StringContent(_Prepared ? "prepared" : "not prepared"))
.Build();
return new(response);
}
}
#endregion
[TestMethod]
[MultiEngineTest]
public async Task TestHandlerPreparation(TestEngine engine)
{
await using var host = await TestHost.RunAsync(new PreparationHandler(), engine: engine);
using var response = await host.GetResponseAsync();
Assert.AreEqual("prepared", await response.GetContentAsync());
}
[TestMethod]
[MultiEngineTest]
public async Task TestLayoutHandlerPreparation(TestEngine engine)
{
var app = Layout.Create().Add("sub", new PreparationHandler());
await using var host = await TestHost.RunAsync(app, engine: engine);
using var response = await host.GetResponseAsync("/sub/");
Assert.AreEqual("prepared", await response.GetContentAsync());
}
}