Enhanced.Testing.Component.DbContext
1.6.0
dotnet add package Enhanced.Testing.Component.DbContext --version 1.6.0
NuGet\Install-Package Enhanced.Testing.Component.DbContext -Version 1.6.0
<PackageReference Include="Enhanced.Testing.Component.DbContext" Version="1.6.0" />
<PackageVersion Include="Enhanced.Testing.Component.DbContext" Version="1.6.0" />
<PackageReference Include="Enhanced.Testing.Component.DbContext" />
paket add Enhanced.Testing.Component.DbContext --version 1.6.0
#r "nuget: Enhanced.Testing.Component.DbContext, 1.6.0"
#:package Enhanced.Testing.Component.DbContext@1.6.0
#addin nuget:?package=Enhanced.Testing.Component.DbContext&version=1.6.0
#tool nuget:?package=Enhanced.Testing.Component.DbContext&version=1.6.0
Enhanced.Testing.Component.DbContext
An EF Core harness for Enhanced.Testing.Component: creates the application's schema on start and runs queries against the application's database from the test.
dotnet add package Enhanced.Testing.Component.DbContext
Usage
var postgreSql = new PostgreSqlHarness { ConnectionName = "People" };
var peopleDb = new DbContextHarness<PeopleDbContext>();
peopleDb.EnsureCreatedOnStart(builder => builder.UseNpgsql(postgreSql.GetConnectionString()));
var component = ComponentBuilder.Create<Program>()
.AddHarness(postgreSql)
.AddHarness(peopleDb)
.AddHarness(http)
.Build();
Add the harness after the database harness it depends on. EnsureCreatedOnStart configures the options when the
component starts, after the database container is up, and creates the schema with Database.EnsureCreatedAsync. For
this, TContext needs a constructor taking DbContextOptions<TContext> or DbContextOptions.
In a test, query or seed through the application's own DbContext (resolved from the application's service
provider in a new scope):
await peopleDb.ExecuteAsync(async db =>
{
db.Persons.Add(new Person { Name = "Kelly" });
await db.SaveChangesAsync();
});
var exists = await peopleDb.ExecuteAsync(db => db.Persons.AnyAsync(p => p.Name == "Kelly"));
Execute and Execute<T> are the synchronous versions.
The harness works with any EF Core provider. For PostgreSQL, see also per-test template databases.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. net11.0 is compatible. |
-
net10.0
- Enhanced.Testing.Component (>= 1.6.0)
- Microsoft.EntityFrameworkCore (>= 10.0.15)
-
net11.0
- Enhanced.Testing.Component (>= 1.6.0)
- Microsoft.EntityFrameworkCore (>= 11.0.0)
-
net8.0
- Enhanced.Testing.Component (>= 1.6.0)
- Microsoft.EntityFrameworkCore (>= 8.0.34)
-
net9.0
- Enhanced.Testing.Component (>= 1.6.0)
- Microsoft.EntityFrameworkCore (>= 9.0.23)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.