public void GetMovieById_Should_return_Valid_MovieObject_For_Valid_SearcParameters() { List <Movie> fakeMovies = new List <Movie>() { new Movie() { MovieId = 1, Title = "First Movie", Rating = 2 }, new Movie() { MovieId = 2, Title = "Second Movie", Rating = 1 }, new Movie() { MovieId = 3, Title = "Third Movie", Rating = 4 } }; bool called = false; Mock <IMovieRepository> mockRepository = new Mock <IMovieRepository>(); mockRepository.Setup(m => m.GetMovieById(It.IsAny <int>())).Callback(() => called = true); MBLayer.MovieBusinessLayer movieBLayer = new MBLayer.MovieBusinessLayer(mockRepository.Object); Movie actual = movieBLayer.GetMovieById(3); Assert.IsTrue(called); }
public void GetMovieById_Should_Return_NUll_For_Movie_For_Invalid_Input() { List <Movie> fakeMovies = new List <Movie>() { new Movie() { MovieId = 1, Title = "First Movie", Rating = 2 }, new Movie() { MovieId = 2, Title = "Second Movie", Rating = 1 }, new Movie() { MovieId = 3, Title = "Third Movie", Rating = 4 } }; Mock <IMovieRepository> mockRepository = new Mock <IMovieRepository>(); mockRepository.Setup(m => m.GetMovies()).Returns(fakeMovies); MBLayer.MovieBusinessLayer movieBLayer = new MBLayer.MovieBusinessLayer(mockRepository.Object); Movie actual = movieBLayer.GetMovieById(4); Assert.IsNull(actual); }