Beispiel #1
0
        public void Get72WeatherById_When_CustomerService_Throws_Exceptions_Returns_InternalServerError()
        {
            var parameterRequest = new ParameterRequest()
            {
                City = "Mauá", State = "SP"
            };

            var controller = new WeatherController(_service);

            _service.Get72hrWeatherById(parameterRequest).Throws(new System.Exception());

            var result = controller.Get72hrWeatherById(parameterRequest);

            result.Should().BeEquivalentTo(new StatusCodeResult(StatusCodes.Status500InternalServerError));
        }
Beispiel #2
0
        public ActionResult Get72hrWeatherById([FromRoute] ParameterRequest request)
        {
            if (request == null || string.IsNullOrEmpty(request.City) || string.IsNullOrEmpty(request.State))
            {
                var result = new ErrorResponse();
                result.Message = "Cidade ou Estado Inválidos";
                return(new BadRequestObjectResult(result));
            }

            try
            {
                var result = _service.Get72hrWeatherById(request);

                if (result == null)
                {
                    var errorResponse = new ErrorResponse();
                    errorResponse.Message = "Cidade invalida, verifique.";
                    return(new BadRequestObjectResult(errorResponse));
                }

                return(new OkObjectResult(result));
            }
            catch
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
Beispiel #3
0
        public void Get72hrWeatherById_When_Parameter_IsNull_OrEmpty_Returns_BadRequest(string city, string state, bool hasInstance)
        {
            var request = !hasInstance ? null : new ParameterRequest()
            {
                City = city, State = state
            };

            var result        = _service.Get72hrWeatherById(request);
            var errorResponse = new HourResponse()
            {
                Detail     = "Parâmetros Inválidos",
                Data       = null,
                StatusCode = HttpStatusCode.BadRequest
            };

            result.Should().BeEquivalentTo(errorResponse);
        }