Beispiel #1
0
        public void GetCurrentWeatherByCity_When_Has_OK_Returns_Success()
        {
            var request = new ParameterRequest();

            request.City  = "Mauá";
            request.State = "SP";

            var response = new CityResponse()
            {
                StatusCode = HttpStatusCode.OK,
                Detail     = "Falha de comunicação.",
                Id         = 3954,
                Name       = "Nublado",
                State      = "SP",
                Country    = "Brasil",
            };

            _service.GetCurrentWeatherByCity(request).Returns(response);

            var controller = new WeatherController(_service);

            var result = controller.GetCurrentWeatherByCity(request);

            result.Should().BeEquivalentTo(new OkObjectResult(response));
        }
Beispiel #2
0
        public void GetCurrentWeatherByCity_When_CustomerService_Throws_Exceptions_Returns_InternalServerError()
        {
            var parameterRequest = new ParameterRequest();

            parameterRequest.City  = "Mauá";
            parameterRequest.State = "SP";

            var controller = new WeatherController(_service);

            _service.GetCurrentWeatherByCity(parameterRequest).Throws(new Exception());

            var result = controller.GetCurrentWeatherByCity(parameterRequest);

            result.Should().BeEquivalentTo(new StatusCodeResult(StatusCodes.Status500InternalServerError));
        }
Beispiel #3
0
        public void GetCurrentWeatherByCity_When_Parameters_IsNull_OrEmpty_Returns_BadRequest(string city, string state)
        {
            ParameterRequest request = null;

            if (city != null || state != null)
            {
                request = new ParameterRequest {
                    City = city, State = state
                }
            }
            ;

            var result = new ErrorResponse();

            result.Message = "Cidade ou Estado Inválidos";
            var controller = new WeatherController(_service);
            var response   = controller.GetCurrentWeatherByCity(request);

            response.Should().BeEquivalentTo(new BadRequestObjectResult(result));
        }
Beispiel #4
0
        public void GetCurrentWeatherByCity_When_InvalidCity_Returns_BadRequest()
        {
            var request = new ParameterRequest()
            {
                City = "Mauaaa", State = "SP"
            };
            var errorMessage = new ErrorResponse()
            {
                Message = "Cidade invalida, verifique."
            };

            CityResponse response = null;

            _service.GetCurrentWeatherByCity(request).Returns(response);

            var controller = new WeatherController(_service);

            var result = controller.GetCurrentWeatherByCity(request);

            result.Should().BeEquivalentTo(new BadRequestObjectResult(errorMessage));
        }