Esempio n. 1
0
        public void GetActorsNamesShouldReturnACollectionOfActors()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Movies_GetActorsNames_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            IMoviesService moviesService = new MoviesService(db);

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

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

            db.SaveChanges();

            db.ActorsMovies.Add(new ActorMovie
            {
                ActorId = db.Actors.ToList()[0].Id,
                MovieId = 1
            });

            db.ActorsMovies.Add(new ActorMovie
            {
                ActorId = db.Actors.ToList()[1].Id,
                MovieId = 1
            });

            db.SaveChanges();

            List <Actor> actors = moviesService.GetActorsNames(1).ToList();

            int actorsCount = actors.Count();

            Assert.Equal(2, actorsCount);
        }