public void GetWeatherDataTest() { OpenWeatherMapService openWeatherMapService = OpenWeatherMapService.Instance; WeatherData exeptedWeatherData = new WeatherData(); City city = new City(); city.ID = "2643743"; city.Country = "GB"; city.Name = "London"; city.Lon = -0.13; city.Lat = 51.51; exeptedWeatherData.City = city; Location loction = new Location(); loction.Name = "London"; WeatherData actualWeatherData = openWeatherMapService.GetWeatherData(loction); Assert.IsNotNull(actualWeatherData); Assert.AreEqual(exeptedWeatherData.City.ID, actualWeatherData.City.ID); Assert.AreEqual(exeptedWeatherData.City.Country, actualWeatherData.City.Country); Assert.AreEqual(exeptedWeatherData.City.Name, actualWeatherData.City.Name); Assert.AreEqual(exeptedWeatherData.City.Lat, actualWeatherData.City.Lat); Assert.AreEqual(exeptedWeatherData.City.Lon, actualWeatherData.City.Lon); }
async void OnGetWeatherButtonClicked(object sender, EventArgs e) { try { var location = await Geolocation.GetLastKnownLocationAsync() ?? await Geolocation.GetLocationAsync(new GeolocationRequest()); var requestUri = GenerateRequestUri(Constants.OpenWeatherMapEndpoint, location.Latitude, location.Longitude); var weatherData = await _openWeatherMapService.GetWeatherData(requestUri); _brightnessService.SetBrightness(1f); BindingContext = weatherData; } catch (Exception ex) { Debug.WriteLine($"Error retrieving weather information: {ex.Message}"); } }
public async Task TestGetWeatherData_HttpClientFailure_Should_Return_Null() { var httpMessageResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, }; var mockHandler = new Mock <HttpMessageHandler>(); mockHandler .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(httpMessageResponse); var service = new OpenWeatherMapService(new HttpClient(mockHandler.Object), mockLogger.Object, mockConfig.Object); var result = await service.GetWeatherData("98012"); result.Should().Be(null); }
public async Task TestGetWeatherData_Success() { var result = await _service.GetWeatherData("98012"); result.Name.Should().Be("Bothell"); }