mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-07-03 12:02:55 +00:00
Adding db config for integration tests
This commit is contained in:
parent
c305529871
commit
5fb2752e5c
@ -5,6 +5,8 @@ using CleanArchitecture.IntegrationTests.Extensions;
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc.Testing;
|
using Microsoft.AspNetCore.Mvc.Testing;
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace CleanArchitecture.IntegrationTests.Infrastructure;
|
namespace CleanArchitecture.IntegrationTests.Infrastructure;
|
||||||
@ -48,6 +50,8 @@ public sealed class CleanArchitectureWebApplicationFactory : WebApplicationFacto
|
|||||||
builder.ConfigureServices(services =>
|
builder.ConfigureServices(services =>
|
||||||
{
|
{
|
||||||
services.SetupTestDatabase<ApplicationDbContext>(_connection);
|
services.SetupTestDatabase<ApplicationDbContext>(_connection);
|
||||||
|
services.SetupTestDatabase<EventStoreDbContext>(_connection);
|
||||||
|
services.SetupTestDatabase<DomainNotificationStoreDbContext>(_connection);
|
||||||
|
|
||||||
var sp = services.BuildServiceProvider();
|
var sp = services.BuildServiceProvider();
|
||||||
|
|
||||||
@ -55,9 +59,19 @@ public sealed class CleanArchitectureWebApplicationFactory : WebApplicationFacto
|
|||||||
var scopedServices = scope.ServiceProvider;
|
var scopedServices = scope.ServiceProvider;
|
||||||
|
|
||||||
var applicationDbContext = scopedServices.GetRequiredService<ApplicationDbContext>();
|
var applicationDbContext = scopedServices.GetRequiredService<ApplicationDbContext>();
|
||||||
|
var storeDbContext = scopedServices.GetRequiredService<EventStoreDbContext>();
|
||||||
|
var domainStoreDbContext = scopedServices.GetRequiredService<DomainNotificationStoreDbContext>();
|
||||||
|
|
||||||
applicationDbContext.EnsureMigrationsApplied();
|
applicationDbContext.EnsureMigrationsApplied();
|
||||||
|
|
||||||
|
var creator2 = (RelationalDatabaseCreator)storeDbContext.Database
|
||||||
|
.GetService<IRelationalDatabaseCreator>();
|
||||||
|
creator2.CreateTables();
|
||||||
|
|
||||||
|
var creator3 = (RelationalDatabaseCreator)domainStoreDbContext
|
||||||
|
.Database.GetService<IRelationalDatabaseCreator>();
|
||||||
|
creator3.CreateTables();
|
||||||
|
|
||||||
_addCustomSeedDataHandler?.Invoke(applicationDbContext);
|
_addCustomSeedDataHandler?.Invoke(applicationDbContext);
|
||||||
_registerCustomServicesHandler?.Invoke(services, sp, scopedServices);
|
_registerCustomServicesHandler?.Invoke(services, sp, scopedServices);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user