public async Task <IActionResult> GetCurrentWeatherAsync([Required][FromQuery] string city, CancellationToken ct) { _logger.LogDebug("Retrieving current weather"); try { WeatherGetModel result = await _openWeatherClient.GetCurrentWeatherInAsync(city, ct); _logger.LogDebug("Retrieved the result"); return(Ok(result)); } catch (HttpStatusException ex) { _logger.LogWarning("The service returned an unexpected status code: {0}", ex.StatusCode); return(StatusCode((int)ex.StatusCode)); } }
public async Task Test_GetCurrentWeatherAsync_Returns_Weather() { const string city = "Mountain View"; Integration.WeatherApi.Given(Request.Create() .WithPath("/data/2.5/weather") .WithParam("appid", Integration.MockWeatherApiKey) .WithParam("q", city)) .RespondWith(Response.Create() .WithSuccess() .WithBodyFromFile("Controllers\\mockWeatherResponse.json")); IWeatherForecastClient client = Integration.CreateClient(); WeatherGetModel weather = await client.GetCurrentWeatherIn(city, CancellationToken.None); Assert.AreEqual(weather.Name, "Mountain View"); }