コード例 #1
0
        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);
        }
コード例 #2
0
 public WeatherService(ICustomHttpClient httpClient,
                       IResponseToWeatherResultMapper responseToWeatherResultMapper)
 {
     _httpClient = httpClient;
     _responseToWeatherResultMapper = responseToWeatherResultMapper;
 }
コード例 #3
0
 public WeatherService()
 {
     _httpClient = new CustomHttpClient();
     _responseToWeatherResultMapper = new ResponseToWeatherResultMapper();
 }