Пример #1
0
        public async Task ReturnCityObject_WithTheSameName_As_Passed()
        {
            DbContextOptions <AlphaCinemaContext> contextOptions =
                new DbContextOptionsBuilder <AlphaCinemaContext>()
                .UseInMemoryDatabase(databaseName: "ReturnCityObject_WithTheSameName_As_Passed")
                .Options;

            // Arrange
            var cityName = "TestCityName";

            var city = new City()
            {
                Name = cityName
            };

            // Act && Assert
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.Cities.AddAsync(city);

                await actContext.SaveChangesAsync();
            }

            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var cityServices = new CityService(assertContext);
                city = await cityServices.GetCity(cityName);

                Assert.AreEqual(cityName, city.Name);
            }
        }
Пример #2
0
        public async Task CorrectlyReturnAllUsers()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "CorrectlyReturnAllUsers")
                             .Options;

            user = new User()
            {
                FirstName = "Krasimir",
                LastName  = "Etov",
                Age       = 21,
            };

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

                await actContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var userService = new UserService(serviceProviderMock.Object, assertContext);
                var users       = await userService.GetAllUsers();

                Assert.IsTrue(users.Count == 1);
            }
        }
        public async Task DeleteCityObject_When_CityExists()
        {
            DbContextOptions <AlphaCinemaContext> contextOptions =
                new DbContextOptionsBuilder <AlphaCinemaContext>()
                .UseInMemoryDatabase(databaseName: "DeleteCityObject_When_CityExists")
                .Options;

            // Arrange
            var cityName = "TestCityName";

            var city = new City()
            {
                Name = cityName
            };


            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.Cities.AddAsync(city);

                await actContext.SaveChangesAsync();
            }

            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var cityServices = new CityService(assertContext);
                await cityServices.DeleteCity(cityName);

                city = await assertContext.Cities.FirstAsync(c => c.Name == cityName);

                Assert.IsTrue(city.IsDeleted == true);
            }
        }
Пример #4
0
        public async Task ReturnWatchedMovieWhenParamsAreInDatabase()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "ReturnWatchedMovieWhenParamsAreInDatabase")
                             .Options;

            var userId       = "userId";
            var projectionId = 5;

            watchedMovie = new WatchedMovie()
            {
                UserId       = userId,
                ProjectionId = projectionId
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.WatchedMovies.AddAsync(watchedMovie);

                await actContext.SaveChangesAsync();
            }

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var watchedMoviesService = new WatchedMoviesService(assertContext);
                var result = await watchedMoviesService.GetWatchedMovie(userId, projectionId);

                Assert.IsNotNull(result);
                Assert.AreEqual(result.ProjectionId, projectionId);
                Assert.AreEqual(result.UserId, userId);
            }
        }
Пример #5
0
        public async Task Throw_InvalidClientInputException_When_ParametersAreNotValid()
        {
            DbContextOptions <AlphaCinemaContext> contextOptions =
                new DbContextOptionsBuilder <AlphaCinemaContext>()
                .UseInMemoryDatabase(databaseName: "Throw_InvalidClientInputException_When_ParametersAreNotValid")
                .Options;

            // Arrange
            var cityName = "Te";

            var city = new City()
            {
                Name = cityName
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.Cities.AddAsync(city);

                await actContext.SaveChangesAsync();
            }

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var cityServices = new CityService(assertContext);
                await Assert.ThrowsExceptionAsync <InvalidClientInputException>(() =>
                                                                                cityServices.AddCity(cityName));
            }
        }
Пример #6
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
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        public async Task ThrowEntityDoesntExistExceptionWhenUserIsDeleted()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "ThrowEntityDoesntExistExceptionWhenUserIsDeleted")
                             .Options;

            user = new User()
            {
                Id        = "my id",
                FirstName = "Krasimir",
                LastName  = "Etov",
                Age       = 21,
                IsDeleted = true
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.Users.AddAsync(user);

                await actContext.SaveChangesAsync();
            }
            //Act and Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var userService = new UserService(serviceProviderMock.Object, assertContext);
                await Assert.ThrowsExceptionAsync <EntityDoesntExistException>(() => userService.Modify(user.Id));
            }
        }
        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);
            }
        }
        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);
            }
        }
Пример #11
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);
            }
        }
Пример #12
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);
            }
        }
Пример #13
0
        public async Task AddNewMovie_WhenParametersAreCorrect()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "AddNewMovie_WhenParametersAreCorrect")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

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

                await actContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                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);
            }
        }
Пример #14
0
        public async Task AddNewCity_WhenParametersAreCorrect(string cityName)
        {
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "AddNewCity_WhenParametersAreCorrect")
                                 .Options;

            var city = new City()
            {
                Name = cityName
            };

            using (var context = new AlphaCinemaContext(contextOptions))
            {
                await context.Cities.AddAsync(city);

                await context.SaveChangesAsync();

                var cityService = new CityService(context);

                city = await cityService.AddCity(cityName);
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                Assert.IsInstanceOfType(city, typeof(City));
                Assert.IsNotNull(city);
            }
        }
Пример #15
0
        public async Task SuccessfullyModifyDateWhenUserIsValid()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "SuccessfullyModifyDateWhenUserIsValid")
                             .Options;

            string userId = "djoni";

            user = new User()
            {
                Id        = userId,
                FirstName = "Krasimir",
                LastName  = "Etov",
                Age       = 21
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.Users.AddAsync(user);

                await actContext.SaveChangesAsync();
            }
            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var userService = new UserService(serviceProviderMock.Object, assertContext);
                await userService.Modify(userId);

                // please don't kill me
                user = await userService.GetUser(userId);

                Assert.AreEqual(DateTime.Now.Year, user.ModifiedOn.Value.Year);
            }
        }
Пример #16
0
        public async Task ReturnNullWhenUserIsNotFound()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "ReturnNullWhenUserIsNotFound")
                             .Options;

            var userId       = "userId";
            var projectionId = 5;

            // Assert && Act
            watchedMovie = new WatchedMovie()
            {
                UserId       = userId,
                ProjectionId = projectionId
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.WatchedMovies.AddAsync(watchedMovie);

                await actContext.SaveChangesAsync();
            }
            var serviceProviderMock = new Mock <IServiceProvider>();

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var watchedMoviesService = new WatchedMoviesService(assertContext);
                var result = await watchedMoviesService.GetWatchedMovie("no user id", projectionId);

                Assert.IsNull(result);
            }
        }
Пример #17
0
        public async Task ThrowEntityAlreadyExistsExceptionWhenParamsAreValid()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "ThrowEntityAlreadyExistsExceptionWhenParamsAreValid")
                             .Options;

            var userId       = "userId";
            var projectionId = 5;

            watchedMovie = new WatchedMovie()
            {
                UserId       = userId,
                ProjectionId = projectionId
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.WatchedMovies.AddAsync(watchedMovie);

                await actContext.SaveChangesAsync();
            }

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var watchedMoviesService = new WatchedMoviesService(assertContext);
                await Assert.ThrowsExceptionAsync <EntityAlreadyExistsException>(() =>
                                                                                 watchedMoviesService.AddNewWatchedMovie(userId, projectionId));
            }
        }
Пример #18
0
        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);
            }
        }
Пример #19
0
        public async Task ReturnUserIfUserIdIsFound()
        {
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "ReturnUserIfUserIdIsFound")
                             .Options;
            // Arrange
            string userId = "myId";

            user = new User()
            {
                Id        = userId,
                FirstName = "Krasimir",
                LastName  = "Etov",
                Age       = 21,
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.Users.AddAsync(user);

                await actContext.SaveChangesAsync();
            }

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var userService = new UserService(serviceProviderMock.Object, assertContext);

                var result = await userService.GetUser(userId);

                Assert.IsNotNull(result);
                Assert.AreEqual(result.Id, userId);
            }
        }
Пример #20
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
            }
        }
Пример #21
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));
            }
        }
Пример #22
0
        public async Task ReturnWatchedMoviesWhenUserIsValid()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "ReturnWatchedMoviesWhenUserIsValid")
                             .Options;

            var userId = "Mitio";

            var watchedMovies = new List <WatchedMovie>()
            {
                new WatchedMovie()
                {
                    UserId     = userId,
                    Projection = new Projection()
                    {
                        Movie = new Movie()
                        {
                            Name = "movie Name"
                        },
                        City = new City()
                        {
                            Name = "city name"
                        },
                        OpenHour = new OpenHour {
                            Hours = 12
                        }
                    }
                },
                new WatchedMovie()
                {
                    UserId     = userId,
                    Projection = new Projection()
                    {
                        Movie = new Movie()
                        {
                            Name = "movie Name"
                        },
                        City = new City()
                        {
                            Name = "city name"
                        },
                        OpenHour = new OpenHour {
                            Hours = 12
                        }
                    }
                },
                new WatchedMovie()
                {
                    UserId     = userId,
                    Projection = new Projection()
                    {
                        Movie = new Movie()
                        {
                            Name = "movie Name"
                        },
                        City = new City()
                        {
                            Name = "city name"
                        },
                        OpenHour = new OpenHour {
                            Hours = 12
                        }
                    }
                },
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                foreach (var watchedMovie in watchedMovies)
                {
                    await actContext.WatchedMovies.AddAsync(watchedMovie);
                }
                await actContext.SaveChangesAsync();
            }
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var watchedMoviesService = new WatchedMoviesService(assertContext);
                var result = await watchedMoviesService.GetWatchedMoviesByUserId(userId);

                Assert.AreEqual(watchedMovies.Count, result.Count);
            }
        }