public DummyMockedAllMoviesRepository() { using (var mock = AutoMock.GetStrict()) { mock.Mock <IAllMoviesRepository>().Setup(iall_m_repo => iall_m_repo.GetMovie(It.IsAny <int>())) .Returns((int id) => new Tuple <Movie, string>(movies.Where(m => m.id == id).Single(), "Drama")); mock.Mock <IAllMoviesRepository>().Setup(iall_m_repo => iall_m_repo.EditMovie(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <Nullable <DateTime> >(), It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <int>())).Callback((int id, string title, int genre, int pg, Nullable <DateTime> date, string summary, byte[] picture, int dur) => { try { movies[1].title = title; movies[1].genre = genre; movies[1].pg = pg; movies[1].year = date; movies[1].summary = summary; movies[1].picture = picture; movies[1].duration = dur; } catch (ImpossibleDataBaseRecordUpdateException ex) { Logger.WriteToLogFile(ex.ToString()); } catch (NotFoundSuchItemException ex) { Logger.WriteToLogFile(ex.ToString()); } catch (Exception ex) { Logger.WriteToLogFile(ex.ToString()); } }); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.DeleteMovie(It.IsAny <int>())).Callback((int id) => { try { movies.Remove(movies.Where(m => m.id == id).Single()); } catch (NotFoundSuchItemException ex) { Logger.WriteToLogFile(ex.ToString()); } }); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.SortMoviesByTitle()).Returns(GetSortedByAToZMovies()); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.SortByDate()).Returns(GetSortedByOldestMovies()); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.FilterMovies(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())) .Returns((int g, int d, int pg) => GetFilteredByGenreDurationAndPGMovies(g, d, pg)); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.FilterMoviesByGenresAndDuration(It.IsAny <int>(), It.IsAny <int>())) .Returns((int g, int d) => GetFilteredByGenreAndDurationMovies(g, d)); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.FilterMoviesByGenresAndPG(It.IsAny <int>(), It.IsAny <int>())) .Returns((int g, int pg) => GetFilteredByGenreAndPGMovies(g, pg)); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.FilterMoviesByDurationAndPG(It.IsAny <int>(), It.IsAny <int>())) .Returns((int d, int pg) => GetFilteredByDurationAndPGMovies(d, pg)); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.FilterMoviesByGenres(It.IsAny <int>())) .Returns((int g) => GetFilteredByGenreMovies(g)); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.FilterMoviesByDuration(It.IsAny <int>())) .Returns((int d) => GetFilteredByGenreMovies(d)); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.FilterMoviesByPG(It.IsAny <int>())) .Returns((int pg) => GetFilteredByGenreMovies(pg)); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.GetMoviesByTitles(It.IsAny <List <string> >())) .Returns((List <string> titles) => GetMoviesByTitles(titles)); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.GetMovieTitle(It.IsAny <int>())) .Returns((int id) => movies.Where(m => m.id == id).Single().title); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.GetMovies()) .Returns(GetAllMovies()); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.GetMoviesTitles()) .Returns(GetMoviesTitles()); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.GetUserInfo(It.IsAny <string>(), It.IsAny <string>())) .Returns((string unm, string pass) => new Tuple <int, string>(users.Where(u => u.userName == unm && u.password == pass).Single().id, usersInfo.Where(u => u.id == users.Where(us => us.userName == unm && us.password == pass).Single().id).Single().position)); mock.Mock <IAllMoviesRepository>().Setup(_allMoviesRepo => _allMoviesRepo.GetMovieGenre(It.IsAny <string>())) .Returns((string gen) => movies.Where(m => m.genre == genres.Where(g => g.name == gen).Single().id).Single().genre); _allMoviesRepo = mock.Create <IAllMoviesRepository>(); } }
/// <summary> /// The <c>FilterMoviesByGenres()</c> method filters /// the movies from the database by genre. /// </summary> /// <param name="g">This is the genre - one of the filtering params.</param> /// <returns>This method returns a dictionary from the filtered movies' ids (int) /// and the filtered movies' wrappers (byte[]) from the service class.</returns> public Dictionary <int, byte[]> FilterMoviesByGenres(int g) { return(movie_repo.FilterMoviesByGenres(g)); }