feat(worker): BandelTicketClient fuer die Ticketsystem-REST-API
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace ClaudeDo.Worker.Tests.Tickets;
|
||||
|
||||
/// <summary>
|
||||
/// Fakes the HTTP transport for BandelTicketClient tests. No test using this may touch the
|
||||
/// network — reused by later tasks that also exercise the ticket client.
|
||||
/// </summary>
|
||||
internal sealed class StubHandler : HttpMessageHandler
|
||||
{
|
||||
public readonly List<HttpRequestMessage> Requests = new();
|
||||
public readonly List<string> Bodies = new();
|
||||
private readonly Func<HttpRequestMessage, (HttpStatusCode, string)> _respond;
|
||||
|
||||
public StubHandler(Func<HttpRequestMessage, (HttpStatusCode, string)> respond) => _respond = respond;
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct)
|
||||
{
|
||||
Requests.Add(request);
|
||||
Bodies.Add(request.Content is null ? "" : await request.Content.ReadAsStringAsync(ct));
|
||||
var (code, body) = _respond(request);
|
||||
return new HttpResponseMessage(code) { Content = new StringContent(body, Encoding.UTF8, "application/json") };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user