protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.ConfigureServices(services => { var descriptor = services.SingleOrDefault( d => d.ServiceType == typeof(DbContextOptions <ProductContext>)); services.Remove(descriptor); services.AddDbContext <ProductContext>(options => { options.UseInMemoryDatabase("InMemoryDbForTesting"); }); //services.AddDbContext<ProductContext>(opt => DbContextMocker.GetDbContextOptions("MockData")); var sp = services.BuildServiceProvider(); using (var scope = sp.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <ProductContext>(); db.Database.EnsureCreated(); DbInitializerTest.Initialize(db); } }); }
public static void Config() { if (ServiceLocator == null) { IWareService WareServiceGetter(IServiceLocator serviceLocator) => new WareService(new WareRepositoryTest(), serviceLocator); IClientService ClientServiceGetter(IServiceLocator serviceLocator) => new ClientService(new ClientRepositoryTest(), serviceLocator); INotificationService NotificationServiceGetter(IServiceLocator serviceLocator) => new NotificationService(new NotificationRepositoryTest(), serviceLocator); ServiceLocator = new ServiceLocator(WareServiceGetter, ClientServiceGetter, NotificationServiceGetter); } DbInitializerTest.Initialize(); }