Add WireMock.Net.AspNetCore.Middleware (#1175)

* Add WireMock.Net.AspNetCore.Middleware

* .

* WireMock.Net.Middleware.Tests

* .

* X-WireMock-Response-Delay
This commit is contained in:
Stef Heyenrath
2024-09-27 20:39:57 +02:00
committed by GitHub
parent c57590b2ba
commit 42306d1864
23 changed files with 641 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
using WireMock.Net.AspNetCore.Middleware;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
namespace WireMock.Net.TestWebApplication;
// Make the implicit Program class public so test projects can access it.
public class Program
{
public static async Task Main(string[] args)
{
var alwaysRedirectToWireMock = args.Contains("--AlwaysRedirectToWireMock=true");
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddWireMockService(server =>
{
server.Given(Request.Create()
.WithPath("/test1")
.UsingAnyMethod()
).RespondWith(Response.Create()
.WithBody("Hello 1 from WireMock.Net !")
);
server.Given(Request.Create()
.WithPath("/test2")
.UsingAnyMethod()
).RespondWith(Response.Create()
.WithBody("Hello 2 from WireMock.Net !")
);
}, alwaysRedirectToWireMock);
var app = builder.Build();
app.MapGet("/real1", async (HttpClient client) =>
{
var result = await client.GetStringAsync("https://real-api:12345/test1");
return result;
});
app.MapGet("/real2", async (IHttpClientFactory factory) =>
{
using var client = factory.CreateClient();
return await client.GetStringAsync("https://real-api:12345/test2");
});
await app.RunAsync();
}
}

View File

@@ -0,0 +1,12 @@
{
"profiles": {
"WireMock.Net.TestWebApplication": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:57712;http://localhost:57713"
}
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net.AspNetCore.Middleware\WireMock.Net.AspNetCore.Middleware.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}