public async void GetWeather_ShouldReturn_CurrentWeather()
        {
            var message =
                "{ \"coord\":{ \"lon\":139,\"lat\":35},\"sys\":{ \"country\":\"JP\",\"sunrise\":1369769524,\"sunset\":1369821049},"
                + "\"weather\":[{\"id\":804,\"main\":\"clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],"
                + "\"main\":{\"temp\":289.5,\"humidity\":89,\"pressure\":1013,\"temp_min\":287.04,\"temp_max\":292.04},"
                + "\"wind\":{\"speed\":7.31,\"deg\":187},"
                + "\"rain\":{\"3h\":0},"
                + "\"clouds\":{\"all\":92}," 
                + "\"dt\":1369824698,\"id\":1851632,\"name\":\"Shuzenji\",\"cod\":200}";
            var expected = new CurrentWeather
                               {
                                   CurrentTemprature = 289.5,
                                   Date = DateTime.Today + TimeSpan.FromTicks(1369824698),
                                   Humidity = 89,
                                   Location = new GeoLocation { City = "Shuzenji"},
                                   Precipation = 0,
                                   Pressure = 1013,
                                   RainingProbability = 0,
                                   Units = MeasureUnits.Celsium,
                                   Wind = new Wind { Degree = 187, Speed = 7.31},
                                   WeatherDescription = "clouds\r\novercast clouds"
            };
            this.mockedMessageHandler.Protected().Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(),ItExpr.IsAny<CancellationToken>()).ReturnsAsync(new HttpResponseMessage {Content = new StringContent(message),StatusCode = HttpStatusCode.OK});

            var actual = await this.sut.GetCurrentWeatherAsync(this.request);
            Assert.True(AssertExtenstions.DeepEqual(expected,actual));
        }
Exemplo n.º 2
0
        public CurrentWeather ToCurrentWeather()
        {
            var currentWeather = new CurrentWeather();

            currentWeather.CurrentTemprature = this.main.temp;
            currentWeather.Humidity = this.main.humidity;
            currentWeather.Pressure = (int)Math.Round(this.main.pressure);
            currentWeather.WeatherDescription = string.Concat(weather?[0]?.main, Environment.NewLine, weather?[0]?.description);
            currentWeather.Date = DateTime.Today + TimeSpan.FromTicks(this.TimeOfDay);
            currentWeather.Wind = this.wind;
            currentWeather.Location = new GeoLocation { City = this.name };

            return currentWeather;
        }