public void SaveNullShouldNotTryAddToDatabase() { //Arrange WeatherMain expecWeatherMain = new WeatherMain() { Humidity = 0, Pressure = 0, Temperature = 0, TemperatureMin = 0, TemperatureMax = 0, }; Wind expectedWind = new Wind() { Direction = 0, Speed = 0 }; PredictionDate expectedPredictionDate = new PredictionDate() { Time = DateTime.Now, }; Clouds expectedClouds = new Clouds() { All = 0 }; Forecast expectedForecast = new Forecast() { Clouds = expectedClouds, WeatherMain = expecWeatherMain, Wind = expectedWind, Time = expectedPredictionDate, CityId = 0 }; ForecastEntity expectedEntity = new ForecastEntity() { WeatherMain = expecWeatherMain, Wind = expectedWind, PredictionDate = expectedPredictionDate, Clouds = expectedClouds, CityServiceId = 0, Forecast = expectedForecast }; var weatherContextMock = new Mock <WeatherDataContext>(); weatherContextMock.Setup(x => x.Forecast.Add(It.IsAny <Forecast>())).Returns((Forecast f) => f); weatherContextMock.Setup(x => x.City.Add(It.IsAny <City>())).Returns((City f) => f); weatherContextMock.Setup(x => x.Clouds.Add(It.IsAny <Clouds>())).Returns((Clouds f) => f); weatherContextMock.Setup(x => x.PredictionDate.Add(It.IsAny <PredictionDate>())).Returns((PredictionDate f) => f); weatherContextMock.Setup(x => x.WeatherMain.Add(It.IsAny <WeatherMain>())).Returns((WeatherMain f) => f); weatherContextMock.Setup(x => x.Wind.Add(It.IsAny <Wind>())).Returns((Wind f) => f); WeatherManager weather = new WeatherManager(weatherContextMock.Object); //Act var savedEntities = weather.SaveForecastEntity(expectedEntity).Result; //Assert Assert.Equal(1, savedEntities); weatherContextMock.Verify(x => x.SaveChangesAsync(), Times.Never); }
public ForecastEntity ConvertEntity(Forecast forecast) { Clouds clouds = forecast.Clouds; PredictionDate predictionDate = forecast.Time; WeatherMain weatherMain = forecast.WeatherMain; Wind wind = forecast.Wind; ForecastEntity forecastEntity = new ForecastEntity { Clouds = clouds, PredictionDate = predictionDate, WeatherMain = weatherMain, Wind = wind }; return(forecastEntity); }
public ForecastEntity GetForecastEntity(City city, DateTime date) { DateTime preciseTime = GetCLosestForecastTime(date); var forecast = dataContext.Forecast.Where(f => f.Time.Time == preciseTime).Where(c => c.City.ServiceId == city.ServiceId).First(); Clouds clouds = forecast.Clouds; PredictionDate predictionDate = forecast.Time; WeatherMain weatherMain = forecast.WeatherMain; Wind wind = forecast.Wind; ForecastEntity forecastEntity = new ForecastEntity { Clouds = clouds, PredictionDate = predictionDate, WeatherMain = weatherMain, Wind = wind }; return(forecastEntity); }
private List <ForecastEntity> ConvertEntities(IQueryable <Forecast> forecast) { List <ForecastEntity> forecasts = new List <ForecastEntity>(); foreach (var item in forecast) { Clouds clouds = item.Clouds; PredictionDate predictionDate = item.Time; WeatherMain weatherMain = item.WeatherMain; Wind wind = item.Wind; ForecastEntity forecastEntity = new ForecastEntity { Clouds = clouds, PredictionDate = predictionDate, WeatherMain = weatherMain, Wind = wind }; forecasts.Add(forecastEntity); } return(forecasts); }