public async Task GetWeather_ReturnsWeatherResponseDto_WhenWeatherApiRequestisSuccessful()
        {
            // arrange
            var weatherRequestDto = new WeatherRequestDto
            {
                CityName = "London"
            };

            var query = new Dictionary <string, string>
            {
                ["cityName"] = weatherRequestDto.CityName
            };

            // act
            var response = await Client.GetAsync(QueryHelpers.AddQueryString(ApiRoutes.Weather.Get, query));

            // assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var weatherResponseDto = JsonSerializer.Deserialize <WeatherResponseDto>(
                await response.Content.ReadAsStringAsync(),
                new JsonSerializerOptions()
            {
                PropertyNameCaseInsensitive = true
            });

            weatherResponseDto.Location.Should().Be(weatherRequestDto.CityName);
        }
Example #2
0
        public async Task <IActionResult> Get([FromQuery] WeatherRequestDto dto)
        {
            var result = await _weatherService.GetCurrentWeatherDataByCityNameAsync(dto.CityName);

            if (result != null)
            {
                var responseDto = _mapper.Map <ExternalWeatherResponseDto, WeatherResponseDto>(result);

                return(new OkObjectResult(responseDto));
            }

            return(BadRequest());
        }
        public async Task GetWeather_ReturnsbadRequest_WhenCityNameContainsInvalidCharacters()
        {
            // arrange
            var weatherRequestDto = new WeatherRequestDto
            {
                CityName = "P@r!s"
            };

            var query = new Dictionary <string, string>
            {
                ["cityName"] = weatherRequestDto.CityName
            };

            // act
            var response = await Client.GetAsync(QueryHelpers.AddQueryString(ApiRoutes.Weather.Get, query));

            // assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }