Exemple #1
0
        public void CanGroupDistinctBooks()
        {
            var basket = new Basket();

            basket.Add(Book.A);
            basket.Add(Book.A);
            basket.Add(Book.B);
            basket.Add(Book.B);
            basket.Add(Book.C);
            basket.Add(Book.C);
            basket.Add(Book.D);
            basket.Add(Book.E);

            var bookGrouper = new BookGrouper();

            var distinctGroups = bookGrouper.SortBooksIntoDistinctGroups(basket.Books);

            Assert.Equal(2, distinctGroups.Count);
        }
Exemple #2
0
        public decimal CalculateBasketTotal()
        {
            var basketTotal = 0m;

            var grouper = new BookGrouper();

            var distinctProductGroups = grouper.SortBooksIntoDistinctGroups(this.basket.Books);

            var productDiscounter = new PriceDiscountCalculator();

            foreach (var distinctProductGroup in distinctProductGroups)
            {
                var totalGroupPrice = GetGroupPrice(distinctProductGroup.Count, this.fullProductPrice);

                basketTotal += productDiscounter.TotalDiscountAppliedToDistinctBookCollection(
                    distinctProductGroup.Count,
                    totalGroupPrice);
            }

            return(basketTotal);
        }