Example #1
0
        public void Baskets_With_Single_Bundle_Of_Different_Copies_Of_Roald_Dahl_Books_Has_Discount_Applied()
        {
            //Arrange
            var discount      = TestHelper.RandomDiscount();
            var bundleSize    = TestHelper.RandomInteger(1, 100);
            var expectedPrice = 0M;

            var basket = new Basket(new Dictionary <int, decimal>
            {
                { bundleSize, discount },
            }
                                    );

            for (int i = 1; i <= bundleSize; i++)
            {
                //Arrange
                var book = new Book(code: i);
                expectedPrice += book.Price;

                //Act
                basket.Add(book);
            }

            expectedPrice *= (1M - discount);

            //Assert
            Assert.AreEqual(expected: bundleSize, actual: basket.Items.Count);
            Assert.AreEqual(expected: expectedPrice, actual: basket.Total);
        }
Example #2
0
        public void Baskets_With_Multiple_Bundles_Of_Different_Copies_Of_Roald_Dahl_Books_Has_Discounts_Applied()
        {
            //Arrange
            var bundleRules   = new Dictionary <int, decimal>();
            var books         = new List <Book>();
            var expectedPrice = 0M;

            var maxBundleSize = TestHelper.RandomInteger(1, 10);

            for (int i = 1; i < maxBundleSize; i++)
            {
                var discount = TestHelper.RandomDiscount();
                bundleRules.Add(i, discount);

                var bundlePrice = 0M;

                for (int j = 1; j <= i; j++)
                {
                    var book = new Book(code: j);
                    bundlePrice += book.Price;
                    books.Add(book);
                }

                expectedPrice += bundlePrice * (1M - discount);
            }

            var basket = new Basket(bundleRules);

            //Act
            foreach (var book in books)
            {
                basket.Add(book);
            }

            //Assert
            Assert.AreEqual(expected: books.Count, actual: basket.Items.Count);
            Assert.AreEqual(expected: expectedPrice, actual: basket.Total);
        }