Esempio n. 1
0
        protected virtual Task LoadProductCustomerReviewsAsync(List <Product> products, WorkContext workContext)
        {
            if (products == null)
            {
                throw new ArgumentException(nameof(products));
            }

            foreach (var product in products)
            {
                product.CustomerReviews = new MutablePagedList <Model.CustomerReviews.CustomerReview>((pageNumber, pageSize, sortInfos, @params) =>
                {
                    var criteria = new CustomerReviewSearchCriteria
                    {
                        ProductIds = new[] { product.Id },
                        PageNumber = pageNumber,
                        PageSize   = pageSize,
                        Sort       = SortInfo.ToString(sortInfos)
                    };
                    return(_customerReviewService.SearchReview(criteria));
                }, 1, CustomerReviewSearchCriteria.DefaulePageSize);
                product.Rating = _customerReviewService.GetProductRating(product.Id);
            }
            return(Task.CompletedTask);
        }
        public void GetProductRating_ShouldBeEquals(float expected, float review1Rating, float review2Rating)
        {
            // arrange
            var fakeProductId = "fake_product_id";
            var review1       = new CustomerReviewEntity {
                ProductId = fakeProductId, Rating = review1Rating
            };
            var review2 = new CustomerReviewEntity {
                ProductId = fakeProductId, Rating = review2Rating
            };
            var repositoryResult = new List <CustomerReviewEntity>
            {
                review1,
                review2
            };

            _repositoryFactory.Setup(repository => repository.CustomerReviews).Returns(repositoryResult.AsQueryable());

            // act
            var result = _customerReviewService.GetProductRating("fake_product_id");

            // assert
            Assert.Equal(expected, result);
        }
        public IHttpActionResult GetProductRating(string productId)
        {
            var result = _customerReviewService.GetProductRating(productId);

            return(Ok(result));
        }
Esempio n. 4
0
 public async Task <ActionResult <string> > GetProductRating(string productId)
 {
     return(await _customerReviewService.GetProductRating(productId));
 }