Esempio n. 1
0
        public void ModelMappingTest()
        {
            var response = WeatherForecastModelConverter.Convert(new Services.Models.WeatherForecastResponse
            {
                Humidity = 39.6,
                Location = new Services.Models.Location
                {
                    City    = "Warsaw",
                    Country = "Poland"
                },
                Tempreature = new Services.Models.Tempreature
                {
                    Format = "Celsius",
                    Value  = 22.1
                }
            });

            Assert.NotNull(response);
            Assert.NotNull(response.Location);
            Assert.NotNull(response.Tempreature);
            Assert.Equal(39.6, response.Humidity);
            Assert.Equal("warsaw", response.Location.City.ToLower());
            Assert.Equal("poland", response.Location.Country.ToLower());
            Assert.Equal("celsius", response.Tempreature.Format.ToLower());
            Assert.Equal(22.1, response.Tempreature.Value);
        }
Esempio n. 2
0
        public async System.Threading.Tasks.Task <IHttpActionResult> GetWeatherForecastAsync(string country, string city)
        {
            var response = await _weatherService.GetWeatherForecastAsync(new WeatherForecastRequest
            {
                Location = new Location
                {
                    City    = city,
                    Country = country
                },
                Configuration = new ApiConfiguration
                {
                    ApiKey = ConfigurationManager.AppSettings["OpenWeatherMapApiKey"]
                }
            });

            if (response != null && !(response is NullWeatherForecastResponse))
            {
                return(Ok(WeatherForecastModelConverter.Convert(response)));
            }
            else
            {
                return(NotFound());
            }
        }