public void GetByIds_MockMethodShouldBeInvoked()
        {
            // arrange
            var ids = new[] { Guid.NewGuid().ToString() };
            var repositoryResult = new List <CustomerReviewEntity>().ToArray();

            _repositoryFactory.Setup(repository => repository.GetByIds(ids)).Returns(repositoryResult);

            // act
            _customerReviewService.GetByIds(ids);

            // assert
            _repositoryFactory.VerifyAll();
        }
        public GenericSearchResult <CustomerReview> Search(CustomerReviewSearchCriteria criteria)
        {
            ValidateCriteria(criteria);

            using (var repository = _repositoryFactory())
            {
                var reviewsQuery      = BuildCustomerReviewsQuery(repository, criteria);
                var reviewsTotalCount = reviewsQuery.Count();
                var reviewsIdsQuery   = reviewsQuery
                                        .Skip(criteria.Skip)
                                        .Take(criteria.Take)
                                        .Select(entity => entity.Id);

                var idsList  = reviewsIdsQuery.ToList();
                var idsArray = idsList.ToArray();

                var reviews         = _customerReviewService.GetByIds(idsArray);
                var sortedReviews   = reviews.OrderBy(review => idsList.IndexOf(review.Id));
                var resultedReviews = sortedReviews.ToList();

                return(new GenericSearchResult <CustomerReview>
                {
                    TotalCount = reviewsTotalCount,
                    Results = resultedReviews
                });
            }
        }
Example #3
0
        public GenericSearchResult <CustomerReview> SearchCustomerReviews(CustomerReviewSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException($"{ nameof(criteria) } must be set");
            }

            var retVal = new GenericSearchResult <CustomerReview>();

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

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

                if (criteria.IsActive.HasValue)
                {
                    query = query.Where(x => x.IsActive == criteria.IsActive);
                }

                if (criteria.HasRating.HasValue)
                {
                    query = query.Where(x => x.Rating > 0);
                }

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

                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 customerReviewIds = query.Skip(criteria.Skip)
                                        .Take(criteria.Take)
                                        .Select(x => x.Id)
                                        .ToList();

                retVal.Results = _customerReviewService.GetByIds(customerReviewIds.ToArray())
                                 .OrderBy(x => customerReviewIds.IndexOf(x.Id)).ToList();
                return(retVal);
            }
        }
Example #4
0
        public IHttpActionResult GetCustomerReview(string id)
        {
            var result = _customerReviewService.GetByIds(new[] { id });

            if (result != null && result.Any())
            {
                return(Ok(result.FirstOrDefault(a => a.Id == id)));
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        protected override ExportableSearchResult FetchData(CustomerReviewSearchCriteria searchCriteria)
        {
            CustomerReview[] result;
            int totalCount;

            if (searchCriteria.ObjectIds.Any(x => !string.IsNullOrWhiteSpace(x)))
            {
                result     = _customerReviewService.GetByIds(Enumerable.ToArray(searchCriteria.ObjectIds));
                totalCount = result.Length;
            }
            else
            {
                var priceSearchResult = _searchService.SearchCustomerReviews(searchCriteria);
                result     = priceSearchResult.Results.ToArray();
                totalCount = priceSearchResult.TotalCount;
            }

            return(new ExportableSearchResult
            {
                Results = ToExportable(result).ToList(),
                TotalCount = totalCount,
            });
        }
Example #6
0
        public IHttpActionResult GetByIds([FromUri] string[] ids)
        {
            var result = _customerReviewService.GetByIds(ids);

            return(Ok(result));
        }