Example #1
0
        public void GetActorsMoviesAndPostersShouldReturnAListOfMovies()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Actors_GetActorsMoviesAndPosters_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            IActorsService actorsService = new ActorsService(db);

            db.Movies.Add(new Movie
            {
                Name      = "Test Name",
                PosterUrl = "https://imdb.com/"
            });

            db.SaveChanges();

            db.Actors.Add(new Actor
            {
                Name = "Test Actor"
            });

            db.SaveChanges();

            db.ActorsMovies.Add(new ActorMovie
            {
                ActorId = db.Actors.Last().Id,
                MovieId = db.Movies.Last().Id
            });

            db.SaveChanges();

            List <Movie> movies = actorsService.GetActorsMoviesAndPosters(db.Actors.Last().Id).ToList();

            int moviesCount = movies.Count();

            Assert.Equal(1, moviesCount);
            Assert.Equal(db.Movies.Last().Id, movies[0].Id);
            Assert.Equal("Test Name", movies[0].Name);
            Assert.Equal("https://imdb.com/", movies[0].PosterUrl);
        }