예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,UsuarioId,ProductoId,Comentario")] Review review)
        {
            if (ModelState.IsValid)
            {
                await _reviewsService.CreateReview(review);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(review));
        }
예제 #2
0
        public async Task CreateReview_WithValidData_ShouldCreateAReview()
        {
            //Arrange
            var expectedReviewsCount = 1;

            var moqUsersService = new Mock <IUsersService>();
            var context         = InitializeContext.CreateContextForInMemory();

            reviewsService = new ReviewsService(context, moqUsersService.Object);

            //Act
            await reviewsService.CreateReview("OwnerId", "CreatorId", "Content", 3);

            //Assert
            Assert.Equal(expectedReviewsCount, context.Reviews.Count());
        }
예제 #3
0
        public async Task CreateReview_WithNullOrEmptyArguments_ShouldThrowAnArgumentException(string ownerId, string creatorId, string content)
        {
            //Arrange
            var expectedErrorMessage = "Some of the arguments are null or empty!";
            var moqUsersService      = new Mock <IUsersService>();
            var context = InitializeContext.CreateContextForInMemory();

            reviewsService = new ReviewsService(context, moqUsersService.Object);


            //Assert and act
            var ex = await Assert.ThrowsAsync <ArgumentException>(() =>
                                                                  reviewsService.CreateReview(ownerId, creatorId, content, 1));

            Assert.Equal(expectedErrorMessage, ex.Message);
        }
예제 #4
0
        public async Task CreateReview_WithOwnerEqualToCreator_ShouldThrowAnInvalidOperationException()
        {
            //Arrange
            var expectedErrorMessage = "Seller of the ad can't leave reviews for his ads!";

            var moqUsersService = new Mock <IUsersService>();
            var context         = InitializeContext.CreateContextForInMemory();

            reviewsService = new ReviewsService(context, moqUsersService.Object);


            //Assert and act
            var ex = await Assert.ThrowsAsync <InvalidOperationException>(() =>
                                                                          reviewsService.CreateReview("CreatorId", "CreatorId", "Content", 3));

            Assert.Equal(expectedErrorMessage, ex.Message);
        }
예제 #5
0
        public async Task CreateReview_WithRatingOutOfRange_ShouldThrowAnArgumentException(int rating)
        {
            //Arrange
            var expectedErrorMessage = "The rating must be in range between 1 and 5";

            var moqUsersService = new Mock <IUsersService>();
            var context         = InitializeContext.CreateContextForInMemory();

            reviewsService = new ReviewsService(context, moqUsersService.Object);


            //Assert and act
            var ex = await Assert.ThrowsAsync <ArgumentException>(() =>
                                                                  reviewsService.CreateReview("OwnerId", "CreatorId", "Content", rating));

            Assert.Equal(expectedErrorMessage, ex.Message);
        }
예제 #6
0
        public async Task <IActionResult> LeaveComment(ReviewInputModel inputModel)
        {
            if (reviewsService.CheckOwnerIdAndSellerId(inputModel.CreatorId, inputModel.OwnerId))
            {
                ModelState.AddModelError("ShopOwner", "You can't leave a review because you are the owner of the shop!");
            }

            if (!ModelState.IsValid)
            {
                var reviewBindingModel = await reviewsService.GetReviewsBindingModelByUserId(inputModel.OwnerId, DefaultPageNumber, DefaultPageSize);

                reviewBindingModel.InputModel = inputModel;
                return(View("ReviewsByShop", reviewBindingModel));
            }

            await reviewsService.CreateReview(inputModel.OwnerId, inputModel.CreatorId, inputModel.Content,
                                              inputModel.Rating);

            return(RedirectToAction("ReviewsByShop", new { userId = inputModel.OwnerId }));
        }