-
-
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
fae846a
commit 4d272d9
Showing
10 changed files
with
172 additions
and
33 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
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,3 @@ | ||
namespace GenHTTP.Modules.ApiBrowsing.Common; | ||
|
||
public record BrowserMetaData(string? Url, string Title); |
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
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
50 changes: 50 additions & 0 deletions
50
Testing/Acceptance/Modules/ApiBrowsing/ApplicationTests.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,50 @@ | ||
using System.Net; | ||
using GenHTTP.Modules.ApiBrowsing; | ||
using GenHTTP.Modules.Functional; | ||
using GenHTTP.Modules.Layouting; | ||
using GenHTTP.Modules.OpenApi; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GenHTTP.Testing.Acceptance.Modules.ApiBrowsing; | ||
|
||
[TestClass] | ||
public class ApplicationTests | ||
{ | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestSwagger(TestEngine engine) | ||
{ | ||
var app = Layout.Create() | ||
.Add(Inline.Create().Get(() => 42)) | ||
.AddOpenApi() | ||
.AddSwaggerUI(); | ||
|
||
await using var host = await TestHost.RunAsync(app, engine: engine); | ||
|
||
using var response = await host.GetResponseAsync("/swagger/"); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.OK); | ||
|
||
AssertX.Contains("Swagger", await response.GetContentAsync()); | ||
} | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestRedoc(TestEngine engine) | ||
{ | ||
var app = Layout.Create() | ||
.Add(Inline.Create().Get(() => 42)) | ||
.AddOpenApi() | ||
.AddRedoc(); | ||
|
||
await using var host = await TestHost.RunAsync(app, engine: engine); | ||
|
||
using var response = await host.GetResponseAsync("/redoc/"); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.OK); | ||
|
||
AssertX.Contains("Redoc", 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System.Net; | ||
using GenHTTP.Modules.ApiBrowsing; | ||
using GenHTTP.Modules.Functional; | ||
using GenHTTP.Modules.Layouting; | ||
using GenHTTP.Modules.Layouting.Provider; | ||
using GenHTTP.Modules.OpenApi; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GenHTTP.Testing.Acceptance.Modules.ApiBrowsing; | ||
|
||
[TestClass] | ||
public class HandlerTests | ||
{ | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestGetOnly(TestEngine engine) | ||
{ | ||
await using var host = await TestHost.RunAsync(GetApi().AddSwaggerUI(), engine: engine); | ||
|
||
var request = host.GetRequest("/swagger"); | ||
|
||
request.Method = HttpMethod.Post; | ||
request.Content = new StringContent("Content"); | ||
|
||
using var response = await host.GetResponseAsync(request); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.MethodNotAllowed); | ||
|
||
Assert.AreEqual("GET", response.GetContentHeader("Allow")); | ||
} | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestResourceAccess(TestEngine engine) | ||
{ | ||
await using var host = await TestHost.RunAsync(GetApi().AddSwaggerUI(), engine: engine); | ||
|
||
using var response = await host.GetResponseAsync("/swagger/static/swagger-ui.css"); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.OK); | ||
} | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestNotFound(TestEngine engine) | ||
{ | ||
await using var host = await TestHost.RunAsync(GetApi().AddSwaggerUI(), engine: engine); | ||
|
||
using var response = await host.GetResponseAsync("/swagger/notfound"); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.NotFound); | ||
} | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestCustomMeta(TestEngine engine) | ||
{ | ||
var api = GetApi().AddSwaggerUI("docs", "https://localhost:5001/swagger.json", "My API"); | ||
|
||
await using var host = await TestHost.RunAsync(api, engine: engine); | ||
|
||
using var response = await host.GetResponseAsync("/docs/"); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.OK); | ||
|
||
var content = await response.GetContentAsync(); | ||
|
||
AssertX.Contains("https://localhost:5001/swagger.json", content); | ||
AssertX.Contains("My API", content); | ||
} | ||
|
||
private static LayoutBuilder GetApi() | ||
{ | ||
return Layout.Create() | ||
.Add(Inline.Create().Get(() => 42)) | ||
.AddOpenApi(); | ||
} | ||
|
||
} |