public async Task StartAsync(CancellationToken cancellationToken) { // Create a new scope to retrieve scoped services using (var scope = _serviceProvider.CreateScope()) { // Get the DbContext instance var forecastContext = scope.ServiceProvider.GetRequiredService <ForecastContext>(); var solarSystem = SolarSystemFactory.GenerateSolarSystem(); var weatherControlSystem = new WeatherControlSystem(solarSystem); await forecastContext.Forecasts.AddRangeAsync(weatherControlSystem.CalculateForecast(3650)); await forecastContext.SaveChangesAsync(); } }
public void SolarSystem_GetForecast_ReturnForecast() { var earth = new Planet("Earth", 1000, 1); var mars = new Planet("Mars", 2000, 3); var neptune = new Planet("Neptune", 3000, 5); var planets = new List <Planet>() { earth, mars, neptune }; var solarSystem = new Entities.SolarSystem.SolarSystem(planets); var weatherControlSystem = new WeatherControlSystem(solarSystem); var forecast = weatherControlSystem.CalculateForecast(50); forecast.Count.Should().Be(50); }
public void RainySolarSystem_GetForecast_ReturnRainy() { var earth = new Planet("Earth", 1000, 45); var mars = new Planet("Mars", 2000, 135); var neptune = new Planet("Neptune", 3000, -90); var planets = new List <Planet>() { earth, mars, neptune }; var solarSystem = new Entities.SolarSystem.SolarSystem(planets); var weatherControlSystem = new WeatherControlSystem(solarSystem); var forecast = weatherControlSystem.CalculateSingleForecast(1); forecast.Day.Should().Be(1); forecast.Weather.Should().Be(Weather.Rainy); forecast.RainfallIntensity.Should().BeGreaterThan(0); }