Beispiel #1
0
        public async Task WhenExecuteDeleteIfIdIsNullThenNotFoundResult()
        {
            TourDTO             tour = null;
            Mock <ITourService> mock = new Mock <ITourService>();

            mock.Setup(repo => repo.Get(It.IsAny <int>())).ReturnsAsync(tour);
            mock.Setup(repo => repo.Delete(tour)).ReturnsAsync(tour);

            TourController controller = new TourController(mock.Object, null, null, null, null, null, null, null, null, null);
            IActionResult  result     = await controller.Delete(It.IsAny <int>());

            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
Beispiel #2
0
        public async Task WhenExecuteDeleteIfIdNotNullThenGetOkResult()
        {
            TourDTO             tour = new TourDTO();
            Mock <ITourService> mock = new Mock <ITourService>();

            mock.Setup(repo => repo.Get(It.IsAny <int>())).ReturnsAsync(tour);
            mock.Setup(repo => repo.Delete(tour)).ReturnsAsync(tour);

            TourController controller = new TourController(mock.Object, null, null, null, null, null, null, null, null, null);
            IActionResult  result     = await controller.Delete(It.IsAny <int>());

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

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(resTour, typeof(TourDTO));
            Assert.IsNotNull(resTour as TourDTO);
        }