Fix Multiple DbContext Registration (#703)
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
This commit is contained in:
@@ -23,6 +23,16 @@ public class TestApplication : WebApplicationFactory<IBasketViewModelService>
|
|||||||
// Add mock/test services to the builder here
|
// Add mock/test services to the builder here
|
||||||
builder.ConfigureServices(services =>
|
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 =>
|
services.AddScoped(sp =>
|
||||||
{
|
{
|
||||||
// Replace SQLite with in-memory database for tests
|
// Replace SQLite with in-memory database for tests
|
||||||
|
|||||||
Reference in New Issue
Block a user