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

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

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

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

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

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

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

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(resTour, typeof(TourDTO));
            Assert.IsNotNull(resTour as TourDTO);
            Assert.AreEqual(resTour, tour);
        }
예제 #3
0
        public async Task WhenExecuteGetAllThenGetCollection()
        {
            //Arrange
            List <TourDTO> tourDTOs = new List <TourDTO>
            {
                new TourDTO(),
                new TourDTO()
            };
            Mock <ITourService> mock = new Mock <ITourService>();

            mock.Setup(repo => repo.Get()).ReturnsAsync(tourDTOs);

            //Act
            TourController controller = new TourController(mock.Object, null, null, null, null, null, null, null, null, null);
            IActionResult  result     = await controller.Get();

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

            //Assert
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(tours, typeof(IEnumerable <TourDTO>));
            Assert.IsNotNull(tours as IEnumerable <TourDTO>);
            Assert.AreEqual(tourDTOs, tours);
        }