Esempio n. 1
0
        public void Get15DaysWeatherById_When_Parameter_IsNull_OrEmpty_Returns_BadRequest(string city, string state)
        {
            var request = new ParameterRequest()
            {
                City = null, State = null
            };

            if (city == null && state == null)
            {
                request = null;
            }
            else
            {
                request.City  = city;
                request.State = state;
            }

            var result = new ErrorResponse();

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

            response.Should().BeEquivalentTo(new BadRequestObjectResult(result));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        public void Get15DaysWeatherById_When_Has_OK_Returns_Success()
        {
            var request = new ParameterRequest()
            {
                City = "Mauá", State = "SP"
            };
            var controller = new WeatherController(_service);
            var response   = Substitute.For <DaysResponse>();

            _service.Get15DaysWeather(request).Returns(response);
            var result = controller.Get15daysWeatherById(request);

            result.Should().BeEquivalentTo(new OkObjectResult(response));
        }
Esempio n. 4
0
        public void Get15DaysWeatherById_When_InvalidCity_Returns_BadRequest()
        {
            var request = new ParameterRequest()
            {
                City = "Mauaaa", State = "SP"
            };
            var errorMessage = new ErrorResponse()
            {
                Message = "Cidade invalida, verifique."
            };

            DaysResponse response = null;

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

            var controller = new WeatherController(_service);

            var result = controller.Get15daysWeatherById(request);

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