Beispiel #1
0
        public void ShouldFormatMultipleCityWeather()
        {
            // Arrange
            var list = new List <CityWeather> {
                new CityWeather
                {
                    City          = "Kiev",
                    Precipitation = 1,
                    Temperature   = 1,
                    Weather       = "Sunny"
                },
                new CityWeather
                {
                    City          = "Riga",
                    Precipitation = 2,
                    Temperature   = 3,
                    Weather       = "Sunny"
                }
            };
            var sut = new WeatherFormatter();

            // Act
            var result = sut.FormatWeather(list);

            // Assert
            Assert.IsTrue(result.Contains(list[0].City + " | "));
            Assert.IsTrue(result.Contains(list[1].City + " | "));
            Assert.IsTrue(result.Contains("--------------------------------------"));
        }
Beispiel #2
0
        public void ShouldFormatEmptyCityWeather()
        {
            // Arrange
            var sut = new WeatherFormatter();

            // Act
            var result = sut.FormatWeather(new List <CityWeather>());

            // Assert
            Assert.IsTrue(result.Contains("--------------------------------------"));
        }
Beispiel #3
0
        private async Task <string> GetMarkdown(long chatId)
        {
            var document = await WeatherParser.GetAsync();

            if (document == null)
            {
                await this.ReplyAsync(chatId, "Информация о погоде недоступна.");

                return(string.Empty);
            }

            return(WeatherFormatter.Format(document));
        }
Beispiel #4
0
        public void ShouldFormatOneCityWeather()
        {
            // Arrange
            var cityWeather = new CityWeather
            {
                City          = "Kiev",
                Precipitation = 1,
                Temperature   = 1,
                Weather       = "Sunny"
            };
            var sut = new WeatherFormatter();

            // Act
            var result = sut.FormatWeather(new List <CityWeather> {
                cityWeather
            });

            // Assert
            Assert.IsTrue(result.Contains(cityWeather.City + " | "));
        }
        public async Task <WeatherResults> Get([FromBody] AddressData address)
        {
            Geolocation gl = new Geolocation(_configuration);

            //var address = JsonConvert.DeserializeObject<AddressData>(rawAddress);

            Coordinates coordinates = gl.GetLatAndLong(address);

            string key      = _configuration["OpenWeatherApiKey"];
            var    request  = $"https://api.openweathermap.org/data/2.5/onecall?lat={coordinates.Lat}&lon={coordinates.Long}&exclude=hourly,daily&appid={key}";
            var    client   = _clientFactory.CreateClient();
            var    response = await client.GetAsync(request);

            var responseBody = await response.Content.ReadAsStringAsync();

            //TODO: Create object to deserialize to
            var forecast = JsonConvert.DeserializeObject <RawWeather>(responseBody);

            //convert values to readable values - check if you need json property
            var results = WeatherFormatter.FormatWeather(forecast);

            return(results);
        }