Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        public async Task UpdateMovie_ShouldThrowException_WhenMovieNotExists()
        {
            using var context = DbContextScopeFactory.Create();
            var newMovie = TestMovieNotSeeded;

            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(newMovie));
        }
Example #4
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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        public async Task AreDetailsAvailable_ShouldCheckIfTheyAre_WhenMovieExistsInDb()
        {
            using var context = DbContextScopeFactory.CreateReadOnly();
            var detailsAvailable = await MovieDetailsDbAccess.AreDetailsAvailableFor(TestMovieSeededWithRelatedInfo.Id);

            var detailsNotAvailable = await MovieDetailsDbAccess.AreDetailsAvailableFor(TestMovieSeededWithoutRelatedInfo.Id);

            Assert.IsTrue(detailsAvailable);
            Assert.IsFalse(detailsNotAvailable);
        }
Example #9
0
        public async Task GetMovieById_ShouldGetAllDetails_WhenMovieExistsInDb()
        {
            using var context = DbContextScopeFactory.CreateReadOnly();
            var movieUnderTest = TestMovieSeededWithRelatedInfo;
            var actualDto      = await MovieDetailsDbAccess.GetMovieDetails(movieUnderTest.Id);

            var expectedDto = Mapper.Map <MovieWithDetailsDto>(movieUnderTest);

            actualDto.Should().BeEquivalentTo(expectedDto);
        }
Example #10
0
        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();
        }
Example #11
0
        protected LocalRepoMoviesTests(IConfig config) : base()
        {
            Config = config;

            var contextFactory = new TestDbContextFactory(Config);

            DbContextScopeFactory   = new DbContextScopeFactory(contextFactory);
            AmbientDbContextLocator = new AmbientDbContextLocator();
            MovieDetailsDbAccess    = new MovieDetailsDbAccess(AmbientDbContextLocator, Mapper, config);
            MovieListsDbAccess      = new MoviesListsDbAccess(AmbientDbContextLocator, Mapper);
            using var context       = DbContextScopeFactory.Create();
            MoviesContext.Database.EnsureDeleted();
            MoviesContext.Database.EnsureCreated();
        }
Example #12
0
        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");
        }
Example #13
0
        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");
        }
Example #14
0
        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);
        }
Example #15
0
        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);
        }