/// <summary> /// <para> /// Creates a new <see cref="DbDependentTestApplication"/> instance /// which can be used to create and work with test entities directly /// through the domain layer with the same API used in the domain /// integration tests project. /// </para> /// <para> /// Note that although the test app and client instances share the same base /// service configuration, they don't seem to share the service collection and /// therefore the same singleton instances, so be aware that features like in-memory /// caching are not shared. To get around this, the caching services in the client /// app will be reset when a new client is created. /// </para> /// <para> /// The application should be disposed of /// when you are done with it. /// </para> /// </summary> public static DbDependentTestApplication CreateApp <TEntryPoint>(this WebApplicationFactory <TEntryPoint> factory) where TEntryPoint : class { var seededEntities = factory.Services.GetRequiredService <SeededEntities>(); var factoryWithAppDependencies = factory.WithServices(services => { DbDependentTestApplicationServiceProviderFactory.ConfigureTestServices(services); }); var app = new DbDependentTestApplication(factoryWithAppDependencies.Services, seededEntities); return(app); }
/// <summary> /// Creates a new HttpClient instance for the test application, having /// configured it with the specified service overrides. /// </summary> /// <param name="serviceConfiguration">Service configuration delegate to run after all other services have been resgistered.</param> public static HttpClient CreateClientWithServices <TEntryPoint>(this WebApplicationFactory <TEntryPoint> factory, Action <IServiceCollection> serviceConfiguration) where TEntryPoint : class { return(factory.WithServices(serviceConfiguration).CreateClient()); }