using System.Net.Http.Json;
using BigRegister.Api.Zgw;
using Microsoft.Extensions.Logging.Abstractions;
namespace BigRegister.Tests;
///
/// The opt-in diagnostic handler (see ZgwDiagnosticHandler's own doc comment) must be inert on
/// the request/response — it only observes. This doesn't catch the flake itself (that needs a
/// real repro with ZGW_DEBUG_HTTP=1), just proves the hook doesn't alter what's sent or break
/// the response passthrough.
///
public class ZgwDiagnosticHandlerTests
{
[Fact]
public async Task Passes_request_and_response_through_unchanged()
{
var stub = new ZgwStubHandler(_ => """{ "ok": true }""");
var diagnostic = new ZgwDiagnosticHandler(NullLogger.Instance) { InnerHandler = stub };
using var client = new HttpClient(diagnostic);
var response = await client.PostAsJsonAsync("https://oz.example/zaken", new { foo = "bar" });
Assert.True(response.IsSuccessStatusCode);
Assert.Single(stub.Requests);
Assert.Contains("\"foo\":\"bar\"", stub.BodyOf("https://oz.example/zaken"));
}
}