-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hi Andrei
Do you have (or could you prepare) any samples showing how to use (or extend) DbContextCustomization to connect to a SQL Server database, for integration test purposes please?
I have created a customization as follows:
public class TestDbContextCustomization : DbContextCustomization
{
public override void Customize(IFixture fixture)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(@"appsettings.json", false, false)
.AddEnvironmentVariables()
.Build();
var connectionString = config["ConnectionStrings:CIServerIntegrationTests"];
Configure = o => o.UseSqlServer(connectionString);
OmitDbSets = false;
OnCreate = OnCreateAction.None;
base.Customize(fixture);
}
}And use the customization as follows:
var fixture = new Fixture().Customize(new TestDbContextCustomization());
var context = fixture.Create<TestDbContext>();
var sale = await context.Sales.FirstOrDefaultAsync();The db context has a normal constructor:
public TestDbContext(DbContextOptions<TestDbContext> options)
: base(options)
{
}However it errors with "No database provider has been configured for this DbContext".
Am I missing a step to properly configure the provider?
A breakpoint on the UseSqlServer method call is never hit.
Thank you
Metadata
Metadata
Assignees
Labels
No labels