public class LocationService
{
...
protected HttpClient StorageClient { get; }
public LocationService(IHttpClientFactory httpClientFactory)
{
StorageClient = httpClientFactory.CreateClient("StorageClient");
}
public async Task Upload(IFormFile file)
{
...
await StorageClient.PostAsync("upload", file, cancellationToken);
}
}
public class IntegrationTestFactory : WebApplicationFactory<Program>, IAsyncLifetime
{
protected WireMockServer _wireMockServer;
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.UseEnvironment("Testing");
builder.ConfigureTestServices(services =>
{
services.AddHttpClient("StorageClient", client =>
{
client.BaseAddress = new Uri("http://localhost:5500");
});
}
}
}
public abstract class BaseTest : IAsyncLifetime
{
...
}
public class MyTest : BaseTest, IAsyncLifetime
{
private readonly IStorageApiClient _storageApiClient;
public MyTest(IntegrationTestFactory factory) : base(factory)
{
//How to inject StorageClient here from the integration test factory?
}
[Fact]
public async Test()
{
....
}
}
As you can see in the above code I have a class that is using http client to upload some files.
How can I inject http client from the integration test factory?