示例#1
0
 public void AddHistoryObject(HistoryWeatherDataObject historyObject)
 {
     using (var unitOfWork = _unitOfWorkFactory.Create())
     {
         unitOfWork.Repository <HistoryWeatherDataObject>().Add(historyObject);
         unitOfWork.SaveChanges();
     }
 }
示例#2
0
 public async Task AddHistoryObjectAsync(HistoryWeatherDataObject historyObject)
 {
     using (var unitOfWork = _unitOfWorkFactory.Create())
     {
         unitOfWork.Repository <HistoryWeatherDataObject>().Add(historyObject);
         await unitOfWork.SaveChangesAsync();
     }
 }
        public void TestSetup()
        {
            var city1 = new CityName {
                Id = 1, Name = "City1"
            };
            var city2 = new CityName {
                Id = 2, Name = "City2"
            };

            var reducedForecastPerDay = new ReducedForecastPerDay
            {
                Time          = 444,
                DayTemp       = 1,
                NightTemp     = 2,
                EveningTemp   = 3,
                MorningTemp   = 4,
                Rain          = "rain",
                Pressure      = 1000,
                Humidity      = 57,
                WindSpeed     = 12,
                WindDirection = 234,
                Clouds        = 65
            };
            var history1 = new HistoryWeatherDataObject
            {
                Id                    = 1,
                City                  = "city1",
                CountDays             = 1,
                RequestTime           = DateTime.Now,
                ReducedForecastPerDay = reducedForecastPerDay
            };
            var history2 = new HistoryWeatherDataObject
            {
                Id                    = 2,
                City                  = "city2",
                CountDays             = 1,
                RequestTime           = DateTime.Now,
                ReducedForecastPerDay = reducedForecastPerDay
            };
            var history3 = new HistoryWeatherDataObject
            {
                Id                    = 3,
                City                  = "city3",
                CountDays             = 1,
                RequestTime           = DateTime.Now,
                ReducedForecastPerDay = reducedForecastPerDay
            };

            _fakeCityRepository.Data.AddRange(new[] { city1, city2 });
            _fakeHistoryRepository.Data.AddRange(new[] { history1, history2, history3 });
        }
示例#4
0
        public void AddHistoryObject_When_history_Then_added_history()
        {
            // Arrange
            var reducedForecastPerDay = new ReducedForecastPerDay
            {
                Time          = 444,
                DayTemp       = 1,
                NightTemp     = 2,
                EveningTemp   = 3,
                MorningTemp   = 4,
                Rain          = "rain",
                Pressure      = 1000,
                Humidity      = 57,
                WindSpeed     = 12,
                WindDirection = 234,
                Clouds        = 65
            };

            var history1 = new HistoryWeatherDataObject
            {
                Id                    = 1,
                City                  = "city1",
                CountDays             = 1,
                RequestTime           = DateTime.Now,
                ReducedForecastPerDay = reducedForecastPerDay
            };

            // Act
            _weatherService.AddHistoryObject(history1);

            // Assert
            using (var db = new WeatherContext())
            {
                Assert.IsNotNull(db.History.FirstOrDefault(h => h.City == history1.City));
            }
        }