public void Test_SelectLongTermEntry_SecondOne() { //Arrange IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock()); var forecast = new ForecastLongTerm(); var entry1 = new ForecastDailyEntry(); entry1.UnixTimestamp = 1335913200; //2012/05/01 23:00 var entry2 = new ForecastDailyEntry(); entry2.UnixTimestamp = 1335927600; //2012/05/02 03:00 forecast.Entries = new List <ForecastDailyEntry>() { entry1, entry2 }; var locDetail = new LocationDetail(); locDetail.Time = new DateTime(2012, 5, 1, 0, 0, 0); //Act var entry = weatherUtils.SelectLongTermEntry(locDetail, forecast); //Assert - entry2 should be selected Assert.AreEqual(1335913200, entry.UnixTimestamp); }
public void Test_SelectLongTermEntry_Argument1Null() { IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock()); var fc = new ForecastLongTerm(); weatherUtils.SelectLongTermEntry(null, fc); }
public ForecastDailyEntry SelectLongTermEntry(LocationDetail location, ForecastLongTerm forecast) { var mockWeatherProvider = new MockWeatherProvider(); var task = mockWeatherProvider.GetForecastLongTerm(new Location()); Task.WhenAll(task); return(task.Result.Entries[0]); }
public void Test_SelectLongTermEntry_NoEntries() { IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock()); LocationDetail loc = new LocationDetail(); var fc = new ForecastLongTerm(); fc.Entries = new List <ForecastDailyEntry>(); var result = weatherUtils.SelectLongTermEntry(loc, fc); Assert.AreEqual("N/A", result.WeatherDescription[0].Description); }
/// <summary> /// Selects daily weather forecast for location's estimated date. /// </summary> /// <param name="location">Location</param> /// <param name="forecast">Forecasts for location</param> /// <returns>Forecast for the day</returns> public ForecastDailyEntry SelectLongTermEntry(LocationDetail location, ForecastLongTerm forecast) { if (location == null) { throw new ArgumentNullException("Location is null"); } if (forecast == null) { throw new ArgumentNullException("Forecast is null"); } var entry = forecast.Entries.FirstOrDefault(x => x.ForecastTime.Date == location.Time.Date); if (entry == null) { string msg = "No forecast for the day selected"; log.Error(msg); int hrs = 12; int min = 0; var lastEntry = forecast.Entries.LastOrDefault(); if (lastEntry != null) { hrs = lastEntry.ForecastTime.Hour; min = lastEntry.ForecastTime.Minute; } return(new ForecastDailyEntry() { Clouds = 0, Deg = 0, Humidity = 0, Pressure = 0, Rain = 0, Speed = 0, Temp = new Temp() { Day = 0, Eve = 0, Max = 0, Min = 0, Morn = 0, Night = 0 }, UnixTimestamp = (int)UnixTimeConverter.DateTimeToUnixTimestamp( new DateTime() .AddYears(location.Time.Year) .AddMonths(location.Time.Month) .AddDays(location.Time.Day) .AddHours(hrs) .AddMinutes(min)), WeatherDescription = new List <WeatherDescription>() { new WeatherDescription() { Description = "N/A", Icon = "N/A", Id = 0, Main = "N/A" } } }); //throw new NullReferenceException(msg); } return(entry); }