mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-24 10:22:13 +01:00
Add WireMock.Net.AspNetCore.Middleware (#1175)
* Add WireMock.Net.AspNetCore.Middleware * . * WireMock.Net.Middleware.Tests * . * X-WireMock-Response-Delay
This commit is contained in:
49
test/WireMock.Net.TestWebApplication/Program.cs
Normal file
49
test/WireMock.Net.TestWebApplication/Program.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"WireMock.Net.TestWebApplication": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:57712;http://localhost:57713"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
9
test/WireMock.Net.TestWebApplication/appsettings.json
Normal file
9
test/WireMock.Net.TestWebApplication/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user