Class InMemoryEntityFrameworkWebApplicationFactory<TEntryPoint, TDbContext>
- Namespace
- XBullet.EasyTesting.EntityFrameworkCore
- Assembly
- XBullet.EasyTesting.EntityFrameworkCore.dll
An Entity Framework Core test factory backed by the EF Core in-memory provider.
public class InMemoryEntityFrameworkWebApplicationFactory<TEntryPoint, TDbContext> : EntityFrameworkWebApplicationFactory<TEntryPoint, TDbContext>, IDisposable, IAsyncDisposable where TEntryPoint : class where TDbContext : DbContext
Type Parameters
TEntryPointThe application entry-point type hosted by the test factory.
TDbContextThe EF Core context type registered with the in-memory provider.
- Inheritance
-
WebApplicationFactory<TEntryPoint>AuthenticatedWebApplicationFactory<TEntryPoint>EntityFrameworkWebApplicationFactory<TEntryPoint, TDbContext>InMemoryEntityFrameworkWebApplicationFactory<TEntryPoint, TDbContext>
- Implements
- Inherited Members
Remarks
Each factory and each test scenario receives an isolated in-memory database. The in-memory provider is not relational and does not support transactions. Use EntityFrameworkWebApplicationFactory<TEntryPoint, TDbContext> with a relational provider when relational behavior is part of the test.
Methods
ConfigureDatabaseServices(IServiceCollection)
Registers TDbContext with the chosen test provider and connection.
protected override sealed void ConfigureDatabaseServices(IServiceCollection services)
Parameters
servicesIServiceCollectionThe mutable test-host service collection to update in place. The host owns the collection and all registered services.
ConfigureInMemoryDatabase(DbContextOptionsBuilder)
Configures options shared by the factory database and every scenario database.
protected virtual void ConfigureInMemoryDatabase(DbContextOptionsBuilder options)
Parameters
optionsDbContextOptionsBuilderThe mutable options builder to configure in place. The factory owns it; implementations must not retain it. The in-memory provider and isolated database name have already been configured.
Remarks
This callback may run more than once as dependency-injection providers build context options.
ConfigureScenarioDatabaseServices(IServiceCollection, TestScenarioContext)
Registers the database used by one scenario. Override this to allocate a distinct database,
schema, or connection and register its cleanup through context.
protected override sealed void ConfigureScenarioDatabaseServices(IServiceCollection services, TestScenarioContext context)
Parameters
servicesIServiceCollectionThe mutable scenario-host service collection to update in place. Existing registrations for
TDbContexthave already been removed.contextTestScenarioContextThe scenario configuration context. Use it to identify the scenario and register resources whose ownership is transferred to the scenario for cleanup; do not retain the context.