Skip to content

Commit

Permalink
Fix Multiple DbContext Registration (dotnet-architecture#703)
Browse files Browse the repository at this point in the history
Hi, i noticed that in the WebTestFixture used for FunctionalTests the DbContexts were registered without removing the existing ones in Program.cs
which leads to duplication
  • Loading branch information
linkprada authored Feb 28, 2023
1 parent 0542c52 commit 4304545
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/FunctionalTests/Web/WebTestFixture.cs
Original file line number Diff line number Diff line change
@@ -23,6 +23,16 @@ protected override IHost CreateHost(IHostBuilder builder)
// Add mock/test services to the builder here
builder.ConfigureServices(services =>
{
var descriptors = services.Where(d =>
d.ServiceType == typeof(DbContextOptions<CatalogContext>) ||
d.ServiceType == typeof(DbContextOptions<AppIdentityDbContext>))
.ToList();

foreach (var descriptor in descriptors)
{
services.Remove(descriptor);
}

services.AddScoped(sp =>
{
// Replace SQLite with in-memory database for tests

0 comments on commit 4304545

Please sign in to comment.