Exemplo n.º 1
0
        internal async void GivenIndexCalledWhenCinemasExistThenReturnsCinemas()
        {
            // Arange
            var dbModels   = modelFaker.GetTestCinemas(10);
            var viewModels = modelFaker.GetTestCinemaIndexes(10);

            mockCinemaService
            .Setup(_ => _.GetPagedAsync(0, 10, "Name", true))
            .ReturnsAsync(dbModels);
            mockCinemaService
            .Setup(_ => _.GetCountAsync())
            .ReturnsAsync(10);
            mockMapper
            .Setup(_ => _.Map <List <CinemaIndexViewModel> >(dbModels))
            .Returns(viewModels);

            // Act
            var response = await controllerUnderTest.Index();

            // Assert
            mockCinemaService.Verify(_ => _.GetPagedAsync(0, 10, "Name", true), Times.Once());
            mockMapper.Verify(_ => _.Map <List <CinemaIndexViewModel> >(dbModels), Times.Once());
            var result = Assert.IsType <ViewResult>(response);

            Assert.True(result != null);
            Assert.True(result is IActionResult);
            Assert.True(result.Model != null);
            var resultModel = Assert.IsType <PagerViewModel <CinemaIndexViewModel> >(result.Model);

            Assert.Same(viewModels, resultModel.Items);
        }
Exemplo n.º 2
0
        public void Can_Show_All_Movies_By_Index()
        {
            // Arrange
            var mock = new Mock <ICinemaRepository>();

            mock.Setup(m => m.Movies).Returns(new List <Movie> {
                new Movie {
                    MovieId = 1, Name = "T1"
                },
                new Movie {
                    MovieId = 2, Name = "T2"
                },
                new Movie {
                    MovieId = 3, Name = "T3"
                },
            }.AsQueryable());

            var controller = new CinemaController(mock.Object);

            //Act
            var result = (controller.Index().Model as IEnumerable <Movie>).ToArray();

            // Assert
            Assert.AreEqual(result.Length, 3);
            Assert.AreEqual("T1", result[0].Name);
            Assert.AreEqual("T2", result[1].Name);
            Assert.AreEqual("T3", result[2].Name);
        }
        public void CinemaControllerIndex()
        {
            this.repository         = new GenericRepository <TblBookingSeat>();
            this.repositoryCustomer = new GenericRepository <TblCustomer>();
            this.repositoryErrorLog = new GenericRepository <TblErrorLog>();

            CinemaController cinemaController = new CinemaController(repository, repositoryCustomer, repositoryErrorLog);
            ViewResult       result           = cinemaController.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }