Ejemplo n.º 1
0
        public async Task WhenExecuteAddCityIfModelIsValidThenGetOkResult()
        {
            CityDTO             city = new CityDTO();
            Mock <ICityService> mock = new Mock <ICityService>();

            mock.Setup(repo => repo.Add(city)).ReturnsAsync(city);

            TourController controller = new TourController(null, null, mock.Object, null, null, null, null, null, null, null);
            IActionResult  result     = await controller.AddCity(city);

            object resCountry = (result as OkObjectResult)?.Value;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(resCountry, typeof(CityDTO));
            Assert.IsNotNull(resCountry as CityDTO);
        }
Ejemplo n.º 2
0
        public async Task WhenExecuteAddCityIfModelNotValidThenBadRequestResult()
        {
            CityDTO             city = null;
            Mock <ICityService> mock = new Mock <ICityService>();

            mock.Setup(repo => repo.Add(city)).ReturnsAsync(city);

            TourController controller = new TourController(null, null, mock.Object, null, null, null, null, null, null, null);

            controller.ModelState.AddModelError("", "");
            IActionResult result = await controller.AddCity(city);

            object modelState = (result as BadRequestObjectResult)?.Value;

            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.IsInstanceOfType(modelState, typeof(SerializableError));
            Assert.IsNotNull(modelState as SerializableError);
        }