Exemple #1
0
        public void Test_SelectShortTermEntry_SecondOne()
        {
            //Arrange
            IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock());

            var forecast = new ForecastShortTerm();

            var entry1 = new ForecastShortTermEntry();

            entry1.UnixTimestamp = 978361200; //2001/01/01 15:00:00
            var entry2 = new ForecastShortTermEntry();

            entry2.UnixTimestamp = 978368400; //2001/01/01 17:00:00

            forecast.Entries = new List <ForecastShortTermEntry>()
            {
                entry1, entry2
            };

            var locDetail = new LocationDetail();

            locDetail.Time = new DateTime(2001, 01, 01, 16, 0, 1); //978364801

            //Act
            var entry = weatherUtils.SelectShortTermEntry(locDetail, forecast);

            //Assert - entry2 should be selected
            Assert.AreEqual(978368400, entry.UnixTimestamp);
        }
Exemple #2
0
        public void Test_SelectShortTermEntry_Argument1Null()
        {
            IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock());

            var fc = new ForecastShortTerm();

            weatherUtils.SelectShortTermEntry(null, fc);
        }
Exemple #3
0
        public ForecastShortTermEntry SelectShortTermEntry(LocationDetail location, ForecastShortTerm forecast)
        {
            var mockWeatherProvider = new MockWeatherProvider();
            var task = mockWeatherProvider.GetForecastShortTerm(new Location());

            Task.WhenAll(task);

            return(task.Result.Entries[0]);
        }
Exemple #4
0
        public void Test_SelectShortTermEntry_NoEntries()
        {
            IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock());

            var loc = new LocationDetail();
            var fc  = new ForecastShortTerm();

            fc.Entries = new List <ForecastShortTermEntry>();

            weatherUtils.SelectShortTermEntry(loc, fc);
        }
Exemple #5
0
        /// <summary>
        /// Selects closest forecast for location's estimated time.
        /// </summary>
        /// <param name="location">Location</param>
        /// <param name="forecast">Forecasts for location</param>
        /// <returns>Forecast entry closest</returns>
        public ForecastShortTermEntry SelectShortTermEntry(LocationDetail location, ForecastShortTerm forecast)
        {
            if (location == null)
            {
                throw new ArgumentNullException("Location is null");
            }
            if (forecast == null)
            {
                throw new ArgumentNullException("Forecast is null");
            }

            var entry = forecast.Entries
                        .OrderBy(e => (e.ForecastTime - location.Time).Duration())
                        .FirstOrDefault();

            if (entry == null)
            {
                string msg = "No forecast was chosen as closest";
                log.Error(msg);
                throw new NullReferenceException(msg);
            }
            return(entry);
        }