public static reviewDto.CustomerReviewVote ToCustomerReviewVoteDto(this CustomerReviewVote сustomerReviewVote)
        {
            var result = new reviewDto.CustomerReviewVote
            {
                Id = сustomerReviewVote.Id,
                CustomerReviewId = сustomerReviewVote.CustomerReviewId,
                AuthorId         = сustomerReviewVote.AuthorId,
                ReviewRate       = сustomerReviewVote.ReviewRate,

                CreatedBy    = сustomerReviewVote.CreatedBy,
                CreatedDate  = сustomerReviewVote.CreatedDate,
                ModifiedBy   = сustomerReviewVote.ModifiedBy,
                ModifiedDate = сustomerReviewVote.ModifiedDate,
            };

            return(result);
        }
        public virtual CustomerReviewVote ToModel(CustomerReviewVote customerReviewVote)
        {
            if (customerReviewVote == null)
            {
                throw new ArgumentNullException(nameof(customerReviewVote));
            }

            customerReviewVote.Id           = Id;
            customerReviewVote.CreatedBy    = CreatedBy;
            customerReviewVote.ModifiedBy   = ModifiedBy;
            customerReviewVote.ModifiedDate = ModifiedDate;

            customerReviewVote.AuthorId         = AuthorId;
            customerReviewVote.ReviewRate       = ReviewRate;
            customerReviewVote.CustomerReviewId = CustomerReviewId;

            return(customerReviewVote);
        }
        public virtual CustomerReviewVoteEntity FromModel(CustomerReviewVote customerReviewVote, PrimaryKeyResolvingMap pkMap)
        {
            if (customerReviewVote == null)
            {
                throw new ArgumentNullException(nameof(customerReviewVote));
            }

            pkMap.AddPair(customerReviewVote, this);

            Id           = customerReviewVote.Id;
            CreatedBy    = customerReviewVote.CreatedBy;
            CreatedDate  = customerReviewVote.CreatedDate;
            ModifiedBy   = customerReviewVote.ModifiedBy;
            ModifiedDate = customerReviewVote.ModifiedDate;

            AuthorId         = customerReviewVote.AuthorId;
            ReviewRate       = customerReviewVote.ReviewRate;
            CustomerReviewId = customerReviewVote.CustomerReviewId;

            return(this);
        }
Пример #4
0
        public void CanDoReviewVoteCRUDandSearch()
        {
            //Read non-existing item
            var getVoteByIdsResult = _customerReviewService.GetVoteByIds(new[] { _customerReviewVoteId });

            Assert.NotNull(getVoteByIdsResult);
            Assert.Empty(getVoteByIdsResult);

            //Create new ReviewVote item
            var itemVote = new CustomerReviewVote
            {
                Id               = _customerReviewVoteId,
                AuthorId         = _authorId,
                CustomerReviewId = _customerReviewId,
                CreatedDate      = DateTime.Now,
                CreatedBy        = "initial data seed",
                VoteIdx          = VoteRate.Helpfull
            };

            //Create new Review item
            var itemReview = new CustomerReview
            {
                Id             = _customerReviewId,
                ProductId      = _productId,
                CreatedDate    = DateTime.Now,
                CreatedBy      = "initial data seed",
                AuthorNickname = "John Doe",
                Content        = "Liked that"
            };

            _customerReviewService.SaveCustomerReviews(new[] { itemReview });

            //Save ReviewVote item for existing Review item
            _customerReviewService.SaveCustomerReviewVotes(new[] { itemVote });

            var getReviewByIdsResult = _customerReviewService.GetReviewByIds(new[] { _customerReviewId });

            Assert.Single(getReviewByIdsResult);

            getVoteByIdsResult = _customerReviewService.GetVoteByIds(new[] { _customerReviewVoteId });
            Assert.Single(getVoteByIdsResult);

            //Check that TotalVotesCount HelpfullVotesCount UselessVotesCount fields of Review item are changed
            itemReview = getReviewByIdsResult[0];
            Assert.Equal(1, itemReview.TotalVotesCount);
            Assert.Equal(1, itemReview.HelpfullVotesCount);
            Assert.Equal(0, itemReview.UselessVotesCount);

            itemVote = getVoteByIdsResult[0];
            Assert.Equal(_customerReviewVoteId, itemVote.Id);


            //Search Votes by creteria
            Assert.Throws <ArgumentNullException>(() => _customerReviewSearchService.SearchCustomerReviewVotes(null));

            var criteriaVote = new CustomerReviewVoteSearchCriteria {
                CustomerReviewIds = new[] { _customerReviewId }
            };
            var searchResultVote = _customerReviewSearchService.SearchCustomerReviewVotes(criteriaVote);

            Assert.NotNull(searchResultVote);
            Assert.Equal(1, searchResultVote.TotalCount);
            Assert.Single(searchResultVote.Results);

            //Update existing item
            var updatedVoteIdx = VoteRate.Useless;

            Assert.NotEqual(updatedVoteIdx, itemVote.VoteIdx);

            itemVote.VoteIdx = updatedVoteIdx;
            _customerReviewService.SaveCustomerReviewVotes(new[] { itemVote });
            getVoteByIdsResult = _customerReviewService.GetVoteByIds(new[] { _customerReviewVoteId });
            Assert.Single(getVoteByIdsResult);

            itemVote = getVoteByIdsResult[0];
            Assert.Equal(updatedVoteIdx, itemVote.VoteIdx);



            //Delete existing items
            CanDeleteCustomerReviewVotes();
            CanDeleteCustomerReviews();
        }