protected override void ConfigureWebHost(IWebHostBuilder builder) { SetupEnvironmentVariables(); builder.ConfigureServices(services => { RemoveDefaultDbContextFromServiceCollection(services); RemoveDefaultDistributedCacheFromServiceCollection(services); services.AddDistributedMemoryCache(); services.AddDbContext <SurveyContext>(options => { options.UseInMemoryDatabase("InMemoryDbForTesting"); }); ConfigureMockServices(services); var rootServiceProvider = services.BuildServiceProvider(); using var scope = rootServiceProvider.CreateScope(); var scopedServiceProvider = scope.ServiceProvider; var context = scopedServiceProvider.GetRequiredService <SurveyContext>(); var logger = scopedServiceProvider .GetRequiredService <ILogger <IntegrationTestWebApplicationFactory <TStartup> > >(); var cache = scopedServiceProvider.GetRequiredService <IDistributedCache>(); cache.Remove("FakeSurveyGenerator"); context.Database.EnsureCreated(); try { DatabaseSeed.SeedSampleData(context); } catch (Exception ex) { logger.LogError(ex, "An error occurred seeding the database with test surveys. Error: {Message}", ex.Message); } }); }
public static void SeedSampleData(SurveyContext context) { DatabaseSeed.SeedSampleData(context); }
public static async Task SeedSampleData(SurveyContext context) { await DatabaseSeed.SeedSampleData(context); }