Ejemplo n.º 1
0
        public async Task WhenExecuteAddHotelIfModelIsValidThenGetOkResult()
        {
            HotelDTO             hotel = new HotelDTO();
            Mock <IHotelService> mock  = new Mock <IHotelService>();

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

            TourController controller = new TourController(null, null, null, mock.Object, null, null, null, null, null, null);
            IActionResult  result     = await controller.AddHotel(hotel);

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

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(res, typeof(HotelDTO));
            Assert.IsNotNull(res as HotelDTO);
        }
Ejemplo n.º 2
0
        public async Task WhenExecuteAddHotelIfModelNotValidThenBadRequestResult()
        {
            HotelDTO             hotel = null;
            Mock <IHotelService> mock  = new Mock <IHotelService>();

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

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

            controller.ModelState.AddModelError("", "");
            IActionResult result = await controller.AddHotel(hotel);

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

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