public async Task UpdateRanksAsync_VerifyRanksCanBeUpdated() { int result; var itemIds = "2,1"; IList <Movie> Movies; Context.Movie.Add(CommonTestFunctions.GetSampleMovie(true, 1)); Context.Movie.Add(CommonTestFunctions.GetSampleTVShow(true, 2)); Context.SaveChanges(); using (var newcontext = new MarksMoviesContext(Options)) { MovieDBAccess db = new MovieDBAccess(newcontext); var service = new RankMoviesService(db); result = await service.UpdateRanksAsync(itemIds); } using (var newestcontext = new MarksMoviesContext(Options)) { MovieDBAccess newdb = new MovieDBAccess(newestcontext); var service = new RankMoviesService(newdb); Movies = service.GetRankedMovies(); Assert.IsNotNull(Movies); Assert.IsTrue(Movies.Count == 2); var FirstID = Movies[0].ID; var SecondID = Movies[1].ID; Assert.AreEqual(2, FirstID); Assert.AreEqual(1, SecondID); } }
public async Task SaveChangesAsync_VerifyValidTVShowIsUpdated() { var mockTMDBapi = new Mock <ITMDBapi>(); Movie newMovie = CommonTestFunctions.GetSampleTVShow(true); List <GenreType> SelectGenres = new List <GenreType>(); SelectGenres.Add(GenreType.Romance); Context.Movie.Add(newMovie); Context.SaveChanges(); using (var newcontext = new MarksMoviesContext(Options)) { MovieDBAccess db = new MovieDBAccess(newcontext); var service = new EditService(db, mockTMDBapi.Object); var result = await service.SaveMovieAsync(newMovie, SelectGenres); Assert.IsTrue(result != 0); } using (var newcontext = new MarksMoviesContext(Options)) { var movie = await newcontext.Movie.Include(g => g.Genres).SingleAsync(); Assert.IsNotNull(movie); Assert.IsNotNull(movie.Genres); Assert.AreEqual(1, movie.Genres.Count); } }
public async Task GetMovieAsync_VerifyValidIdReturnsMovie() { var mockTMDBapi = new Mock <ITMDBapi>(); int? id = 1; Movie movie; Movie newMovie = CommonTestFunctions.GetSampleMovie(true); Context.Movie.Add(newMovie); Context.SaveChanges(); using (var newcontext = new MarksMoviesContext(Options)) { MovieDBAccess db = new MovieDBAccess(newcontext); var service = new DetailsService(db, mockTMDBapi.Object); movie = await service.GetMovieAsync(id); Assert.IsNotNull(movie); Assert.AreEqual(1, await Context.Movie.CountAsync <Movie>()); Assert.AreEqual(1, movie.ID); Assert.AreEqual("Avenger's Endgame", movie.Title); Assert.AreEqual(2019, movie.Year); Assert.AreEqual(Rating.PG13, movie.Rating); Assert.AreEqual(DiscType.UHD_Bluray, movie.MediaType); Assert.AreEqual(299534, movie.TMDB_ID); Assert.IsTrue(movie.Genres.Count == 3); } }
public void Init() { Options = new DbContextOptionsBuilder <MarksMoviesContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; Context = new MarksMoviesContext(Options); DbAccess = new MovieDBAccess(Context); }
public void OnGet_VerifyMovieListOnSuccess() { IList <Movie> Movies; Context.Movie.Add(CommonTestFunctions.GetSampleMovie(true)); Context.SaveChanges(); using (var newcontext = new MarksMoviesContext(Options)) { MovieDBAccess db = new MovieDBAccess(newcontext); var service = new RankMoviesService(db); Movies = service.GetRankedMovies(); Assert.IsNotNull(Movies); Assert.IsTrue(Movies.Count == 1); } }
public async Task OnGetAsync_VerifyNoQueryStringReturnsMovieList() { IList <Movie> Movies; Context.Movie.Add(CommonTestFunctions.GetSampleMovie(true)); Context.SaveChanges(); using (var context = new MarksMoviesContext(Options)) { var DbAccess = new MovieDBAccess(context); var service = new MovieIndexService(DbAccess); Movies = await service.OnGetAsync("", 0); Assert.IsNotNull(Movies); Assert.IsTrue(Movies.Count() > 0); } }
public async Task DeleteMovieAsync_VerifyValidIdReturnsDELETE_OK() { int? id = 1; Movie newMovie = CommonTestFunctions.GetSampleMovie(true); Context.Movie.Add(newMovie); Context.SaveChanges(); using (var newcontext = new MarksMoviesContext(Options)) { MovieDBAccess db = new MovieDBAccess(newcontext); var service = new DeleteService(db); var result = await service.DeleteMovieAsync(id); Assert.AreEqual(DeleteService.DELETE_SUCCESS, result); Assert.AreEqual(0, await Context.Movie.CountAsync <Movie>()); } }
public async Task OnGetAsync_VerifyGenreSelectionReturnsMovieList() { IList <Movie> Movies; string expectedTitle = "House"; GenreType selection = GenreType.Drama; Context.Movie.Add(CommonTestFunctions.GetSampleMovie(true)); Context.Movie.Add(CommonTestFunctions.GetSampleTVShow(true, 2)); Context.SaveChanges(); using (var context = new MarksMoviesContext(Options)) { var DbAccess = new MovieDBAccess(context); var service = new MovieIndexService(DbAccess); Movies = await service.OnGetAsync("", selection); Assert.IsNotNull(Movies); Assert.IsTrue(Movies.Count() == 1); Assert.AreEqual(expectedTitle, Movies[0].Title); } }
public async Task OnGetAsync_VerifyQueryStringReturnsMovieList() { IList <Movie> Movies; string expectedTitle = "Avenger's Endgame"; string SearchString = "avenger"; Context.Movie.Add(CommonTestFunctions.GetSampleMovie(true)); Context.Movie.Add(CommonTestFunctions.GetSampleTVShow(true, 2)); Context.SaveChanges(); using (var context = new MarksMoviesContext(Options)) { var DbAccess = new MovieDBAccess(context); var service = new MovieIndexService(DbAccess); Movies = await service.OnGetAsync(SearchString, 0); Assert.IsNotNull(Movies); Assert.IsTrue(Movies.Count() == 1); Assert.AreEqual(expectedTitle, Movies[0].Title); } }