Class DatabaseLifecycleFixture<TEntryPoint, TContext>
- Namespace
- FEFF.TestFixtures.AspNetCore.EF
- Assembly
- FEFF.TestFixtures.AspNetCore.EF.dll
A fixture that manages Entity Framework Core database creation and deletion for the lifetime of a test scope. The database is deleted on DisposeAsync().
public sealed class DatabaseLifecycleFixture<TEntryPoint, TContext> : IAsyncDisposable, IDatabaseLifecycleFixture<TContext>, IDatabaseLifecycleFixture where TEntryPoint : class where TContext : DbContext
Type Parameters
TEntryPointThe application entry point type.
TContextThe DbContext type to manage.
- Inheritance
-
DatabaseLifecycleFixture<TEntryPoint, TContext>
- Implements
-
IDatabaseLifecycleFixture<TContext>
- Inherited Members
- Extension Methods
Remarks
Note: EnsureDeleted may fail for admin databases. Consider using TmpDbNameFixture for such cases.
Constructors
DatabaseLifecycleFixture(AppManagerFixture<TEntryPoint>, AppServicesFixture<TEntryPoint>)
Creates a new database lifecycle management fixture.
public DatabaseLifecycleFixture(AppManagerFixture<TEntryPoint> app, AppServicesFixture<TEntryPoint> services)
Parameters
appAppManagerFixture<TEntryPoint>The application manager fixture.
servicesAppServicesFixture<TEntryPoint>The application services fixture.
Properties
LazyDbContext
Gets the TContext instance resolved from the service provider.
public TContext LazyDbContext { get; }
Property Value
- TContext
Remarks
Accessing this property starts the application under test if not already running.
Methods
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.