Example #1
0
        public async Task ReturnListOfNotBookedProjections_WhenUserIdIsNull()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnListOfNotBookedProjections_WhenUserIdIsNull")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            //Act
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.AddAsync(projection);

                await actContext.AddAsync(validReservation);

                await actContext.AddAsync(movie);

                await actContext.AddAsync(openHour);

                await actContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var command     = new ProjectionService(assertContext);
                var projections = await command.GetByTownId(cityId, "");

                Assert.AreEqual(false, projections.First().IsBooked);
                Assert.AreEqual(projectionSeats - 1, projections.First().Seats);
                //Someone already booked for this Projection
            }
        }
Example #2
0
        public async Task UpdateMovieParameters_WhenPassedParametersAreValid()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "UpdateMovieParameters_WhenPassedParametersAreValid")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            //Act
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.AddAsync(movie);

                await actContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var command = new MovieService(assertContext);
                var movie   = await command.UpdateMovie(movieId, newMovieName, newMovieDescription, newRealeaseYear, newMovieDuration, "");

                Assert.AreEqual(newMovieName, movie.Name);
                Assert.AreEqual(newMovieDescription, movie.Description);
                Assert.AreEqual(int.Parse(newRealeaseYear), movie.ReleaseYear);
                Assert.AreEqual(int.Parse(newMovieDuration), movie.Duration);
            }
        }
        public async Task ChangeIsDeletedToFalse_WhenExistAndParametersAreValid()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ChangeIsDeletedToFalse_WhenExistAndParametersAreValid")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            //Act
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.AddAsync(deletedReservation);

                await actContext.SaveChangesAsync();

                var command = new ProjectionService(actContext);
                await command.AddReservation(testUserId, testProjectionId);
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                Assert.IsTrue(assertContext.WatchedMovies.Count() == 1);
                Assert.IsTrue(assertContext.WatchedMovies.First().IsDeleted == false);
            }
        }
Example #4
0
        public async Task ChangeIsDeletedToFalse_WhenMovieAlreadyExist()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ChangeIsDeletedToFalse_WhenMovieAlreadyExist")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            using (var arrangeContext = new AlphaCinemaContext(contextOptions))
            {
                movie.IsDeleted = true;
                await arrangeContext.AddAsync(movie);

                await arrangeContext.SaveChangesAsync();
            }

            //Act and Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var command = new MovieService(assertContext);
                await command.AddMovie(movieName, movieDescription, releaseYear, movieDuration);

                Assert.IsTrue(!assertContext.Movies.First().IsDeleted);
                Assert.AreEqual(1, await assertContext.Movies.CountAsync());
                Assert.AreEqual(movieName, assertContext.Movies.First().Name);
                Assert.AreEqual(movieDescription, assertContext.Movies.First().Description);
                Assert.AreEqual(int.Parse(movieDuration), assertContext.Movies.First().Duration);
                Assert.AreEqual(int.Parse(releaseYear), assertContext.Movies.First().ReleaseYear);
            }
        }
Example #5
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
            }
        }
Example #6
0
        public async Task ThrowException_WhenMovieAlreadyExist()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ThrowException_WhenMovieAlreadyExist")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            using (var arrangeContext = new AlphaCinemaContext(contextOptions))
            {
                await arrangeContext.AddAsync(movie);

                await arrangeContext.SaveChangesAsync();
            }

            //Act and Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var command = new MovieService(assertContext);
                await Assert.ThrowsExceptionAsync <Exception>(async() => await command.AddMovie(movieName, movieDescription, releaseYear, movieDuration));
            }
        }