Exemple #1
0
        public void Movie_DeleteConfirmed_IndexRedirect()
        {
            // Arrange
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieId = 1, Title = "Superman 1"
                },
                new Movie()
                {
                    MovieId = 2, Title = "Superman 2"
                }
            }.AsQueryable();

            Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType);
            mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(list.First());

            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);

            MoviesController controller = new MoviesController(mockContext.Object);
            // Act
            RedirectToRouteResult result = controller.DeleteConfirmed(1) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public void MovieStore_DeleteConfirmed_ModelStateIsValid()
        {
            #region Arrange
            var movies = new List <Movie>()
            {
                new Movie {
                    MovieId = 1, Title = "Superman 1", YearRelease = 2019
                },
                new Movie {
                    MovieId = 2, Title = "Superman 2", YearRelease = 2007
                }
            }.AsQueryable();

            Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            mockSet.As <IQueryable <Movie> >().Setup(o => o.GetEnumerator())
            .Returns(movies.GetEnumerator());

            mockContext.Setup(o => o.Movies)
            .Returns(mockSet.Object);
            #endregion

            #region Act
            MoviesController controller = new MoviesController(mockContext.Object);

            RedirectToRouteResult result = controller.DeleteConfirmed(1) as RedirectToRouteResult;
            #endregion

            #region Assert
            Assert.AreEqual("Index", result.RouteValues["action"]);
            #endregion
        }
Exemple #3
0
        public void MoviesControllerDeleteConfirmed()
        {
            var moviesController = new MoviesController(null, null);

            var result = moviesController.DeleteConfirmed(1);

            Assert.IsNotNull(result);
        }
Exemple #4
0
        public void Delete_CallsService()
        {
            // Arrange

            // Act
            _controller.DeleteConfirmed(1);

            // Assert
            _mockService.Verify(s => s.DeleteMovie(1), Times.Once);
        }
Exemple #5
0
        public async Task MoviesController_Delete_Post()
        {
            /// Arrange
            var controller = new MoviesController(_db);

            /// Act
            var result = await controller.DeleteConfirmed(1);

            /// Assert
            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", viewResult.ActionName);
        }
        public void MockEverythingDeletedMovie()
        {
            var movie   = new Movie();
            var service = new Mock <IMovieRepository>();

            service.Setup(x => x.GetMovieById(1)).Returns(movie);
            _moviesController = new MoviesController(service.Object);

            var expectedType = typeof(RedirectToRouteResult);
            var result       = _moviesController.DeleteConfirmed(1);

            Assert.IsInstanceOfType(result, expectedType);
        }
        public void MovieStore_DeletePOST_Success()
        {
            // Step 1
            Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            // Step 2
            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);

            // Arrange
            MoviesController controller = new MoviesController(mockContext.Object);

            // Act
            RedirectToRouteResult result = controller.DeleteConfirmed(1) as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public void Books_DeleteConfirmed()
        {
            // Arrange
            Source source = GetTestSource();
            var    movies = GetTestMovieSet(source);
            var    db     = new Mock <IPersonalInformationManagerContext>();

            db.Setup(e => e.Movies).Returns(movies);
            db.Setup(e => e.Movies.Find(It.IsAny <int>())).Returns(GetTestMovie(source));
            db.Setup(e => e.SaveChanges()).Returns(1);
            MoviesController controller = new MoviesController(db.Object);

            // Act
            var result = (RedirectToRouteResult)controller.DeleteConfirmed(1);

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public void MovieStore_DeleteConfirmed_Success()
        {
            //Step 1
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieId = 1, Title = "Superman 1"
                },
                new Movie()
                {
                    MovieId = 2, Title = "Superman 2"
                },
            }.AsQueryable();

            //Step 2
            Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            //Step 3
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.ElementType).Returns(list.ElementType);
            mockSet.Setup(expression: m => m.Find(It.IsAny <object>())).Returns(list.First());


            //Step 4
            mockContext.Setup(expression: db => db.Movies).Returns(mockSet.Object);


            //Arrange
            MoviesController controller = new MoviesController(mockContext.Object);

            //Act
            RedirectToRouteResult result = controller.DeleteConfirmed(id: 1) as RedirectToRouteResult;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expected: "Index", actual: result.RouteValues["action"]);
            Assert.AreEqual(expected: null, actual: result.RouteValues["controller"]);
        }