Enable support for WireMock Middleware in Hosted Services (#1285)

This commit is contained in:
Emil Tang Kristensen
2025-04-25 16:35:55 +02:00
committed by GitHub
parent 0fd190b5a3
commit 9392069f8a
5 changed files with 94 additions and 3 deletions

View File

@@ -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);
}
}
}
}