public void Get15DaysWeatherById_When_CustomerService_Throws_Exceptions_Returns_InternalServerError() { var parameterRequest = new ParameterRequest() { City = "Mauá", State = "SP" }; var controller = new WeatherController(_service); _service.Get15DaysWeather(parameterRequest).Throws(new Exception()); var result = controller.Get15daysWeatherById(parameterRequest); result.Should().BeEquivalentTo(new StatusCodeResult(StatusCodes.Status500InternalServerError)); }
public void GetDaysWeather_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.Get15DaysWeather(request); var response = new DaysResponse { Detail = "Parâmetros Inválidos", StatusCode = HttpStatusCode.BadRequest }; result.Should().BeEquivalentTo(response); }
public ActionResult Get15daysWeatherById([FromRoute] ParameterRequest request) { if (request == null || string.IsNullOrEmpty(request.City) || string.IsNullOrEmpty(request.State)) { var errorResponse = new ErrorResponse(); errorResponse.Message = "Cidade ou Estado Inválidos"; return(new BadRequestObjectResult(errorResponse)); } try { var result = _service.Get15DaysWeather(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)); } }