public void GetWeatherAsyncTest()
        {
            uint days_count = 10;

            Openweathermap map = new Openweathermap(Openweathermap.DEFAULT_KEY);

            var location = new Location
            {
                Attitude  = 59.916668f,
                Longitude = 30.25f
            };

            var weather = map.GetWeatherAsync(location, days_count).Result;

            Assert.IsNotNull(weather);
            Assert.AreEqual <uint>((uint)weather.Length, days_count);

            DateTime today = DateTime.Now;

            for (uint day = 0; day < days_count; ++day)
            {
                DateTime cur = today.AddDays(day);

                Assert.AreEqual(cur.Year, weather[day].Date.Year);
                Assert.AreEqual(cur.Month, weather[day].Date.Month);
                Assert.AreEqual(cur.Day, weather[day].Date.Day);
            }
        }
Пример #2
0
        public async Task <WeatherInfoModel> DownloadWeatherAsync(string city)
        {
            var jsonString = await GetWeatherAsync(city.ToLower());

            if (string.IsNullOrEmpty(jsonString))
            {
                throw new ArgumentOutOfRangeException(nameof(city));
            }

            var weatherFromJson = Openweathermap.FromJson(jsonString);

            return(WeatherInfoMapper.Map(weatherFromJson));
        }
Пример #3
0
 public static WeatherInfoModel Map(Openweathermap openweathermap)
 {
     return(new WeatherInfoModel
     {
         CityName = openweathermap.Name,
         Description = openweathermap.Weather.First().Main,
         Humidity = openweathermap.Main.Humidity,
         Icon = GetIcon(openweathermap.Weather.First().Icon),
         Sunrise = DateTimeOffset.FromUnixTimeSeconds(openweathermap.Sys.Sunrise).DateTime,
         Sunset = DateTimeOffset.FromUnixTimeSeconds(openweathermap.Sys.Sunset).DateTime,
         Temperature = (decimal)openweathermap.Main.Temp,
         WindDirection = (decimal)openweathermap.Wind.Deg,
         WindSpeed = (decimal)openweathermap.Wind.Speed
     });
 }