public async Task UpdateMovie_ShoulAddNewMovieActor_WhenOtherExistsPreviously() { var movieUnderTest = TestMovieSeededWithRelatedInfo; var secondRelationUnderTest = new MovieActor { Movie = movieUnderTest, MovieId = movieUnderTest.Id, Person = TestActorNotSeeded, PersonId = TestActorNotSeeded.Id, AsCharacter = "Paco" }; using var context = DbContextScopeFactory.Create(); movieUnderTest.ActorList.Add(secondRelationUnderTest); await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest)); context.SaveChanges(); var existingFirstRelation = MoviesContext.MovieActors.Find(movieUnderTest.Id, TestActorSeeded.Id); var existingSecondRelation = MoviesContext.MovieActors.Find(movieUnderTest.Id, TestActorNotSeeded.Id); var existingSecondPerson = MoviesContext.People.Find(TestActorNotSeeded.Id); var existingMovie = MoviesContext.Movies.Find(movieUnderTest.Id); existingFirstRelation.Should().BeEquivalentTo(TestMovieActorSeeded); existingSecondRelation.Should().BeEquivalentTo(secondRelationUnderTest); existingSecondPerson.Should().Be(TestActorNotSeeded); existingMovie.Should().Be(movieUnderTest); }
public async Task UpdateMovie_ShouldAddRatingSourceAndRating_WhenRatingSourceNotExists() { using var context = DbContextScopeFactory.Create(); var movieUnderTest = TestMovieSeededWithoutRelatedInfo; var newRatingSource = fixture.Build <RatingSource>() .With(x => x.Ratings, new List <Rating>()) .Create(); var relationUnderTest = new Rating { Movie = movieUnderTest, MovieId = movieUnderTest.Id, Source = newRatingSource, SourceId = newRatingSource.Id }; movieUnderTest.Ratings.Add(relationUnderTest); await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest)); context.SaveChanges(); var existingMovie = MoviesContext.Movies.Find(movieUnderTest.Id); var existingRelation = MoviesContext.Ratings.Find(movieUnderTest.Id, newRatingSource.Id); var existingRatingSource = MoviesContext.RatingSources.Find(newRatingSource.Id); existingMovie.Should().Be(movieUnderTest); existingRelation.Should().BeEquivalentTo(relationUnderTest); existingRatingSource.Should().Be(newRatingSource); }
public async Task UpdateMovie_ShouldThrowException_WhenMovieNotExists() { using var context = DbContextScopeFactory.Create(); var newMovie = TestMovieNotSeeded; await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(newMovie)); }
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); }
public async Task UpdateMovie_ShoulAddSecondMovieCompany_WhenOtherExistsPreviously() { var movieUnderTest = TestMovieSeededWithRelatedInfo; var secondRelationUnderTest = new MovieCompany { Movie = movieUnderTest, MovieId = movieUnderTest.Id, Company = TestCompanyNotSeeded, CompanyId = TestCompanyNotSeeded.Id }; using var context = DbContextScopeFactory.Create(); movieUnderTest.CompanyList.Add(secondRelationUnderTest); await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest)); context.SaveChanges(); var existingFirstRelation = MoviesContext.MovieCompanies.Include(x => x.Company).Single(x => x.MovieId == movieUnderTest.Id && x.CompanyId == TestCompanySeeded.Id); var existingSecondRelation = MoviesContext.MovieCompanies.Find(movieUnderTest.Id, TestCompanyNotSeeded.Id); var existingSecondCompany = MoviesContext.Companies.Find(TestCompanyNotSeeded.Id); var existingMovie = MoviesContext.Movies.Find(movieUnderTest.Id); existingFirstRelation.Should().BeEquivalentTo(TestMovieCompanySeeded); existingSecondRelation.Should().BeEquivalentTo(secondRelationUnderTest); existingSecondCompany.Should().Be(TestCompanyNotSeeded); existingMovie.Should().Be(movieUnderTest); }
public async Task UpdateMovie_ShouldAddCompanyAndMovieCompany_WhenCompanyNotExists() { using var context = DbContextScopeFactory.Create(); var movieUnderTest = TestMovieSeededWithoutRelatedInfo; var relationUnderTest = new MovieCompany { Movie = movieUnderTest, MovieId = movieUnderTest.Id, Company = TestCompanyNotSeeded, CompanyId = TestCompanyNotSeeded.Id }; movieUnderTest.CompanyList.Add(relationUnderTest); await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest)); context.SaveChanges(); var existingMovie = MoviesContext.Movies.Find(movieUnderTest.Id); var existingRelation = MoviesContext.MovieCompanies.Find(movieUnderTest.Id, TestCompanyNotSeeded.Id); var existingCompany = MoviesContext.Companies.Find(TestCompanyNotSeeded.Id); existingMovie.Should().Be(movieUnderTest); existingRelation.Should().BeEquivalentTo(relationUnderTest); existingCompany.Should().Be(TestCompanyNotSeeded); }
public async Task UpdateMovie_ShouldAddWriterAndMovieWriter_WhenWriterNotExists() { using var context = DbContextScopeFactory.Create(); var movieUnderTest = TestMovieSeededWithoutRelatedInfo; var relationUnderTest = new MovieWriter { Movie = movieUnderTest, MovieId = movieUnderTest.Id, Person = TestWriterNotSeeded, PersonId = TestWriterNotSeeded.Id }; movieUnderTest.WriterList.Add(relationUnderTest); await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest)); context.SaveChanges(); var existingMovie = MoviesContext.Movies.Find(movieUnderTest.Id); var existingRelation = MoviesContext.MovieWriters.Find(movieUnderTest.Id, TestWriterNotSeeded.Id); var existingWriter = MoviesContext.People.Find(TestWriterNotSeeded.Id); existingMovie.Should().Be(movieUnderTest); existingRelation.Should().BeEquivalentTo(relationUnderTest); existingWriter.Should().Be(TestWriterNotSeeded); }
public async Task UpdateMovie_ShouldChangeLastUpdatedDetails_WhenCalled() { using var context = DbContextScopeFactory.Create(); var movieUnderTest = TestMovieSeededWithoutRelatedInfo; await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest)); context.SaveChanges(); var existingMovie = MoviesContext.Movies.Find(TestMovieSeededWithoutRelatedInfo.Id); existingMovie.LastUpdatedDetails.Value.Should().BeCloseTo(DateTime.Now, 2000); existingMovie.AreDetailsAvailable.Should().BeTrue(); }
public async Task UpdateMovie_ShouldUpdateTrailer() { TestTrailerSeeded.ThumbnailUrl = "11111"; using var context = DbContextScopeFactory.Create(); TestMovieSeededWithoutRelatedInfo.Trailer = TestTrailerSeeded; await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(TestMovieSeededWithoutRelatedInfo)); context.SaveChanges(); var existingMovie = MoviesContext.Movies.Find(TestMovieSeededWithoutRelatedInfo.Id); existingMovie.Trailer.ThumbnailUrl.Should().Be("11111"); }
public async Task UpdateMovie_ShouldUpdateBoxOffice() { TestBoxOfficeSeeded.GrossUSA = "11111"; using var context = DbContextScopeFactory.Create(); TestMovieSeededWithoutRelatedInfo.BoxOffice = TestBoxOfficeSeeded; await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(TestMovieSeededWithoutRelatedInfo)); context.SaveChanges(); var existingMovie = MoviesContext.Movies.Find(TestMovieSeededWithoutRelatedInfo.Id); existingMovie.BoxOffice.GrossUSA.Should().Be("11111"); }
public async Task UpdateMovie_ShouldAddImages() { using var context = DbContextScopeFactory.Create(); var movieUnderTest = TestMovieSeededWithoutRelatedInfo; var relationUnderTest = TestMovieImageNotSeeded; relationUnderTest.Movie = movieUnderTest; relationUnderTest.MovieId = movieUnderTest.Id; movieUnderTest.Images.Add(relationUnderTest); await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest)); context.SaveChanges(); var existingMovie = MoviesContext.Movies.Find(movieUnderTest.Id); var existingRelation = MoviesContext.MovieImageDatas.Find(movieUnderTest.Id, TestMovieImageNotSeeded.Id); existingMovie.Should().Be(movieUnderTest); existingRelation.Should().BeEquivalentTo(relationUnderTest); }
public async Task UpdateMovie_ShouldAddRating_WhenMovieExists() { using var context = DbContextScopeFactory.Create(); var movieUnderTest = TestMovieSeededWithoutRelatedInfo; var relationUnderTest = new Rating { Movie = movieUnderTest, MovieId = movieUnderTest.Id, Source = RatingSources[0], SourceId = RatingSources[0].Id }; movieUnderTest.Ratings.Add(relationUnderTest); await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest)); context.SaveChanges(); var existingMovie = MoviesContext.Movies.Find(movieUnderTest.Id); var existingRelation = MoviesContext.Ratings.Find(movieUnderTest.Id, RatingSources[0].Id); existingMovie.Should().Be(movieUnderTest); existingRelation.Should().BeEquivalentTo(relationUnderTest); }