using System.Net;
namespace Big.Tests;
/// A test double for that records the last request and
/// returns a scripted response — the same approach the ACL gateway tests use.
internal sealed class StubHandler(Func> onSend) : HttpMessageHandler
{
protected override Task SendAsync(HttpRequestMessage request, CancellationToken ct)
=> onSend(request);
}
/// Captures the request a client sent, including the (buffered) body.
internal sealed class RequestCapture
{
public HttpRequestMessage? Seen { get; private set; }
public string? Body { get; private set; }
/// A handler that records the request, then replies with and
/// .
public StubHandler Responds(HttpStatusCode status, string? json = null) => new(async req =>
{
Seen = req;
Body = req.Content is null ? null : await req.Content.ReadAsStringAsync();
var response = new HttpResponseMessage(status);
if (json is not null)
response.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
return response;
});
}