async Task <WeatherResponse> BuildWeatherResponse( HttpContent current, HttpContent forecast ) { var currentRead = current.ReadAsAsync <WeatherQueryEntry>(); var forecastRead = forecast.ReadAsAsync <WeatherQueryList>(); return(WeatherBuilder.Build(await currentRead, await forecastRead)); }
public async Task GetWeather_NonExistingCityAndNonExistingState_ShouldReturnStatusCode400() { Weather weatherRequest = WeatherBuilder.New().WithCity("--").WithState("--").Build(); var request = new RestRequest("/getweather") .AddParameter("city", weatherRequest.City) .AddParameter("state", weatherRequest.State); var response = await _client.ExecuteGetTaskAsync <Weather>(request); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); response.StatusDescription.Should().Be("Bad Request"); }
public async Task GetWeather_CityAndState_ShouldValidStatusCode(string city, string state, HttpStatusCode expectedStatusCode, string expectedStatusDescription) { Weather weatherRequest = WeatherBuilder.New().WithCity(city).WithState(state).Build(); var request = new RestRequest("/getweather") .AddParameter("city", weatherRequest.City) .AddParameter("state", weatherRequest.State); var response = await _client.ExecuteGetTaskAsync <Weather>(request); response.StatusCode.Should().Be(expectedStatusCode); response.StatusDescription.Should().Be(expectedStatusDescription); }
public async Task Given_A_City_Request_Validate_WeatherInformation_Returned() { var mockCities = new List <City> { new CityBuilder().WithId(1) .WithName("CityA") .WithCountry("CounterA") .WithTouristRating(1) .WithEstimatedPopulation(100) .WithDateEstablished(new DateTime(1800, 1, 1)) .Build() }; var expectedWeatherInfo = new WeatherBuilder() .WithDescription("Cloudy") .WithTemperature(15.6F) .WithMaximumTemperature(16) .WithMinimumTemperature(15) .WithPressure(1012) .WithHimidity(75) .Build(); _weatherService.Setup(x => x.GetWeatherAsync(It.IsAny <string>())).ReturnsAsync(expectedWeatherInfo); var service = new ServiceCore(_cityRepository.Object, _weatherService.Object, _countryService.Object, _mapper); _cityRepository.Setup(x => x.GetCityByNameAsync(It.IsAny <string>())).ReturnsAsync(mockCities); //Act var cities = await service.GetCityByNameAsync("CityName"); var actualWeatherInfo = cities.FirstOrDefault().Weather; //Assert Assert.AreEqual(actualWeatherInfo.Description, "Cloudy"); Assert.AreEqual(actualWeatherInfo.Temperature, 15.6M); Assert.AreEqual(actualWeatherInfo.TemperatureMaximum, 16); Assert.AreEqual(actualWeatherInfo.TemperatureMinimum, 15); Assert.AreEqual(actualWeatherInfo.Humidity, 75); Assert.AreEqual(actualWeatherInfo.Pressure, 1012); }