Update integration tests sample app (#19274)
parent
5b634b5d37
commit
97af55e45a
|
@ -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<ApplicationDbContext>));
|
||||
|
||||
if (descriptor != null)
|
||||
{
|
||||
services.Remove(descriptor);
|
||||
}
|
||||
services.Remove(descriptor);
|
||||
|
||||
// Add ApplicationDbContext using an in-memory database for testing.
|
||||
services.AddDbContext<ApplicationDbContext>(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<ILogger<CustomWebApplicationFactory<TStartup>>>();
|
||||
|
||||
// Ensure the database is created.
|
||||
db.Database.EnsureCreated();
|
||||
|
||||
try
|
||||
{
|
||||
// Seed the database with test data.
|
||||
Utilities.InitializeDbForTests(db);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Reference in New Issue