public void CallDeleteMethodOnMovie_WhenMovieExists() { //Arrange movieMock.Object.IsDeleted = false; movieRepoMock .Setup(repo => repo.Delete(It.IsAny <Movie>())) .Callback <Movie>((movie) => { predifinedListOfMovies.Remove(movieMock.Object); }); unitOfWork.Setup(x => x.Movies).Returns(movieRepoMock.Object); unitOfWork.Setup(p => p.Projections.All()).Returns(new List <Projection>().AsQueryable()); unitOfWork.Setup(mg => mg.MovieGenres.All()).Returns(new List <MovieGenre>().AsQueryable()); movieRepoMock.Setup(repo => repo.AllAndDeleted()).Returns(predifinedListOfMovies.AsQueryable()); //Act var command = new MovieServices(unitOfWork.Object); command.DeleteMovie(movieMock.Object.Name); //Assert Assert.AreEqual(0, predifinedListOfMovies.Count); }
public void DeleteAllMovieGenres_WhenMovieIsDeleted() { // Arrange var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>() .UseInMemoryDatabase(databaseName: "DeleteAllMovieGenres_WhenMovieIsDeleted") .Options; var movieGenre = new MovieGenre(); movie.MovieGenres.Add(movieGenre); //Act using (var actContext = new AlphaCinemaContext(contextOptions)) { actContext.Movies.Add(movie); actContext.SaveChanges(); var unitOfWork = new UnitOfWork(actContext); var command = new MovieServices(unitOfWork); command.DeleteMovie(testMovieName); } //Assert using (var assertContext = new AlphaCinemaContext(contextOptions)) { Assert.IsTrue(movie.MovieGenres.First().IsDeleted); } }
public void ThrowEntityDoesntExistException_WhenMovieDoesNotExist() { //Arrange unitOfWork.Setup(x => x.Movies).Returns(movieRepoMock.Object); //Act and Assert var deleteMovieCommand = new MovieServices(unitOfWork.Object); Assert.ThrowsException <EntityDoesntExistException>(() => deleteMovieCommand.DeleteMovie(testMovieName)); }
public void ThrowEntityDoesntExistException_WhenMovieIsDeleted() { //Arrange movieMock.Object.IsDeleted = true; unitOfWork.Setup(x => x.Movies).Returns(movieRepoMock.Object); movieRepoMock.Setup(repo => repo.AllAndDeleted()).Returns(predifinedListOfMovies.AsQueryable()); //Act and Assert var deleteMovieCommand = new MovieServices(unitOfWork.Object); Assert.ThrowsException <EntityDoesntExistException>(() => deleteMovieCommand.DeleteMovie(testMovieName)); }
public void DeleteMovie(int id) { movieServices.DeleteMovie(id); }
public ActionResult DeleteMovie(int id) { _movieServices = new MovieServices(); _movieServices.DeleteMovie(id); return(RedirectToAction("ListMovie")); }