public async Task DeleteMovie_WhenNameIsValid()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "DeleteMovie_WhenNameIsValid")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;
            var listOfMovies = new List <Movie>()
            {
                testMovieOne, testMovieTwo
            };

            //Act
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.AddRangeAsync(listOfMovies);

                await actContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var command = new MovieService(assertContext);
                await command.DeleteMovie(testMovieOneName);

                Assert.IsTrue(assertContext.Movies.First().IsDeleted);
            }
        }
        public async Task ReturnCollectionOfMovies_WhenCalled()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCollectionOfMovies_WhenCalled")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;
            var listOfMovies = new List <Movie>()
            {
                testMovieOne, testMovieTwo, testMovieThree
            };

            //Act
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.AddRangeAsync(listOfMovies);

                await actContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var command = new MovieService(assertContext);
                var result  = await command.GetMovies();

                Assert.IsTrue(result.Count() == 3);
                Assert.AreEqual(testMovieOneName, result.First().Name);
                Assert.AreEqual(testMovieTwoName, result.Skip(1).First().Name);
                Assert.AreEqual(testMovieThreeName, result.Skip(2).First().Name);
            }
        }
        public async Task ReturnMovie_WhenNameIsValid()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnMovie_WhenNameIsValid")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;
            var listOfMovies = new List <Movie>()
            {
                testMovieOne, testMovieTwo
            };

            //Act
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.AddRangeAsync(listOfMovies);

                await actContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var command = new MovieService(assertContext);
                var result  = await command.GetMovie(testMovieOneName);

                Assert.AreEqual(testMovieOneName, result.Name);
                Assert.AreEqual(movieId, result.Id);
            }
        }
Beispiel #4
0
        public async Task ReturnCollectionOfProjections_WhenCountIsValid()
        {
            //Arrange
            // Create a new options instance telling the context to use an InMemory database and the new service provider.
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCollectionOfProjections_WhenCountIsValid")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var listOfProjections = new List <Projection>()
            {
                testProjectionOne, testProjectionTwo, testProjectionThree
            };
            var listOfMovies = new List <Movie>()
            {
                testMovieOne, testMovieTwo, testMovieThree
            };

            //Act and Assert
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.AddRangeAsync(listOfProjections);

                await actContext.AddRangeAsync(listOfMovies);

                await actContext.AddAsync(testOpenHour);

                await actContext.AddAsync(testCity);

                await actContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var command = new ProjectionService(assertContext);
                var result  = await command.GetTopProjections(projectionCount);

                Assert.AreEqual(testProjectionOne.Id, result.First().Id);
                //We are returning the FirstProjection and we want the top 1
            }
        }