Example #1
0
        public async Task GetAllMovieReviews_400(string movieId, MovieReviewDto expectedReviews)
        {
            // Arrange
            var expectedResult    = Mapper.Map <MovieReviewDto, GetAllReviewsResponse>(expectedReviews);
            var mockReviewService = new Mock <IReviewService>();

            mockReviewService.Setup(x => x.GetAllReviewsAsync(It.IsAny <string>()))
            .Returns((string mId) => Task.FromResult(MockDataHelper.GetReviews(mId)));
            // Act
            var reviewController = new ReviewController(Mapper, mockReviewService.Object);
            var request          = new GetAllReviewsRequest
            {
                MovieId = movieId
            };
            var response = await reviewController.GetAllMovieReviews(request);

            // Assert
            var okResponse = Assert.IsType <OkObjectResult>(response.Result);
            var result     = Assert.IsAssignableFrom <GetAllReviewsResponse>(okResponse.Value);

            Assert.Equal(expectedResult.Reviews.Count(), result.Reviews.Count());
            Assert.False(result.Reviews.Any());
        }
Example #2
0
        public async Task GetAllMovieReviews_200(string movieId, MovieReviewDto expectedReviews)
        {
            // Arrange
            var expectedResult    = Mapper.Map <MovieReviewDto, GetAllReviewsResponse>(expectedReviews);
            var mockReviewService = new Mock <IReviewService>();

            mockReviewService.Setup(x => x.GetAllReviewsAsync(It.IsAny <string>()))
            .Returns((string mId) => Task.FromResult(MockDataHelper.GetReviews(mId)));
            // Act
            var reviewController = new ReviewController(Mapper, mockReviewService.Object);
            var request          = new GetAllReviewsRequest
            {
                MovieId = movieId
            };
            var response = await reviewController.GetAllMovieReviews(request);

            // Assert
            var okResponse = Assert.IsType <OkObjectResult>(response.Result);
            var result     = Assert.IsAssignableFrom <GetAllReviewsResponse>(okResponse.Value);


            foreach (var(actualReview, expectedReview) in result.Reviews.Zip(expectedResult.Reviews))
            {
                Assert.Equal(expectedReview.Author.DisplayName, actualReview.Author.DisplayName);
                Assert.Equal(expectedReview.Author.Id, actualReview.Author.Id);
                Assert.Equal(expectedReview.Author.Followers, actualReview.Author.Followers);
                Assert.Equal(expectedReview.Author.UserName, actualReview.Author.UserName);

                Assert.Equal(expectedReview.Movie.Id, actualReview.Movie.Id);
                Assert.Equal(expectedReview.Movie.Title, actualReview.Movie.Title);

                Assert.Equal(expectedReview.Description, actualReview.Description);
                Assert.Equal(expectedReview.Rating, actualReview.Rating);
                Assert.Equal(expectedReview.Title, actualReview.Title);
            }
        }