mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-23 01:29:05 +01:00
Enable support for WireMock Middleware in Hosted Services (#1285)
This commit is contained in:
committed by
GitHub
parent
0fd190b5a3
commit
9392069f8a
@@ -13,6 +13,9 @@ public class Program
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddSingleton<TaskQueue>();
|
||||
builder.Services.AddHostedService<TestBackgroundService>();
|
||||
|
||||
builder.Services.AddWireMockService(server =>
|
||||
{
|
||||
server.Given(Request.Create()
|
||||
@@ -28,6 +31,13 @@ public class Program
|
||||
).RespondWith(Response.Create()
|
||||
.WithBody("Hello 2 from WireMock.Net !")
|
||||
);
|
||||
|
||||
server.Given(Request.Create()
|
||||
.WithPath("/test3")
|
||||
.UsingAnyMethod()
|
||||
).RespondWith(Response.Create()
|
||||
.WithBody("Hello 3 from WireMock.Net !")
|
||||
);
|
||||
}, alwaysRedirectToWireMock);
|
||||
|
||||
var app = builder.Build();
|
||||
@@ -44,6 +54,11 @@ public class Program
|
||||
return await client.GetStringAsync("https://real-api:12345/test2");
|
||||
});
|
||||
|
||||
app.MapGet("/real3", async (TaskQueue taskQueue, CancellationToken cancellationToken) =>
|
||||
{
|
||||
return await taskQueue.Enqueue("https://real-api:12345/test3", cancellationToken);
|
||||
});
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user