public DatabaseFixture() { var options = new DbContextOptionsBuilder <RivaIdentityDbContext>() .UseInMemoryDatabase("RivaIdentityDatabaseIntegrationTestsDb").Options; Context = new RivaIdentityDbContext(options); Context.ClearDatabase(); }
protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.ConfigureTestServices(services => { var descriptor = services.SingleOrDefault(x => x.ServiceType == typeof(DbContextOptions <RivaIdentityDbContext>)); if (descriptor != null) { services.Remove(descriptor); } descriptor = services.SingleOrDefault(x => x.ServiceType == typeof(IIntegrationEventBus)); if (descriptor != null) { services.Remove(descriptor); } descriptor = services.SingleOrDefault(x => x.ServiceType == typeof(IPersistedGrantRepository)); if (descriptor != null) { services.Remove(descriptor); } descriptor = services.SingleOrDefault(x => x.ServiceType == typeof(IAccountDataConsistencyService)); if (descriptor != null) { services.Remove(descriptor); } services .AddDbContext <RivaIdentityDbContext>((options, context) => context.UseInMemoryDatabase(_databaseName)); var sp = services.BuildServiceProvider(); _serviceScope = sp.CreateScope(); var scopedServices = _serviceScope.ServiceProvider; DbContext = scopedServices.GetRequiredService <RivaIdentityDbContext>(); DbContext.Database.EnsureCreated(); DbContext.ClearDatabase(); services.AddSingleton <IIntegrationEventBus, IntegrationEventBusStub>(); services.AddScoped <IPersistedGrantRepository, PersistedGrantRepositoryStub>(); services.AddScoped <IAccountDataConsistencyService, AccountDataConsistencyServiceStub>(); }); }