I create a HTTP Client using IHttpClientFactory and attach a Polly policy (requires Microsoft.Extensions.Http.Polly) as follows:
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
IHost host = new HostBuilder()
.ConfigureServices((hostingContext, services) =>
{
services.AddHttpClient("TestClient", client =>
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
})
.AddPolicyHandler(PollyPolicies.HttpResponsePolicies(
arg1,
arg2,
arg3));
})
.Build();
IHttpClientFactory httpClientFactory = host.Services.GetRequiredService<IHttpClientFactory>();
HttpClient httpClient = httpClientFactory.CreateClient("TestClient");
How can I mock this HTTP Client using Moq?
EDIT: Mock means to be able to mock the requests of the HTTP. The policy should be applied as defined.