Alvecta.Foundation.Infrastructure.EF.Testing
9.0.86
See the version list below for details.
dotnet add package Alvecta.Foundation.Infrastructure.EF.Testing --version 9.0.86
NuGet\Install-Package Alvecta.Foundation.Infrastructure.EF.Testing -Version 9.0.86
<PackageReference Include="Alvecta.Foundation.Infrastructure.EF.Testing" Version="9.0.86" />
<PackageVersion Include="Alvecta.Foundation.Infrastructure.EF.Testing" Version="9.0.86" />
<PackageReference Include="Alvecta.Foundation.Infrastructure.EF.Testing" />
paket add Alvecta.Foundation.Infrastructure.EF.Testing --version 9.0.86
#r "nuget: Alvecta.Foundation.Infrastructure.EF.Testing, 9.0.86"
#:package Alvecta.Foundation.Infrastructure.EF.Testing@9.0.86
#addin nuget:?package=Alvecta.Foundation.Infrastructure.EF.Testing&version=9.0.86
#tool nuget:?package=Alvecta.Foundation.Infrastructure.EF.Testing&version=9.0.86
Alvecta.Foundation.Infrastructure.EF.Testing
EF Core persistence test harness for solutions that follow the Alvecta read/write DbContext split: a projection-only read context that maps the query schema and owns the migrations, and a write context that maps the domain entities as a relational subset of it.
The package is a library of abstract xunit base classes (not a runnable test project). Each consuming solution adds thin sealed run-host subclasses that supply the context factories.
What it pins
SchemaParityTestsBase<TReadDbContext, TWriteDbContext>— the scalar shapes of the two models (table names, columns, store types, nullability — navigations excluded) must match exactly, and the read face keeps its structural guarantees: no tracking, the projection-only materialization interceptor registered, and refusingSaveChangesAsync.MigrationsDriftTestsBase<TDbContext>— the migrations-owning context has no pending model changes relative to its snapshot.MigrationsScriptTestsBase<TDbContext>— the SQL the migrations send to the database, as the provider's migrations SQL generator writes it (a custom generator's rewrites included), is pinned in two files of the run host's test project:<RunHost>.Up.sql, from an empty database to the latest migration, and<RunHost>.Down.sql, back. Every run writes the generated script over the pinned one and fails when they differed: a new migration or a provider upgrade that changes the SQL fails once, its diff is reviewed and committed, and the next run passes. Line endings become\nand the EF version in the history rows becomes<ProductVersion>. The project folder is found by walking up from the test output to the folder holding<assembly name>.csproj, so the output has to lie inside the project folder (the defaultbin/layout, not the artifacts layout).ModelShapes— the shape-rendering helper behind the parity assertion, public for solution-specific comparisons.
Usage
public sealed class ConnectorSchemaParityTests
: SchemaParityTestsBase<ConnectorReadDbContext, ConnectorWriteDbContext>
{
protected override ConnectorReadDbContext CreateReadDbContext() => TestDbContexts.ConnectorRead();
protected override ConnectorWriteDbContext CreateWriteDbContext() => TestDbContexts.ConnectorWrite();
}
public sealed class ConnectorMigrationsDriftTests : MigrationsDriftTestsBase<ConnectorReadDbContext>
{
// Build through the design-time factory the `dotnet ef` tooling uses, so the comparison sees
// exactly what migration generation would see.
protected override ConnectorReadDbContext CreateDbContext()
=> new ConnectorDbContextDesignTimeFactory().CreateDbContext([]);
}
// Pins ConnectorMigrationsScriptTests.Up.sql and .Down.sql in the test project's folder.
public sealed class ConnectorMigrationsScriptTests : MigrationsScriptTestsBase<ConnectorReadDbContext>
{
protected override ConnectorReadDbContext CreateDbContext()
=> new ConnectorDbContextDesignTimeFactory().CreateDbContext([]);
}
Contexts built against a dummy connection string are fine — none of the tests touches the database.
Integration tests over in-memory Sqlite
The Sqlite namespace is the engine for tests that run a solution's query services and persistence
services over its real read/write contexts:
SqliteTestDatabase— an in-memory Sqlite database that lives as long as its connection, so every instance starts empty.InitializeAsyncopens the connection and creates the schema from the context the subclass'sCreateSchemaDbContextbuilds (the read context, whose query schema owns the migrations; a multi-tenant one in cross-tenant mode). The subclass builds its contexts overOptions<TDbContext>(), which share the one connection, and hands out the persistence ports throughBuildQuerySessionFactoryandBuildUnitOfWorkFactory, which compose them from the same Foundation classes the hosts register.SqliteReadDbContextConcernBundle/SqliteWriteDbContextConcernBundle— the read and write faces' concerns as the hosts compose them (the read face projection-only, so a query that materializes a query-schema entity fails here as in production), plusUtcTicksDateTimeOffsetConcern, last: Sqlite stores aDateTimeOffsetas text and compares it only for equality, so ordering by one or comparing two with</>throws; the concern stores the UTC ticks instead and reads them back at offset zero, as PostgreSQL'stimestamptzkeeps the instant and not the offset.DelegatingDbContextFactory<TDbContext>(root namespace) — theIDbContextFactorythat hands Foundation's persistence scopes the contexts a test builds.
public sealed class OrdersTestDatabase : SqliteTestDatabase
{
public IQuerySessionFactory<IOrdersQuerySession> CreateQuerySessionFactory(TenantId tenantId)
{
return
BuildQuerySessionFactory<IOrdersQuerySession, OrdersReadDbContext>(
() => CreateReadDbContext(new FixedTenantIdProvider<TenantId>(tenantId)),
dependencyFactory => new OrdersQuerySession(dependencyFactory));
}
public IUnitOfWorkFactory<IOrdersUnitOfWork> CreateUnitOfWorkFactory(TenantId tenantId)
{
return
BuildUnitOfWorkFactory<IOrdersUnitOfWork, OrdersWriteDbContext>(
() => new(
Options<OrdersWriteDbContext>(),
new FixedTenantIdProvider<TenantId>(tenantId),
new SqliteWriteDbContextConcernBundle()),
dependencyFactory => new OrdersUnitOfWork(dependencyFactory));
}
// The schema is created by a cross-tenant context, as the migrations are in production.
protected override DbContext CreateSchemaDbContext()
{
return CreateReadDbContext(new DesignTimeTenantIdProvider<TenantId>());
}
private OrdersReadDbContext CreateReadDbContext(ITenantIdProvider<TenantId> tenantIdProvider)
{
return new(Options<OrdersReadDbContext>(), tenantIdProvider, new SqliteReadDbContextConcernBundle());
}
}
FixedTenantIdProvider comes from Alvecta.Foundation.Application.Ports.Testing. The query services
run their async terminals through Alvecta.Utils.Queryable, so the test project registers
EFQueryableAsyncHelper (from Alvecta.Utils.Queryable.EF), as the hosts do. Sqlite reproduces
materialization failures and most translation failures, but not the translation specific to the
production provider.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Alvecta.Foundation.Application.Ports (>= 9.0.86)
- Alvecta.Foundation.Infrastructure.EF (>= 9.0.86)
- Alvecta.Utils (>= 8.4.80)
- Microsoft.EntityFrameworkCore (>= 10.0.14)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.14)
- Microsoft.EntityFrameworkCore.Sqlite (>= 10.0.14)
- SQLitePCLRaw.bundle_e_sqlite3 (>= 3.0.5)
- xunit.v3.assert (>= 4.0.2)
- xunit.v3.extensibility.core (>= 4.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 9.4.91 | 49 | 11/20/2026 |
| 9.3.90 | 114 | 11/13/2026 |
| 9.2.89 | 91 | 11/12/2026 |
| 9.1.88 | 94 | 11/11/2026 |
| 9.0.87 | 101 | 11/4/2026 |
| 9.0.86 | 86 | 11/4/2026 |
| 9.0.85 | 94 | 11/4/2026 |
| 9.0.84 | 89 | 11/4/2026 |
| 9.0.83 | 102 | 10/29/2026 |
| 9.0.82 | 109 | 10/29/2026 |
| 8.1.81 | 95 | 10/29/2026 |
| 8.0.80 | 96 | 10/28/2026 |
| 8.0.79 | 94 | 10/28/2026 |
| 8.0.78 | 101 | 10/28/2026 |
| 8.0.77 | 102 | 10/28/2026 |
| 7.1.76 | 107 | 10/27/2026 |
| 7.1.75 | 94 | 10/26/2026 |
| 7.0.74 | 99 | 10/26/2026 |
| 7.0.73 | 99 | 10/23/2026 |
| 7.0.72 | 102 | 10/23/2026 |