Enigmatry.Entry.AspNetCore.Tests.Utilities
11.0.0-preview.1
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
<PackageReference Include="Enigmatry.Entry.AspNetCore.Tests.Utilities" Version="11.0.0-preview.1" />
<PackageVersion Include="Enigmatry.Entry.AspNetCore.Tests.Utilities" Version="11.0.0-preview.1" />
<PackageReference Include="Enigmatry.Entry.AspNetCore.Tests.Utilities" />
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"
#:package Enigmatry.Entry.AspNetCore.Tests.Utilities@11.0.0-preview.1
#addin nuget:?package=Enigmatry.Entry.AspNetCore.Tests.Utilities&version=11.0.0-preview.1&prerelease
#tool nuget:?package=Enigmatry.Entry.AspNetCore.Tests.Utilities&version=11.0.0-preview.1&prerelease
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
TestDatabasehas to start a SQL Server container (see below). - An Autofac container in the application under test, for
ApiEnvironment<T>andInMemoryDbModule.
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
ResetDataEnabledis set. - Otherwise it deletes all data with Respawn, skipping
TablesToIgnoreand reseeding identity columns unlessReseedIdentityColumnsis false.BeforeDeleteCustomSqlQueryandAfterDeleteCustomSqlQueryrun 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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Autofac (>= 9.3.4)
- Azure.Identity (>= 1.21.0)
- Enigmatry.Entry.Core (>= 11.0.0-preview.1)
- Enigmatry.Entry.Infrastructure (>= 11.0.0-preview.1)
- FluentValidation (>= 12.2.0)
- JetBrains.Annotations (>= 2026.2.0)
- MediatR (= 12.4.1)
- Microsoft.AspNetCore.Mvc.Testing (>= 11.0.0)
- Microsoft.AspNetCore.TestHost (>= 11.0.0)
- Microsoft.Data.SqlClient (>= 7.1.1)
- Microsoft.Data.SqlClient.Extensions.Azure (>= 7.1.1)
- Microsoft.EntityFrameworkCore (>= 11.0.0)
- Microsoft.EntityFrameworkCore.InMemory (>= 11.0.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 11.0.0)
- Microsoft.Extensions.Configuration (>= 11.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 11.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 11.0.0)
- Microsoft.Extensions.Configuration.UserSecrets (>= 11.0.0)
- Microsoft.Extensions.DependencyInjection (>= 11.0.0)
- Microsoft.Extensions.Logging (>= 11.0.0)
- Microsoft.Extensions.Logging.Console (>= 11.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 11.0.0)
- NUnit (>= 5.0.0)
- Respawn (>= 7.0.0)
- Serilog (>= 4.4.0)
- Shouldly (>= 4.3.0)
- System.Security.Cryptography.Pkcs (>= 11.0.0)
- Testcontainers.MsSql (>= 4.16.0)
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 |