How do I grab all the Services from a CustomWebApplicationFactory? Startup class has conducted dependency injection for IDepartmentRepository and IDepartmentAppService. Would like to grab the new DI repository or service.
We are creating integration test which points to original application startup.
namespace Integrationtest
{
public class CustomWebApplicationFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureAppConfiguration((hostingContext, configurationBuilder) =>
{
var type = typeof(TStartup);
var path = @"C:\\OriginalApplicationWebAPI";
configurationBuilder.AddJsonFile($"{path}\\appsettings.json", optional: true, reloadOnChange: true);
configurationBuilder.AddEnvironmentVariables();
});
}
}
}
public class DepartmentAppServiceTest : IClassFixture<CustomWebApplicationFactory<OriginalApplication.Startup>>
{
public testDbContext context;
private readonly HttpClient _client;
public DepartmentAppServiceTest(CustomWebApplicationFactory<OriginalApplication.Startup> factory)
{
_client = factory.CreateClient();
factory. // trying to find services here for IDepartmentRepository
}
https://fullstackmark.com/post/20/painless-integration-testing-with-aspnet-core-web-api