Class TestEventStoreServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Stratara.Testing.EntityFrameworkCore.dll
Wires the real Stratara event-sourcing write stack against a shared in-memory SQLite database,
using the in-memory doubles from Stratara.Testing for the cross-cutting dependencies.
public static class TestEventStoreServiceCollectionExtensions
- Inheritance
-
TestEventStoreServiceCollectionExtensions
- Inherited Members
Methods
AddStrataraTestingEventStore<TWriteDbContext>(IServiceCollection, SqliteConnection, Guid)
Register the event-sourcing write stack (IEventSource, IAggregationService,
snapshots, the EF Core write store) over sharedConnection, plus an
InMemoryKeyStore, a TestSessionContextProvider, and a
RecordingEventBundleOutboxDispatcher. Register your aggregates with
AddAggregatesFromAssemblyContaining<T>() so event payload types deserialize.
public static IServiceCollection AddStrataraTestingEventStore<TWriteDbContext>(this IServiceCollection services, SqliteConnection sharedConnection, Guid defaultTenantId) where TWriteDbContext : DbContext, IWriteDbContext
Parameters
servicesIServiceCollectionThe service collection.
sharedConnectionSqliteConnectionAn open SQLite connection kept alive for the test's lifetime. It must stay open so every DbContext minted by the unit of work shares the same in-memory database. The caller owns it.
defaultTenantIdGuidThe tenant the preset session context is scoped to.
Returns
- IServiceCollection
The same service collection for chaining.
Type Parameters
TWriteDbContextThe concrete write DbContext (e.g. StrataraTestWriteDbContext).
Examples
The connection is shared so the in-memory database outlives a single context. Register the aggregates too, or persisted event payloads will not resolve:
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
services.AddStrataraTestingEventStore<AppWriteDbContext>(connection, Guid.NewGuid());
services.AddAggregatesFromAssemblyContaining<Account>();
Exceptions
- InvalidOperationException
Thrown when the service collection carries a host environment, or the environment variables state one, naming anything other than
Development. Where no environment is stated at all — an ordinary unit test — the call is allowed.