Beispiel #1
0
        public async Task UpdateMovie_ShoulAddSecondMovieSimilar_WhenOtherExistsPreviously()
        {
            var movieUnderTest          = TestMovieSeededWithRelatedInfo;
            var secondRelationUnderTest = new MovieSimilar
            {
                Movie     = movieUnderTest,
                MovieId   = movieUnderTest.Id,
                Similar   = TestMovieNotSeeded,
                SimilarId = TestMovieNotSeeded.Id
            };

            using var context = DbContextScopeFactory.Create();
            movieUnderTest.Similars.Add(secondRelationUnderTest);
            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest));

            context.SaveChanges();

            var existingFirstRelation  = MoviesContext.MovieSimilars.Find(movieUnderTest.Id, TestMovieSeededWithoutRelatedInfo.Id);
            var existingSecondRelation = MoviesContext.MovieSimilars.Find(movieUnderTest.Id, TestMovieNotSeeded.Id);
            var existingSecondSimilar  = MoviesContext.Movies.Find(TestMovieNotSeeded.Id);
            var existingMovie          = MoviesContext.Movies.Find(movieUnderTest.Id);

            existingFirstRelation.Should().BeEquivalentTo(TestMovieSimilarSeeded);
            existingSecondRelation.Should().BeEquivalentTo(secondRelationUnderTest);
            existingSecondSimilar.Should().Be(TestMovieNotSeeded);
            existingMovie.Should().Be(movieUnderTest);
        }
Beispiel #2
0
        private void CreateTestManyToManyData()
        {
            TestMovieDirectorSeeded = new MovieDirector
            {
                Person   = TestDirectorSeeded,
                PersonId = TestDirectorSeeded.Id,
                Movie    = TestMovieSeededWithRelatedInfo,
                MovieId  = TestMovieSeededWithRelatedInfo.Id
            };
            TestMovieActorSeeded = new MovieActor
            {
                Person      = TestActorSeeded,
                PersonId    = TestActorSeeded.Id,
                Movie       = TestMovieSeededWithRelatedInfo,
                MovieId     = TestMovieSeededWithRelatedInfo.Id,
                AsCharacter = "Test"
            };
            TestMovieWriterSeeded = new MovieWriter
            {
                Person   = TestWriterSeeded,
                PersonId = TestWriterSeeded.Id,
                Movie    = TestMovieSeededWithRelatedInfo,
                MovieId  = TestMovieSeededWithRelatedInfo.Id,
            };
            TestMovieCompanySeeded = new MovieCompany
            {
                Company   = TestCompanySeeded,
                CompanyId = TestCompanySeeded.Id,
                Movie     = TestMovieSeededWithRelatedInfo,
                MovieId   = TestMovieSeededWithRelatedInfo.Id,
            };
            TestMovieImageSeeded = fixture.Build <MovieImageData>()
                                   .With(x => x.Movie, TestMovieSeededWithRelatedInfo)
                                   .With(x => x.MovieId, TestMovieSeededWithRelatedInfo.Id)
                                   .Create();
            TestMovieImageNotSeeded = fixture.Build <MovieImageData>()
                                      .With(x => x.Movie, TestMovieNotSeeded)
                                      .With(x => x.MovieId, TestMovieNotSeeded.Id)
                                      .Create();

            TestMovieSimilarSeeded = new MovieSimilar
            {
                Similar   = TestMovieSeededWithoutRelatedInfo,
                SimilarId = TestMovieSeededWithoutRelatedInfo.Id,
                Movie     = TestMovieSeededWithRelatedInfo,
                MovieId   = TestMovieSeededWithRelatedInfo.Id,
            };

            TestMovieSeededWithRelatedInfo.DirectorList.Add(TestMovieDirectorSeeded);
            TestMovieSeededWithRelatedInfo.ActorList.Add(TestMovieActorSeeded);
            TestMovieSeededWithRelatedInfo.WriterList.Add(TestMovieWriterSeeded);
            TestMovieSeededWithRelatedInfo.CompanyList.Add(TestMovieCompanySeeded);
            TestMovieSeededWithRelatedInfo.Images.Add(TestMovieImageSeeded);
            TestMovieSeededWithRelatedInfo.Similars.Add(TestMovieSimilarSeeded);
        }
Beispiel #3
0
        public async Task UpdateMovie_ShouldAddMovieSimilar_WhenMovieExists()
        {
            using var context = DbContextScopeFactory.Create();
            var movieUnderTest    = TestMovieSeededWithoutRelatedInfo;
            var relationUnderTest = new MovieSimilar
            {
                Movie     = movieUnderTest,
                MovieId   = movieUnderTest.Id,
                Similar   = TestMovieSeededWithRelatedInfo,
                SimilarId = TestMovieSeededWithRelatedInfo.Id
            };

            movieUnderTest.Similars.Add(relationUnderTest);

            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest));

            context.SaveChanges();
            var existingMovie    = MoviesContext.Movies.Find(movieUnderTest.Id);
            var existingRelation = MoviesContext.MovieSimilars.Find(movieUnderTest.Id, TestMovieSeededWithRelatedInfo.Id);

            existingMovie.Should().Be(movieUnderTest);
            existingRelation.Should().BeEquivalentTo(relationUnderTest);
        }
Beispiel #4
0
        private void CreateFillerData()
        {
            for (int i = 0; i < 3; i++)
            {
                var movie = CreateMovieWithoutRelatedInfo();
                InitialMoviesInDb.Add(movie);

                var similar = new MovieSimilar
                {
                    Movie     = TestMovieSeededWithRelatedInfo,
                    MovieId   = TestMovieSeededWithRelatedInfo.Id,
                    Similar   = movie,
                    SimilarId = movie.Id
                };

                TestMovieSeededWithRelatedInfo.Similars.Add(similar);
            }

            for (int i = 0; i < 3; i++)
            {
                var person = CreatePersonWithoutRelatedInfo();
                PeopleList.Add(person);

                TestMovieSeededWithRelatedInfo.ActorList.Add(new MovieActor
                {
                    Movie    = TestMovieSeededWithRelatedInfo,
                    MovieId  = TestMovieSeededWithRelatedInfo.Id,
                    Person   = person,
                    PersonId = person.Id
                });
            }

            for (int i = 0; i < 3; i++)
            {
                var person = CreatePersonWithoutRelatedInfo();
                PeopleList.Add(person);

                TestMovieSeededWithRelatedInfo.DirectorList.Add(new MovieDirector
                {
                    Movie    = TestMovieSeededWithRelatedInfo,
                    MovieId  = TestMovieSeededWithRelatedInfo.Id,
                    Person   = person,
                    PersonId = person.Id
                });
            }

            for (int i = 0; i < 3; i++)
            {
                var person = CreatePersonWithoutRelatedInfo();
                PeopleList.Add(person);

                TestMovieSeededWithRelatedInfo.WriterList.Add(new MovieWriter
                {
                    Movie    = TestMovieSeededWithRelatedInfo,
                    MovieId  = TestMovieSeededWithRelatedInfo.Id,
                    Person   = person,
                    PersonId = person.Id
                });
            }

            for (int i = 0; i < 3; i++)
            {
                var company = CreateCompanyWithoutRelatedInfo();
                CompanyList.Add(company);

                TestMovieSeededWithRelatedInfo.CompanyList.Add(new MovieCompany
                {
                    Movie     = TestMovieSeededWithRelatedInfo,
                    MovieId   = TestMovieSeededWithRelatedInfo.Id,
                    Company   = company,
                    CompanyId = company.Id
                });
            }

            for (int i = 0; i < 3; i++)
            {
                var rating = fixture.Build <Rating>()
                             .With(x => x.Movie, TestMovieSeededWithRelatedInfo)
                             .With(x => x.MovieId, TestMovieSeededWithRelatedInfo.Id)
                             .Create();

                TestMovieSeededWithRelatedInfo.Ratings.Add(rating);
            }
        }
Beispiel #5
0
        private void UpdateRelatedInfo(UpdateMovieDetailsDto movie)
        {
            foreach (var image in movie.Images)
            {
                var existingLink = DbContext.MovieImageDatas.Find(new object[] { image.MovieId, image.Id });
                if (existingLink != null)
                {
                    continue;
                }

                var existingMovie = DbContext.Movies.Find(new object[] { image.MovieId });
                if (existingMovie == null)
                {
                    throw new InvalidOperationException("Se esperaba encontrar pelicula para agregar personas");
                }

                existingMovie.Images.Add(new MovieImageData
                {
                    Id      = image.Id,
                    Movie   = existingMovie,
                    MovieId = existingMovie.Id,
                    Image   = image.Image,
                    Title   = image.Title
                });
            }

            //TODO: refactor this
            foreach (var moviePerson in movie.ActorList)
            {
                var existingLink = DbContext.MovieActors.Find(new object[] { moviePerson.MovieId, moviePerson.PersonId });
                if (existingLink != null)
                {
                    continue;
                }

                var existingPerson = DbContext.People.Find(new object[] { moviePerson.PersonId });
                if (existingPerson == null)
                {
                    DbContext.People.Add(moviePerson.Person);
                    existingPerson = DbContext.People.Find(new object[] { moviePerson.PersonId });
                }

                var existingMovie = DbContext.Movies.Find(new object[] { moviePerson.MovieId });
                if (existingMovie == null)
                {
                    throw new InvalidOperationException("Se esperaba encontrar pelicula para agregar personas");
                }

                var newLink = new MovieActor
                {
                    Movie       = existingMovie,
                    MovieId     = existingMovie.Id,
                    Person      = existingPerson,
                    PersonId    = existingPerson.Id,
                    AsCharacter = moviePerson.AsCharacter,
                    IsStar      = moviePerson.IsStar
                };

                DbContext.MovieActors.Add(newLink);
            }

            foreach (var moviePerson in movie.WriterList)
            {
                var existingLink = DbContext.MovieWriters.Find(new object[] { moviePerson.MovieId, moviePerson.PersonId });
                if (existingLink != null)
                {
                    continue;
                }

                var existingPerson = DbContext.People.Find(new object[] { moviePerson.PersonId });
                if (existingPerson == null)
                {
                    DbContext.People.Add(moviePerson.Person);
                    existingPerson = DbContext.People.Find(new object[] { moviePerson.PersonId });
                }

                var existingMovie = DbContext.Movies.Find(new object[] { moviePerson.MovieId });
                if (existingMovie == null)
                {
                    throw new InvalidOperationException("Se esperaba encontrar pelicula para agregar personas");
                }

                var newLink = new MovieWriter
                {
                    Movie    = existingMovie,
                    MovieId  = existingMovie.Id,
                    Person   = existingPerson,
                    PersonId = existingPerson.Id,
                };

                DbContext.MovieWriters.Add(newLink);
            }

            foreach (var moviePerson in movie.DirectorList)
            {
                var existingLink = DbContext.MovieDirectors.Find(new object[] { moviePerson.MovieId, moviePerson.PersonId });
                if (existingLink != null)
                {
                    continue;
                }

                var existingPerson = DbContext.People.Find(new object[] { moviePerson.PersonId });
                if (existingPerson == null)
                {
                    DbContext.People.Add(moviePerson.Person);
                    existingPerson = DbContext.People.Find(new object[] { moviePerson.PersonId });
                }

                var existingMovie = DbContext.Movies.Find(new object[] { moviePerson.MovieId });
                if (existingMovie == null)
                {
                    throw new InvalidOperationException("Se esperaba encontrar pelicula para agregar personas");
                }

                var newLink = new MovieDirector
                {
                    Movie    = existingMovie,
                    MovieId  = existingMovie.Id,
                    Person   = existingPerson,
                    PersonId = existingPerson.Id,
                };

                DbContext.MovieDirectors.Add(newLink);
            }

            foreach (var movieSimilar in movie.Similars)
            {
                var existingLink = DbContext.MovieSimilars.Find(new object[] { movieSimilar.MovieId, movieSimilar.SimilarId });
                if (existingLink != null)
                {
                    continue;
                }

                var existingSimilar = DbContext.Movies.Find(new object[] { movieSimilar.SimilarId });
                if (existingSimilar == null)
                {
                    DbContext.Movies.Add(movieSimilar.Similar);
                    existingSimilar = DbContext.Movies.Find(new object[] { movieSimilar.SimilarId });
                }

                var existingMovie = DbContext.Movies.Find(new object[] { movieSimilar.MovieId });
                if (existingMovie == null)
                {
                    throw new InvalidOperationException("Se esperaba encontrar pelicula para agregar personas");
                }

                var newLink = new MovieSimilar
                {
                    Movie     = existingMovie,
                    MovieId   = existingMovie.Id,
                    Similar   = existingSimilar,
                    SimilarId = existingSimilar.Id,
                };

                DbContext.MovieSimilars.Add(newLink);
            }

            foreach (var movieCompany in movie.CompanyList)
            {
                var existingLink = DbContext.MovieCompanies.Find(new object[] { movieCompany.MovieId, movieCompany.CompanyId });
                if (existingLink != null)
                {
                    continue;
                }

                var existingCompany = DbContext.Companies.Find(new object[] { movieCompany.CompanyId });
                if (existingCompany == null)
                {
                    DbContext.Companies.Add(movieCompany.Company);
                    existingCompany = DbContext.Companies.Find(new object[] { movieCompany.CompanyId });
                }

                var existingMovie = DbContext.Movies.Find(new object[] { movieCompany.MovieId });
                if (existingMovie == null)
                {
                    throw new InvalidOperationException("Se esperaba encontrar pelicula para agregar personas");
                }

                var newLink = new MovieCompany
                {
                    Movie     = existingMovie,
                    MovieId   = existingMovie.Id,
                    Company   = existingCompany,
                    CompanyId = existingCompany.Id,
                };

                DbContext.MovieCompanies.Add(newLink);
            }
        }