private WeatherContext CreateAndSeedContext() { var optionsBuilder = new DbContextOptionsBuilder<WeatherContext>(); optionsBuilder.UseInMemoryDatabase(); var context = new WeatherContext(optionsBuilder.Options); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.WeatherEvents.AddRange(BuildWeatherEvents()); context.SaveChanges(); return context; }
private WeatherContext CreateAndSeedContext() { // All contexts that share the same service provider will share the same InMemory database var serviceProvider = _services.BuildServiceProvider(); var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope(); context = serviceScope.ServiceProvider.GetService<WeatherContext>(); context.WeatherEvents.AddRange(BuildWeatherEvents()); context.SaveChanges(); return context; }