public void Can_Edit_Movie() { // Arrange var mock = new Mock <ICinemaRepository>(); mock.Setup(m => m.Movies).Returns(new List <Movie> { new Movie { MovieId = 1, Name = "P1", ShowTime = new TimeSpan(12, 0, 0) }, new Movie { MovieId = 2, Name = "P2", ShowTime = new TimeSpan(13, 0, 0) }, new Movie { MovieId = 3, Name = "P3", ShowTime = new TimeSpan(14, 0, 0) } }.AsQueryable()); var controller = new CinemaController(mock.Object); // Act var movieResult1 = controller.EditMovie(1).Model as Movie; var movieResult2 = controller.EditMovie(2).Model as Movie; var movieResult3 = controller.EditMovie(3).Model as Movie; // Assert Assert.AreEqual(1, movieResult1.MovieId); Assert.AreEqual(2, movieResult2.MovieId); Assert.AreEqual(3, movieResult3.MovieId); }
public void Cannot_Edit_Nonexistent_Movie() { // Arrange var mock = new Mock <ICinemaRepository>(); mock.Setup(movie => movie.Movies).Returns(new List <Movie> { new Movie { MovieId = 1, Name = "P1" }, new Movie { MovieId = 2, Name = "P2" }, new Movie { MovieId = 3, Name = "P3" }, }.AsQueryable()); var controller = new CinemaController(mock.Object); // Act var movieResult = controller.EditMovie(4).Model; // Assert Assert.IsNull(movieResult); }
public void Can_Save_Valid_Movie() { // Arrange var mock = new Mock <ICinemaRepository>(); var controller = new CinemaController(mock.Object); var movie = new Movie { MovieId = 1, Name = "Приключения Шурика", ShowTime = new TimeSpan(12, 0, 0) }; // Act var result = controller.EditMovie(movie); // Assert mock.Verify(m => m.SaveMovie(movie), Times.Once()); }
public void Cannot_Save_Invalid_Movie() { // Arrange var mock = new Mock <ICinemaRepository>(); var controller = new CinemaController(mock.Object); var movie = new Movie { MovieId = 1, Name = "Приключения Шурика", ShowTime = new TimeSpan(12, 0, 0) }; controller.ModelState.AddModelError("Error", "Error in model"); // Act var result = controller.EditMovie(movie); // Assert mock.Verify(m => m.SaveMovie(movie), Times.Never()); }