示例#1
0
        public void RankingMinCount()
        {
            var allReviews = new List <CustomerReview>()
            {
                new CustomerReview()
                {
                    ProductId = Product1Id, Rating = 1
                },
                new CustomerReview()
                {
                    ProductId = Product2Id, Rating = 1
                },
                new CustomerReview()
                {
                    ProductId = Product1Id, Rating = 1
                },
            };
            IProductRaitingCalculator calculator = GetCalculator(allReviews.Take(2).ToList());

            Assert.Equal(0m, calculator.GetProductRating(Product1Id));
            Assert.Equal(0m, calculator.GetProductRating(Product2Id));
            Assert.Equal(0m, calculator.GetProductRating(Product3Id));

            calculator = GetCalculator(allReviews);
            Assert.Equal(1m, calculator.GetProductRating(Product1Id));
            Assert.Equal(0m, calculator.GetProductRating(Product2Id));
            Assert.Equal(0m, calculator.GetProductRating(Product3Id));
        }
示例#2
0
        public void BadArguments()
        {
            var allReviews = new List <CustomerReview>()
            {
            };
            IProductRaitingCalculator calculator = GetCalculator(allReviews);

            Assert.Throws <ArgumentNullException>(() => calculator.GetProductRating(null));
            Assert.Equal(0m, calculator.GetProductRating(NonExistentProductId));
        }
示例#3
0
        public void NoRankingsOnReviews()
        {
            var allReviews = new List <CustomerReview>()
            {
                new CustomerReview()
                {
                    ProductId = Product1Id
                },
                new CustomerReview()
                {
                    ProductId = Product1Id
                },
                new CustomerReview()
                {
                    ProductId = Product1Id
                },
                new CustomerReview()
                {
                    ProductId = Product2Id
                },
                new CustomerReview()
                {
                    ProductId = Product2Id
                },
                new CustomerReview()
                {
                    ProductId = Product2Id
                },
                new CustomerReview()
                {
                    ProductId = Product2Id
                },
                new CustomerReview()
                {
                    ProductId = Product2Id
                },
                new CustomerReview()
                {
                    ProductId = Product2Id
                },
                new CustomerReview()
                {
                    ProductId = Product3Id
                },
            };
            IProductRaitingCalculator calculator = GetCalculator(allReviews);

            Assert.Equal(0m, calculator.GetProductRating(Product1Id));
            Assert.Equal(0m, calculator.GetProductRating(Product2Id));
            Assert.Equal(0m, calculator.GetProductRating(Product3Id));
        }
示例#4
0
        public void ComplexScenario()
        {
            var allReviews = new List <CustomerReview>()
            {
                new CustomerReview()
                {
                    ProductId = Product1Id, Rating = 1
                },
                new CustomerReview()
                {
                    ProductId = Product1Id, Rating = 2
                },
                new CustomerReview()
                {
                    ProductId = Product1Id, Rating = 3
                },
                new CustomerReview()
                {
                    ProductId = Product1Id, Rating = 4
                },
                new CustomerReview()
                {
                    ProductId = Product1Id, Rating = 5
                },
                new CustomerReview()
                {
                    ProductId = Product2Id, Rating = 2
                },
                new CustomerReview()
                {
                    ProductId = Product2Id, Rating = 1
                },
                new CustomerReview()
                {
                    ProductId = Product3Id, Rating = 2
                },
                new CustomerReview()
                {
                    ProductId = Product3Id, Rating = 5
                },
                new CustomerReview()
                {
                    ProductId = Product3Id, Rating = 5
                },
            };
            IProductRaitingCalculator calculator = GetCalculator(allReviews);

            Assert.Equal(3m, calculator.GetProductRating(Product1Id));
            Assert.Equal(2.25m, calculator.GetProductRating(Product2Id));
            Assert.Equal(3.6m, calculator.GetProductRating(Product3Id));
        }
示例#5
0
 public ProductRatingService(Func <IProductRatingRepository> repositoryFactory, IProductRaitingCalculator calculator)
 {
     _repositoryFactory = repositoryFactory;
     _calculator        = calculator;
 }