using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Moq; using Moq.Protected; namespace Cloudflare.Core.Tests { internal class HttpMessageHandlerMock { public HttpMessageHandlerMock() { Mock = new(); Mock.Protected() .Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny()) .Callback(async (request, ct) => { var callback = new HttpMessageRequestCallback { Method = request.Method, Url = request.RequestUri.ToString(), Headers = request.Headers.ToDictionary(h => h.Key, h => h.Value.First()), }; if (request.Content != null) callback.Content = await request.Content.ReadAsStringAsync(); Callbacks.Add(callback); }) .ReturnsAsync(() => Responses.Dequeue()); } public List Callbacks { get; } = []; public Queue Responses { get; } = new(); public Mock Mock { get; } } internal class HttpMessageRequestCallback { public HttpMethod Method { get; set; } public string Url { get; set; } public Dictionary Headers { get; set; } public string Content { get; set; } } }