-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
5961245
commit ff2e864
Showing
3 changed files
with
71 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
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,63 @@ | ||
using GenHTTP.Api.Content; | ||
using GenHTTP.Api.Protocol; | ||
using GenHTTP.Modules.Layouting; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
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()); | ||
} | ||
|
||
} |
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