Alvecta.Foundation.Infrastructure.EF.Testing 9.0.82

There is a newer version of this package available.
See the version list below for details.
dotnet add package Alvecta.Foundation.Infrastructure.EF.Testing --version 9.0.82
                    
NuGet\Install-Package Alvecta.Foundation.Infrastructure.EF.Testing -Version 9.0.82
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Alvecta.Foundation.Infrastructure.EF.Testing" Version="9.0.82" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Alvecta.Foundation.Infrastructure.EF.Testing" Version="9.0.82" />
                    
Directory.Packages.props
<PackageReference Include="Alvecta.Foundation.Infrastructure.EF.Testing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Alvecta.Foundation.Infrastructure.EF.Testing --version 9.0.82
                    
#r "nuget: Alvecta.Foundation.Infrastructure.EF.Testing, 9.0.82"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Alvecta.Foundation.Infrastructure.EF.Testing@9.0.82
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Alvecta.Foundation.Infrastructure.EF.Testing&version=9.0.82
                    
Install as a Cake Addin
#tool nuget:?package=Alvecta.Foundation.Infrastructure.EF.Testing&version=9.0.82
                    
Install as a Cake Tool

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 refusing SaveChangesAsync.
  • 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 \n and 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 default bin/ 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. InitializeAsync opens the connection and creates the schema from the context the subclass's CreateSchemaDbContext builds (the read context, whose query schema owns the migrations; a multi-tenant one in cross-tenant mode). The subclass builds its contexts over Options<TDbContext>(), which share the one connection, and hands out the persistence ports through BuildQuerySessionFactory and BuildUnitOfWorkFactory, 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), plus UtcTicksDateTimeOffsetConcern, last: Sqlite stores a DateTimeOffset as 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's timestamptz keeps the instant and not the offset.
  • DelegatingDbContextFactory<TDbContext> (root namespace) — the IDbContextFactory that 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed