コード例 #1
0
        public void ReturnCollectionOfGenreNames_WhenTheyExist()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCollectionOfGenreNames_WhenTheyExist")
                                 .Options;

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                actContext.Cities.Add(testCity);
                actContext.MoviesGenres.Add(testMovieGenre);
                actContext.Movies.Add(testMovie);
                actContext.Genres.Add(testGenre);
                actContext.Projections.Add(testProjection);
                actContext.SaveChanges();
            }

            //Act and Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var unitOfWork  = new UnitOfWork(assertContext);
                var cityService = new CityServices(unitOfWork);
                var result      = cityService.GetGenreNames(testCityId);
                Assert.IsTrue(result.Count == 1);
                Assert.AreEqual(result.First(), testGenreName);
            }
        }
コード例 #2
0
        public void DeleteAllMovieGenres_WhenMovieIsDeleted()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "DeleteAllMovieGenres_WhenMovieIsDeleted")
                                 .Options;

            var movieGenre = new MovieGenre();

            movie.MovieGenres.Add(movieGenre);

            //Act
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                actContext.Movies.Add(movie);
                actContext.SaveChanges();
                var unitOfWork = new UnitOfWork(actContext);
                var command    = new MovieServices(unitOfWork);
                command.DeleteMovie(testMovieName);
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                Assert.IsTrue(movie.MovieGenres.First().IsDeleted);
            }
        }
コード例 #3
0
        public void AddAllPreviousMovieGenres_WhenMovieIsRestored()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "AddAllPreviousMovieGenres_WhenMovieIsRestored")
                                 .Options;

            movie.IsDeleted      = true;
            movieGenre.IsDeleted = true;
            movie.MovieGenres.Add(movieGenre);

            //Act
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                actContext.Movies.Add(movie);
                actContext.SaveChanges();
                var unitOfWork      = new UnitOfWork(actContext);
                var addMovieCommand = new MovieServices(unitOfWork);
                addMovieCommand.AddNewMovie(testMovieName, testMovieDescription,
                                            testMovieReleaseYear, testMovieDuration);
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                Assert.IsFalse(movie.MovieGenres.First().IsDeleted);
            }
        }
コード例 #4
0
        public void ChangeStateToUnchanged_WhenEntityIsAdded()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ChangeStateToAdded_WhenEntityIsModified")
                                 .Options;

            var testMovie = new Movie {
                Name = "TestMovie"
            };

            //Act
            using (var context = new AlphaCinemaContext(contextOptions))
            {
                var movieRepo = new Repository <Movie>(context);
                movieRepo.Add(testMovie);
                context.SaveChanges();
                EntityEntry entry = context.Entry(testMovie);
                //Assert
                Assert.AreEqual(EntityState.Unchanged, entry.State);
            }
        }
コード例 #5
0
ファイル: Data.cs プロジェクト: KrasimirEtov/AlphaCinema
        public void Load()
        {
            if (!IsEmpty())
            {
                return;
            }

            Clear();
            //Fill Users Table
            //var usersAsString = File.ReadAllText("../../../../AlphaCinemaData/Files/Users.json");
            //var users = JsonConvert.DeserializeObject<List<User>>(usersAsString);
            //context.Users.AddRange(users);
            //context.SaveChanges();
            //If there are no watched movies there shouldnt be users also

            //Fill Genres Table
            var genresAsString = File.ReadAllText("../../../../AlphaCinemaData/Files/Genres.json");
            var genres         = JsonConvert.DeserializeObject <List <Genre> >(genresAsString);

            context.Genres.AddRange(genres);
            context.SaveChanges();

            //Fill Movies Table
            var moviesAsString = File.ReadAllText("../../../../AlphaCinemaData/Files/Movies.json");
            var movies         = JsonConvert.DeserializeObject <List <Movie> >(moviesAsString);

            context.Movies.AddRange(movies);
            context.SaveChanges();

            //Fill MovieGenres Table
            var indexOfMovies = new List <int>()
            {
                0, 0, 1, 1, 2, 3, 3,
            };
            var indexOfGenres = new List <int>()
            {
                0, 1, 0, 1, 5, 4, 2,
            };

            for (int i = 0; i < 7; i++)
            {
                var movieGenre = new MovieGenre
                {
                    Movie = movies[indexOfMovies[i]],
                    Genre = genres[indexOfGenres[i]]
                };
                context.MoviesGenres.Add(movieGenre);
            }
            context.SaveChanges();

            //Fill OpenHours Table
            var openHoursAsString = File.ReadAllText("../../../../AlphaCinemaData/Files/OpenHours.json");
            var openHours         = JsonConvert.DeserializeObject <List <OpenHour> >(openHoursAsString);

            context.OpenHours.AddRange(openHours);
            context.SaveChanges();

            //Fill Cities Table
            var citiesAsString = File.ReadAllText("../../../../AlphaCinemaData/Files/Cities.json");
            var cities         = JsonConvert.DeserializeObject <List <City> >(citiesAsString);

            context.Cities.AddRange(cities);
            context.SaveChanges();

            //Fill Projections Table
            indexOfMovies = new List <int>()
            {
                1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3
            };
            var indexOfCities = new List <int>()
            {
                1, 2, 2, 2, 5, 2, 2, 1, 4, 5, 5, 5, 3, 3, 2, 1, 2, 3, 4, 5
            };
            var indexOfOpenHours = new List <int>()
            {
                1, 2, 3, 4, 5, 1, 5, 3, 4, 5, 2, 3, 4, 1, 2, 3, 5, 4, 3, 1
            };

            for (int i = 0; i < 20; i++)
            {
                var projection = new Projection
                {
                    MovieId    = indexOfMovies[i],
                    CityId     = indexOfCities[i],
                    OpenHourId = indexOfOpenHours[i]
                };
                context.Projections.Add(projection);
                context.SaveChanges();
            }
            context.SaveChanges();
        }