public async Task Call_MapFunction_Once()
        {
            var dabataseName = nameof(Call_MapFunction_Once);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            Movie movieReturned = null;

            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock
            .Setup(x => x.MapTo <MovieViewModel>(It.IsAny <Movie>()))
            .Callback <object>(inputargs => movieReturned = inputargs as Movie);

            // we use new instance of that context, but it has the data already saved.
            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut       = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string movieName = "London";
                string actorName = "Deo";

                await sut.ManageActorAsync(movieName, actorName);

                mappingProviderMock.Verify(m => m.MapTo <MovieViewModel>(movieReturned), Times.Once);
            }
        }
        public async Task Correctly_UnassignActorToMovie()
        {
            var dabataseName = nameof(Correctly_UnassignActorToMovie);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            // we use new instance of that context, but it has the data already saved.
            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                // Actor Johnny has already been assigned to this movie in the Test Utilies, upon db filling.
                var    sut       = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string movieName = "Spiderman";
                string actorName = "Johnny";

                await sut.ManageActorAsync(movieName, actorName);

                Assert.IsTrue(actAndAssertContext
                              .Movies.FirstOrDefault(x => x.Name == movieName)
                              .MovieActor.Any(a => a.Actor?.Name == actorName) == false);
            }
        }
Esempio n. 3
0
        public async Task ReturnCorrectViewModel()
        {
            // Arrange
            var dabataseName = nameof(ReturnCorrectViewModel);
            var options      = MovieTestUtils.GetOptions(dabataseName);

            MovieTestUtils.FillContextWithGenre(options);

            // setting up the automapper to be able to map the object from Movie to MovieViewModel
            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock.Setup(x => x.MapTo <MovieViewModel>(It.IsAny <Movie>())).Returns(new MovieViewModel());

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut       = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string movieName = "TestMovie";
                int    duration  = 90;
                string director  = "TestDirector";
                string storyline = "TestStoryline";
                string imageUrl  = "TestImageUrl";
                string genreName = "Comedy";

                var result = await sut.CreateMovieAsync(movieName, duration, storyline, director, imageUrl, genreName);

                Assert.IsInstanceOfType(result, typeof(MovieViewModel));
            }
        }
Esempio n. 4
0
        public async Task Call_MapFunction_Once()
        {
            var dabataseName = nameof(Return_CorrectMovie);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            Movie movie = null;

            mappingProviderMock
            .Setup(m => m.MapTo <MovieViewModel>(It.IsAny <Movie>()))
            .Callback <object>(inputargs => movie = inputargs as Movie);

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut       = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string movieName = "Spiderman";

                await sut.GetMovieByNameAsync(movieName);

                mappingProviderMock.Verify(m => m.MapTo <MovieViewModel>(movie), Times.Once);
            }
        }
Esempio n. 5
0
        public async Task AddNewMovie_WhenAllParametersAreValid()
        {
            var dabataseName = nameof(AddNewMovie_WhenAllParametersAreValid);
            var options      = MovieTestUtils.GetOptions(dabataseName);

            MovieTestUtils.FillContextWithGenre(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            string movieName = "Spiderman";
            int    duration  = 90;
            string director  = "TestDirector";
            string storyline = "TestStoryline";
            string imageUrl  = "TestImageUrl";
            string genreName = "Comedy";

            using (var arrangeContext = new MovieManagementContext(options))
            {
                var sut = new MovieService(arrangeContext, mappingProviderMock.Object);

                await sut.CreateMovieAsync(movieName, duration, storyline, director, imageUrl, genreName);

                arrangeContext.SaveChanges();
            }

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                Assert.IsTrue(actAndAssertContext.Movies.Count() == 1);
                Assert.IsTrue(actAndAssertContext.Movies.Any(m => m.Name == movieName));
            }
        }
Esempio n. 6
0
        public async Task Throw_WhenMovie_DoesExists()
        {
            var dabataseName = nameof(Throw_WhenMovie_DoesExists);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            // we use new instance of that context, but it has the data already saved.
            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut       = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string movieName = "Spiderman";
                int    duration  = 90;
                string director  = "TestDirector";
                string storyline = "TestStoryline";
                string imageUrl  = "TestImageUrl";
                string genreName = "TestGenre";

                await Assert.ThrowsExceptionAsync <EntityAlreadyExistsException>(
                    async() => await sut.CreateMovieAsync(movieName, duration, storyline, director, imageUrl, genreName));
            }
        }
Esempio n. 7
0
        public async Task Flag_MovieAsDeleted()
        {
            var dabataseName = nameof(Flag_MovieAsDeleted);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            // we use new instance of that context, but it has the data already saved.
            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut       = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string movieName = "Spiderman";

                var movie = await actAndAssertContext.Movies.FirstOrDefaultAsync(m => m.Name == movieName);

                Assert.IsTrue(movie.IsDeleted == false);

                await sut.DeleteMovieAsync(movieName);

                Assert.IsTrue(await actAndAssertContext.Movies.AnyAsync(m => m.Name == movieName) == false);
            }
        }
        public async Task Add_VotesCountSuccessfully()
        {
            var dabataseName = nameof(Add_VotesCountSuccessfully);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            // we use new instance of that context, but it has the data already saved.
            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut       = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string movieName = "Spiderman";
                double rating    = 10;

                var movie = await actAndAssertContext.Movies.FirstOrDefaultAsync(m => m.Name == movieName);

                Assert.IsTrue(movie.VotesCount == 0);

                await sut.RateMovieAsync(movieName, rating);

                Assert.IsTrue(actAndAssertContext.Movies.FirstOrDefault(m => m.Name == movieName).VotesCount == 1);
            }
        }
Esempio n. 9
0
        public async Task Return_TwoMoviesInCorrectOrderByDateCrated()
        {
            var dabataseName = nameof(Return_TwoMoviesInCorrectOrderByDateCrated);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithGenre(options);

            var collectionOfMovies = new List <Movie>();

            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock
            .Setup(x => x.MapTo <ICollection <MovieViewModel> >(It.IsAny <List <Movie> >()))
            .Callback <object>(inputargs => collectionOfMovies = inputargs as List <Movie>);

            using (var arrangeContext = new MovieManagementContext(options))
            {
                arrangeContext.Movies.Add(new Movie()
                {
                    Name     = "BestRatedMovieTest",
                    Duration = 90,
                    //Rating = 5,
                    //VotesCount = 1,
                    Director  = "TestDirector",
                    Storyline = "TestStoryline",
                    ImageUrl  = "TestImageUrl",
                    GenreID   = "e9c7b88f-4ef4-4cb9-9acd-c65f6d94de60",
                    CreatedOn = DateTime.Parse("3/20/2019 7:36:05 PM")
                });
                arrangeContext.Movies.Add(new Movie()
                {
                    Name     = "SecondMovieTestName",
                    Duration = 90,
                    //Rating = 3,
                    //VotesCount = 1,
                    Director  = "TestDirector",
                    Storyline = "TestStoryline",
                    ImageUrl  = "TestImageUrl",
                    GenreID   = "e9c7b88f-4ef4-4cb9-9acd-c65f6d94de60",
                    CreatedOn = DateTime.Parse("4/15/2019 7:36:05 PM")
                });
                await arrangeContext.SaveChangesAsync();
            }

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var sut = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                await sut.GetLatestMoviesAsync();

                Assert.AreEqual(2, collectionOfMovies.Count());
                Assert.AreEqual("SecondMovieTestName", collectionOfMovies.FirstOrDefault().Name);
            }
        }
        public async Task Return_TwoMoviesInCorrectOrderByDateCrated()
        {
            var dabataseName = nameof(Return_TwoMoviesInCorrectOrderByDateCrated);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            var collectionOfMovies = new List <Movie>();

            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock
            .Setup(x => x.MapTo <ICollection <MovieViewModel> >(It.IsAny <List <Movie> >()))
            .Callback <object>(inputargs => collectionOfMovies = inputargs as List <Movie>);

            using (var arrangeContext = new MovieManagementContext(options))
            {
                arrangeContext.Movies.Add(new Movie()
                {
                    Name      = "VeryCoolMovie",
                    Duration  = 90,
                    Director  = "TestDirector",
                    Storyline = "TestStoryline",
                    ImageUrl  = "TestImageUrl",
                    GenreID   = "e9c7b88f-4ef4-4cb9-9acd-c65f6d94de60"
                });
                arrangeContext.Movies.Add(new Movie()
                {
                    Name      = "NotThatCoolMovie",
                    Duration  = 90,
                    Director  = "TestDirector",
                    Storyline = "TestStoryline",
                    ImageUrl  = "TestImageUrl",
                    GenreID   = "e9c7b88f-4ef4-4cb9-9acd-c65f6d94de60"
                });
                await arrangeContext.SaveChangesAsync();
            }

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var sut = new MovieService(actAndAssertContext, mappingProviderMock.Object);

                string partOfTitle = "Cool";
                await sut.SearchAsync(partOfTitle);

                Assert.AreEqual(2, collectionOfMovies.Count());

                Assert.IsTrue(collectionOfMovies.Any(x => x.Name == "VeryCoolMovie"));
                Assert.IsTrue(collectionOfMovies.Any(x => x.Name == "NotThatCoolMovie"));
            }
        }
Esempio n. 11
0
        public async Task Call_MapFunction_Once()
        {
            var dabataseName = nameof(Call_MapFunction_Once);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithGenre(options);

            var collectionOfMovies = new List <Movie>();

            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock
            .Setup(x => x.MapTo <ICollection <MovieViewModel> >(It.IsAny <List <Movie> >()))
            .Callback <object>(inputargs => collectionOfMovies = inputargs as List <Movie>);

            using (var arrangeContext = new MovieManagementContext(options))
            {
                arrangeContext.Movies.Add(new Movie()
                {
                    Name       = "BestRatedMovieTest",
                    Duration   = 90,
                    Rating     = 5,
                    VotesCount = 1,
                    Director   = "TestDirector",
                    Storyline  = "TestStoryline",
                    ImageUrl   = "TestImageUrl",
                    GenreID    = "e9c7b88f-4ef4-4cb9-9acd-c65f6d94de60"
                });
                arrangeContext.Movies.Add(new Movie()
                {
                    Name       = "SecondMovieTestName",
                    Duration   = 90,
                    Rating     = 3,
                    VotesCount = 1,
                    Director   = "TestDirector",
                    Storyline  = "TestStoryline",
                    ImageUrl   = "TestImageUrl",
                    GenreID    = "e9c7b88f-4ef4-4cb9-9acd-c65f6d94de60",
                });
                await arrangeContext.SaveChangesAsync();
            }

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var sut = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                await sut.GetTopRatedMoviesAsync();

                mappingProviderMock.Verify(m => m.MapTo <ICollection <MovieViewModel> >(collectionOfMovies), Times.Once);
            }
        }
        public async Task Call_MapFunction_Once()
        {
            var dabataseName = nameof(Call_MapFunction_Once);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            Movie movieReturned = null;

            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock
            .Setup(x => x.MapTo <MovieViewModel>(It.IsAny <Movie>()))
            .Callback <object>(inputargs => movieReturned = inputargs as Movie);

            string newMovieName = "NewSpiderman";
            int    duration     = 120;
            string storyline    = "NewStoryline";
            string director     = "NewDirector";
            string imageUrl     = "NewImageUrl";

            var movieViewModel = new MovieViewModel()
            {
                Name      = newMovieName,
                Duration  = duration,
                Storyline = storyline,
                Director  = director,
                ImageUrl  = imageUrl
            };

            // we use new instance of that context, but it has the data already saved.
            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut          = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string oldMovieName = "Spiderman";

                await sut.UpdateMovieAsync(oldMovieName, movieViewModel);

                mappingProviderMock.Verify(m => m.MapTo <MovieViewModel>(movieReturned), Times.Once);
            }
        }
        public async Task UpdateMovie_WithCorrectInformation()
        {
            var dabataseName = nameof(UpdateMovie_WithCorrectInformation);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            string newMovieName = "NewSpiderman";
            int    duration     = 120;
            string storyline    = "NewStoryline";
            string director     = "NewDirector";
            string imageUrl     = "NewImageUrl";

            var movieViewModel = new MovieViewModel()
            {
                Name      = newMovieName,
                Duration  = duration,
                Storyline = storyline,
                Director  = director,
                ImageUrl  = imageUrl
            };

            // we use new instance of that context, but it has the data already saved.
            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut          = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string oldMovieName = "Spiderman";

                await sut.UpdateMovieAsync(oldMovieName, movieViewModel);

                Assert.IsTrue(await actAndAssertContext.Movies.AnyAsync(m => m.Name == newMovieName));
                Assert.IsTrue(await actAndAssertContext.Movies.AnyAsync(m => m.Duration == duration));
                Assert.IsTrue(await actAndAssertContext.Movies.AnyAsync(m => m.Storyline == storyline));
                Assert.IsTrue(await actAndAssertContext.Movies.AnyAsync(m => m.Director == director));
                Assert.IsTrue(await actAndAssertContext.Movies.AnyAsync(m => m.ImageUrl == imageUrl));
            }
        }
Esempio n. 14
0
        public async Task Throw_WhenMovie_DoesNotExists()
        {
            var dabataseName = nameof(Throw_WhenMovie_DoesNotExists);

            var options = MovieTestUtils.GetOptions(dabataseName);

            // We fill the context with data and save it.
            MovieTestUtils.FillContextWithActorsMoviesAndGenres(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            // we use new instance of that context, but it has the data already saved.
            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut       = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string movieName = "TestInvalidMovie";

                await Assert.ThrowsExceptionAsync <EntityInvalidException>(
                    async() => await sut.GetMovieByNameAsync(movieName));
            }
        }
Esempio n. 15
0
        public async Task Throw_WhenGenreIsNotFound()
        {
            var dabataseName = nameof(Throw_WhenGenreIsNotFound);
            var options      = MovieTestUtils.GetOptions(dabataseName);

            var mappingProviderMock = new Mock <IMappingProvider>();

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var    sut       = new MovieService(actAndAssertContext, mappingProviderMock.Object);
                string movieName = "Spiderman";
                int    duration  = 90;
                string director  = "TestDirector";
                string storyline = "TestStoryline";
                string imageUrl  = "TestImageUrl";
                string genreName = "TestGenre";

                await Assert.ThrowsExceptionAsync <EntityInvalidException>(
                    async() => await sut.CreateMovieAsync(movieName, duration, storyline, director, imageUrl, genreName));
            }
        }