public async Task GetWeather_Success_ResultWeatherResult() { string country = "Poland"; string city = "Warsaw"; HttpResponseMessage failResponseMessage = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; IResponseToWeatherResultMapper responseToWeatherResultMapper = Substitute.For <IResponseToWeatherResultMapper>(); WeatherResult expectedWeatherResult = new WeatherResult() { location = new Location() { country = country, city = city }, temperature = new Temperature() { format = "Celsius", value = 40.1 }, humidity = 52.1 }; responseToWeatherResultMapper.Map(Arg.Any <HttpResponseMessage>()).Returns(expectedWeatherResult); ICustomHttpClient httpClient = Substitute.For <ICustomHttpClient>(); httpClient.GetAsync(Arg.Any <Uri>(), Arg.Any <string>()).Returns(failResponseMessage); var weatherService = new WeatherService(httpClient, responseToWeatherResultMapper); var weatherResult = await weatherService.GetWeather(country, city); Assert.Equal(expectedWeatherResult, weatherResult); }
public WeatherService(ICustomHttpClient httpClient, IResponseToWeatherResultMapper responseToWeatherResultMapper) { _httpClient = httpClient; _responseToWeatherResultMapper = responseToWeatherResultMapper; }
public WeatherService() { _httpClient = new CustomHttpClient(); _responseToWeatherResultMapper = new ResponseToWeatherResultMapper(); }