Esempio n. 1
0
        public async Task ThrowArgumentException_WhenArgumentsAreIncorrect(int movieID, int rating)
        {
            // Arrange
            var reviewRepoStub = new Mock <IRepository <Review> >();

            var movieRepoMock      = new Mock <IRepository <Movie> >();
            var directorRepoStub   = new Mock <IRepository <Director> >();
            var genreRepoStub      = new Mock <IRepository <Genre> >();
            var movieGenreRepoStub = new Mock <IRepository <MovieGenre> >();

            var sut = new MovieServices(reviewRepoStub.Object, movieRepoMock.Object, directorRepoStub.Object, genreRepoStub.Object, movieGenreRepoStub.Object);
            // Act & Assert
            await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await sut.RateMovieAsync(movieID, rating, "pishki", "randomUserId"));
        }
Esempio n. 2
0
        public async Task UpdateMovieScoreCreatingReview_WhenParametersAreCorrect()
        {
            // Arrange
            const int    movieID         = 2;
            const int    ratingInput     = 8;
            const string textInput       = "pishki";
            const string userId          = "213qwas";
            const int    r1rating        = 7;
            const int    r2rating        = 3;
            const int    r3DeleteDrating = 3;
            const int    movieScore      = 5;


            var movieRepoMock = new Mock <IRepository <Movie> >();
            var review1       = new Review {
                MovieID = movieID, MovieRating = r1rating, UserID = "123123123"
            };
            var review2 = new Review {
                MovieID = movieID, MovieRating = r2rating, UserID = "12352315"
            };
            var review3Deleted = new Review {
                MovieID = movieID, MovieRating = r3DeleteDrating, IsDeleted = true
            };
            var revireList = new List <Review>()
            {
                review1, review2, review3Deleted
            };
            var movie = new Movie
            {
                Name          = "Stivi's adventure into unit testing of the underworld",
                ID            = movieID,
                IsDeleted     = false,
                MovieScore    = movieScore,
                Reviews       = revireList,
                NumberOfVotes = 2
            };

            movieRepoMock
            .Setup(mr => mr.All())
            .Returns(new List <Movie>()
            {
                movie
            }.AsQueryable().BuildMock().Object);

            var reviewRepoMock     = new Mock <IRepository <Review> >();
            var directorRepoStub   = new Mock <IRepository <Director> >();
            var genreRepoStub      = new Mock <IRepository <Genre> >();
            var movieGenreRepoStub = new Mock <IRepository <MovieGenre> >();

            var sut = new MovieServices(reviewRepoMock.Object, movieRepoMock.Object, directorRepoStub.Object, genreRepoStub.Object, movieGenreRepoStub.Object);
            // Act
            await sut.RateMovieAsync(movieID, ratingInput, textInput, userId);

            //Assert
            //check if movie's score is updated should be 6
            Assert.IsTrue(movie.MovieScore == (r1rating + r2rating + ratingInput) / movie.NumberOfVotes);
            Assert.IsTrue(movie.Reviews.Last().MovieID == movieID);
            Assert.IsTrue(movie.Reviews.Last().MovieRating == ratingInput);
            Assert.IsTrue(movie.Reviews.Last().Text == textInput);
            movieRepoMock.Verify(mr => mr.Update(movie));
            movieRepoMock.Verify(mr => mr.SaveAsync(), Times.Once);
            movieRepoMock.Verify(rrm => rrm.SaveAsync(), Times.Once);
        }
Esempio n. 3
0
        public async Task ThrowMovieNotFoundExceptionWhenMovieIsNotValid(int movieID, bool deletedFlag)
        {
            // Arrange
            var reviewRepoStub = new Mock <IRepository <Review> >();

            var movieRepoMock = new Mock <IRepository <Movie> >();
            var movieMock     = new Movie
            {
                Name      = "Stivi's adventure into unit testing of the underworld",
                ID        = 1,
                IsDeleted = deletedFlag,
            };

            movieRepoMock
            .Setup(mr => mr.All())
            .Returns(new List <Movie>()
            {
                movieMock
            }.AsQueryable().BuildMock().Object);

            var directorRepoStub   = new Mock <IRepository <Director> >();
            var genreRepoStub      = new Mock <IRepository <Genre> >();
            var movieGenreRepoStub = new Mock <IRepository <MovieGenre> >();

            var sut = new MovieServices(reviewRepoStub.Object, movieRepoMock.Object, directorRepoStub.Object, genreRepoStub.Object, movieGenreRepoStub.Object);
            // Act & Assert
            await Assert.ThrowsExceptionAsync <MovieNotFoundException>(async() => await sut.RateMovieAsync(movieID, 5, "pishki", "randomUseRId"));
        }