Skip to content

Commit

Permalink
Fixes and additional coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Dec 15, 2024
1 parent 5961245 commit ff2e864
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Modules/OpenApi/Handler/OpenApiConcern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public OpenApiConcern(IHandler content, ApiDiscoveryRegistry discovery, bool ena

#region Functionality

public ValueTask PrepareAsync() => new();
public ValueTask PrepareAsync() => Content.PrepareAsync();

public async ValueTask<IResponse?> HandleAsync(IRequest request)
{
Expand Down
63 changes: 63 additions & 0 deletions Testing/Acceptance/Engine/MainHandlerTests.cs
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());
}

}
8 changes: 7 additions & 1 deletion Testing/Acceptance/Modules/ApiBrowsing/HandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using GenHTTP.Modules.Layouting;
using GenHTTP.Modules.Layouting.Provider;
using GenHTTP.Modules.OpenApi;

using GenHTTP.Testing.Acceptance.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GenHTTP.Testing.Acceptance.Modules.ApiBrowsing;
Expand Down Expand Up @@ -71,6 +71,12 @@ public async Task TestCustomMeta(TestEngine engine)
AssertX.Contains("My API", content);
}

[TestMethod]
public void TestConcernChaining()
{
Chain.Works(ApiBrowser.Redoc());
}

private static LayoutBuilder GetApi()
{
return Layout.Create()
Expand Down

0 comments on commit ff2e864

Please sign in to comment.