Enigmatry.Entry.AspNetCore.Tests.Utilities 11.0.0-preview.1

This is a prerelease version of Enigmatry.Entry.AspNetCore.Tests.Utilities.
dotnet add package Enigmatry.Entry.AspNetCore.Tests.Utilities --version 11.0.0-preview.1
                    
NuGet\Install-Package Enigmatry.Entry.AspNetCore.Tests.Utilities -Version 11.0.0-preview.1
                    
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="Enigmatry.Entry.AspNetCore.Tests.Utilities" Version="11.0.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Enigmatry.Entry.AspNetCore.Tests.Utilities" Version="11.0.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Enigmatry.Entry.AspNetCore.Tests.Utilities" />
                    
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 Enigmatry.Entry.AspNetCore.Tests.Utilities --version 11.0.0-preview.1
                    
#r "nuget: Enigmatry.Entry.AspNetCore.Tests.Utilities, 11.0.0-preview.1"
                    
#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 Enigmatry.Entry.AspNetCore.Tests.Utilities@11.0.0-preview.1
                    
#: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=Enigmatry.Entry.AspNetCore.Tests.Utilities&version=11.0.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Enigmatry.Entry.AspNetCore.Tests.Utilities&version=11.0.0-preview.1&prerelease
                    
Install as a Cake Tool

ASP.NET Core Tests Utilities

Helpers for integration tests of Entry-based ASP.NET Core APIs: a test host, a SQL Server test database with data reset between tests, and an in-memory EF Core database.

Requirements

  • NUnit 5. Diagnostic output goes to TestContext.Out.
  • Docker, when TestDatabase has to start a SQL Server container (see below).
  • An Autofac container in the application under test, for ApiEnvironment<T> and InMemoryDbModule.

Installation

dotnet add package Enigmatry.Entry.AspNetCore.Tests.Utilities

Test host

ApiEnvironment<T> is a WebApplicationFactory<T> that runs the API in the Test environment, loads appsettings.Test.json, and returns an HttpClient for https://localhost with a 30 second timeout. Override OnContainerBuilderConfiguration to replace Autofac registrations.

public class TestEnvironment : ApiEnvironment<Program>
{
    public override void OnContainerBuilderConfiguration(HostBuilderContext context, ContainerBuilder builder)
    {
        base.OnContainerBuilderConfiguration(context, builder);
        builder.RegisterModule<InMemoryDbModule>();
    }
}

[Test]
public async Task GetsWeatherForecasts()
{
    await using var environment = new TestEnvironment();
    await TestRunner.Run(environment, async (_, client) =>
    {
        var response = await client.GetAsync(new Uri("weatherforecast", UriKind.Relative));
        response.EnsureSuccessStatusCode();
    });
}

InMemoryDbModule registers DbContextOptions for an EF Core in-memory database with a unique name. UriExtensions.AppendParameters adds query-string parameters to a Uri, and ServiceScopeExtensions.Resolve<T> resolves a required service from an IServiceScope.

SQL Server test database

TestDatabase.Create reads the connection strings from the environment variables listed in DatabaseInitializerOptions.ConnectionStringEnvironmentVariables (default: IntegrationTestsConnectionString). When any of them is unset, it starts one shared SQL Server container through Testcontainers (SqlContainerImage) and uses that container's connection string for the unset ones. Disposing the last TestDatabase stops the container.

Reset(dbContext) prepares the database for a test:

  • When the database doesn't exist or has pending migrations, it drops all objects and applies the migrations. Data is then reset only when ResetDataEnabled is set.
  • Otherwise it deletes all data with Respawn, skipping TablesToIgnore and reseeding identity columns unless ReseedIdentityColumns is false. BeforeDeleteCustomSqlQuery and AfterDeleteCustomSqlQuery run around the delete.
private static TestDatabase _database = null!;

[OneTimeSetUp]
public static async Task CreateDatabase() =>
    _database = await TestDatabase.Create(new DatabaseInitializerOptions { TablesToIgnore = ["__EFMigrationsHistory"] });

[SetUp]
public async Task ResetDatabase()
{
    await using var dbContext = CreateDbContext(_database.ConnectionStrings["IntegrationTestsConnectionString"]);
    await _database.Reset(dbContext);
}

[OneTimeTearDown]
public static async Task DisposeDatabase() => await _database.DisposeAsync();

Migrating needs at least one migration in the DbContext: EF Core throws when MigrateAsync finds none. DatabaseHelpers.DropAllSql holds the script that drops all database objects.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Enigmatry.Entry.AspNetCore.Tests.Utilities:

Package Downloads
Enigmatry.Entry.AspNetCore.Tests.SystemTextJson

Building Block for writing tests in an Entry AspNetCore based project with SystemText Json

Enigmatry.Entry.AspNetCore.Tests.NewtonsoftJson

Building Block for writing tests in an Entry AspNetCore based project with Newtonsoft Json

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.0-preview.1 56 11/13/2026
10.6.0 185 11/12/2026
10.5.1 821 10/27/2026
10.5.0 494 10/15/2026
10.4.0 327 10/6/2026
10.3.1 1,925 8/20/2026
10.3.0 3,288 7/21/2026
10.2.4 1,363 7/3/2026
10.2.3 1,069 6/1/2026
10.2.3-preview.4 110 6/1/2026
10.2.2 567 4/27/2026
10.2.1-preview.1 93 4/27/2026
10.1.0 470 4/16/2026
10.0.1 296 5/19/2026
10.0.1-preview.2 100 4/16/2026
10.0.0 186 4/2/2026
9.6.0 632 3/18/2026
9.5.0 1,550 1/26/2026
8.3.1-preview.1 251 12/24/2025
8.3.0 1,571 12/23/2025
Loading failed