Files
Flypaper/test/Flypaper.Tests/Fakes/FakeHttpHandler.cs
T
TomandClaude Opus 5.5 3671019e60
Build and deploy / build (push) Successful in 1m46s
Build and deploy / deploy (push) Successful in 22s
Add IP origin enrichment with DB-IP and world map
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:44:33 +01:00

23 lines
801 B
C#

using System.Collections.Concurrent;
using System.Net;
namespace Flypaper.Tests.Fakes;
internal sealed class FakeHttpHandler : HttpMessageHandler
{
private readonly ConcurrentDictionary<string, Func<HttpResponseMessage>> _responses = new();
public ConcurrentQueue<string> Requests { get; } = new();
public void Respond(string url, Func<HttpResponseMessage> response) => _responses[url] = response;
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var url = request.RequestUri!.ToString();
Requests.Enqueue(url);
return Task.FromResult(_responses.TryGetValue(url, out var response)
? response()
: new HttpResponseMessage(HttpStatusCode.NotFound));
}
}