Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
33 lines
1.6 KiB
C#
33 lines
1.6 KiB
C#
using System.Net;
|
|
using System.Text;
|
|
using Bff.Api;
|
|
|
|
namespace Bff.Tests;
|
|
|
|
// S-29 (#192): the BFF reads the domain's provide-documents answer — 422 carries the refusal reason,
|
|
// 503 means the scanner was down — into a result the endpoint relays.
|
|
public class DomainClientProvideDocumentsTests
|
|
{
|
|
private sealed class Reply(HttpStatusCode status, string? json) : HttpMessageHandler
|
|
{
|
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct)
|
|
=> Task.FromResult(new HttpResponseMessage(status)
|
|
{
|
|
Content = new StringContent(json ?? "", Encoding.UTF8, "application/json"),
|
|
});
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(HttpStatusCode.NoContent, null, ProvideDocumentsResult.Provided)]
|
|
[InlineData(HttpStatusCode.NotFound, null, ProvideDocumentsResult.NotFound)]
|
|
[InlineData(HttpStatusCode.UnprocessableEntity, """{"reason":"not-a-pdf"}""", ProvideDocumentsResult.NotAPdf)]
|
|
[InlineData(HttpStatusCode.UnprocessableEntity, """{"reason":"infected"}""", ProvideDocumentsResult.Infected)]
|
|
[InlineData(HttpStatusCode.ServiceUnavailable, null, ProvideDocumentsResult.ScannerUnavailable)]
|
|
public async Task Maps_the_domain_answer_to_a_result(HttpStatusCode status, string? body, ProvideDocumentsResult expected)
|
|
{
|
|
var client = new DomainClient(new HttpClient(new Reply(status, body)) { BaseAddress = new Uri("http://domain/") });
|
|
|
|
Assert.Equal(expected, await client.ProvideDocumentsAsync("reg-1", "123456782", "JVBERi0=", null, null));
|
|
}
|
|
}
|