public GenericSearchResult <CustomerReviewVote> SearchCustomerReviewVotes(CustomerReviewVoteSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException($"{nameof(criteria)} must be set");
            }

            var retVal = new GenericSearchResult <CustomerReviewVote>();

            using (var repository = _repositoryFactory())
            {
                var query = repository.CustomerReviewVotes;

                if (!criteria.CustomerReviewIds.IsNullOrEmpty())
                {
                    query = query.Where(x => criteria.CustomerReviewIds.Contains(x.CustomerReviewId));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "CreatedDate", SortDirection = SortDirection.Descending
                                        } };
                }
                query = query.OrderBySortInfos(sortInfos);

                retVal.TotalCount = query.Count();

                var customerReviewVoteIds = query.Skip(criteria.Skip)
                                            .Take(criteria.Take)
                                            .Select(x => x.Id)
                                            .ToList();

                retVal.Results = _customerReviewService.GetVoteByIds(customerReviewVoteIds.ToArray())
                                 .OrderBy(x => customerReviewVoteIds.IndexOf(x.Id)).ToList();

                return(retVal);
            }
        }
        public IHttpActionResult SearchCustomerReviewVotes(CustomerReviewVoteSearchCriteria criteria)
        {
            var result = _customerReviewSearchService.SearchCustomerReviewVotes(criteria);

            return(Ok(result));
        }
示例#3
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();
        }