- JSON API /v1: odeslání SMS, doručenka, události, potvrzení událostí, kredit - vlastní API klíč pro každou aplikaci (X-Api-Key, API_KEYS) - po chybě přihlášení k bráně se volání zastaví, aby se účet nezablokoval - heslo maskované v logu, odeslání se nikdy neopakuje automaticky - /health, /docs a OpenAPI s prefixem z ROOT_PATH - .NET 10, šablona .NET 8 nahrazena projektem v src/, testy v tests/ - dokumentace: návrh, stav a návod pro napojení aplikací
34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using System.Net;
|
|
using System.Text;
|
|
|
|
namespace SmsSluzba.Api.Tests.Api;
|
|
|
|
/// <summary>Stands in for the SMS gateway: returns queued responses and records every request.</summary>
|
|
internal sealed class FakeGatewayHandler : HttpMessageHandler
|
|
{
|
|
private readonly Queue<Func<HttpResponseMessage>> _responses = new();
|
|
|
|
public List<(Uri Uri, string? Body)> Requests { get; } = [];
|
|
|
|
public void Enqueue(string body, HttpStatusCode status = HttpStatusCode.OK) =>
|
|
_responses.Enqueue(() => new HttpResponseMessage(status)
|
|
{
|
|
Content = new StringContent(body, Encoding.UTF8, "application/xml"),
|
|
});
|
|
|
|
public void EnqueueException(Exception exception) => _responses.Enqueue(() => throw exception);
|
|
|
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
var body = request.Content is null ? null : await request.Content.ReadAsStringAsync(cancellationToken);
|
|
Requests.Add((request.RequestUri!, body));
|
|
|
|
if (_responses.Count == 0)
|
|
{
|
|
throw new InvalidOperationException("Unexpected gateway call: " + request.RequestUri);
|
|
}
|
|
|
|
return _responses.Dequeue()();
|
|
}
|
|
}
|