mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-28 12:22:14 +01:00
Enable support for WireMock Middleware in Hosted Services (#1285)
This commit is contained in:
committed by
GitHub
parent
0fd190b5a3
commit
9392069f8a
@@ -0,0 +1,24 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
namespace WireMock.Net.TestWebApplication;
|
||||
|
||||
public class TestBackgroundService(HttpClient client, TaskQueue taskQueue, ILogger<TestBackgroundService> logger)
|
||||
: BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
await foreach (var item in taskQueue.ReadTasks(stoppingToken))
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await client.GetStringAsync(item, stoppingToken);
|
||||
await taskQueue.WriteResponse(result, stoppingToken);
|
||||
}
|
||||
catch (ArgumentNullException argNullEx)
|
||||
{
|
||||
logger.LogError(argNullEx, "Null exception");
|
||||
await taskQueue.WriteErrorResponse(argNullEx.Message, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user