diff --git a/aspnetcore/test/integration-tests/samples/3.x/IntegrationTestsSample/tests/RazorPagesProject.Tests/CustomWebApplicationFactory.cs b/aspnetcore/test/integration-tests/samples/3.x/IntegrationTestsSample/tests/RazorPagesProject.Tests/CustomWebApplicationFactory.cs index 8bedf4084c..fcfbe3e010 100644 --- a/aspnetcore/test/integration-tests/samples/3.x/IntegrationTestsSample/tests/RazorPagesProject.Tests/CustomWebApplicationFactory.cs +++ b/aspnetcore/test/integration-tests/samples/3.x/IntegrationTestsSample/tests/RazorPagesProject.Tests/CustomWebApplicationFactory.cs @@ -17,27 +17,19 @@ namespace RazorPagesProject.Tests { builder.ConfigureServices(services => { - // Remove the app's ApplicationDbContext registration. var descriptor = services.SingleOrDefault( d => d.ServiceType == typeof(DbContextOptions)); - if (descriptor != null) - { - services.Remove(descriptor); - } + services.Remove(descriptor); - // Add ApplicationDbContext using an in-memory database for testing. services.AddDbContext(options => { options.UseInMemoryDatabase("InMemoryDbForTesting"); }); - // Build the service provider. var sp = services.BuildServiceProvider(); - // Create a scope to obtain a reference to the database - // context (ApplicationDbContext). using (var scope = sp.CreateScope()) { var scopedServices = scope.ServiceProvider; @@ -45,12 +37,10 @@ namespace RazorPagesProject.Tests var logger = scopedServices .GetRequiredService>>(); - // Ensure the database is created. db.Database.EnsureCreated(); try { - // Seed the database with test data. Utilities.InitializeDbForTests(db); } catch (Exception ex)