Ejemplo n.º 1
0
        public async Task WhenExecuteAddIfModelIsValidThenGetOkResult()
        {
            TourDTO             tour = AddDataTour();
            Mock <ITourService> mock = new Mock <ITourService>();

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

            TourController controller = new TourController(mock.Object, null, null, null, null, null, null, null, null, null);
            IActionResult  result     = await controller.Add(tour);

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

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(resTour, typeof(TourDTO));
            Assert.IsNotNull(resTour as TourDTO);
        }
Ejemplo n.º 2
0
        public async Task WhenExecuteAddIfModelIsNotValidThenBadRequestResult()
        {
            TourDTO             tour = new TourDTO();
            Mock <ITourService> mock = new Mock <ITourService>();

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

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

            controller.ModelState.AddModelError("", "");
            IActionResult result = await controller.Add(tour);

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

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