Beispiel #1
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));
        }
Beispiel #2
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));
        }
Beispiel #3
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));
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public void CalculateProductRatings(string[] productIds)
        {
            if (productIds == null)
            {
                throw new ArgumentNullException(nameof(productIds));
            }

            SaveProductRatings(productIds.Select(x => new ProductRating()
            {
                ProductId = x,
                Rating    = _calculator.GetProductRating(x)
            }).ToArray());
        }