Esempio n. 1
0
        public async Task GetCities_WeatherInfo_Success()
        {
            // Arrange
            var testDayDate = new DateTime(2019, 8, 9, 0, 0, 0);
            var tempDay     = 18;
            var tempNight   = -20;
            var comment     = "Небольшой дождь";

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock.Setup(x => x.GetAsync(It.IsAny <Uri>())).Returns(Task.FromResult(_pageFull));
            var page = new WeatherPage(new Uri("https://yandex.ru/pogoda/saint-petersburg"), requestProviderMock.Object);

            // Act
            await page.LoadPageAsync();

            var weather = page.GetWeather().ToList();

            // Assert
            var specialDay = weather.First(d => d.Date.Date == testDayDate.Date);

            Assert.Equal(tempDay, specialDay.TempDay);
            Assert.Equal(tempNight, specialDay.TempNight);
            Assert.Equal(comment, specialDay.Comment);
        }
Esempio n. 2
0
        public async Task GetCities_CorruptedPage_Success()
        {
            // Arrange
            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock.Setup(x => x.GetAsync(It.IsAny <Uri>())).Returns(Task.FromResult("Corrupted page"));
            var page = new WeatherPage(new Uri("https://yandex.ru/pogoda/saint-petersburg"), requestProviderMock.Object);

            // Act
            await page.LoadPageAsync();

            var weather = page.GetWeather().ToList();

            // Assert
            Assert.Empty(weather);
        }
Esempio n. 3
0
        public async Task <IEnumerable <Domain.Models.Weather> > GetWeatherAsync(string cityUrl)
        {
            if (cityUrl == null)
            {
                throw new ArgumentNullException(nameof(cityUrl));
            }

            try
            {
                var weatherPage = new WeatherPage(new Uri(cityUrl), _requestProvider);
                await weatherPage.LoadPageAsync();

                var weatherData = weatherPage.GetWeather();
                return(weatherData.Select(w => new Domain.Models.Weather(w.Date, w.TempDay, w.TempNight, w.Comment)));
            }
            catch (Exception e)
            {
                throw new Domain.Exceptions.WeatherProviderServiceException(e.Message, e);
            }
        }