Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void Basket_With_Only_Copies_Of_Same_Roald_Dahl_Book_Costs_That_Of_Buying_As_Many_Single_Copies()
        {
            for (var i = 1; i <= 5; i++)
            {
                //Arrange
                var basket   = new Basket();
                var qtyToAdd = TestHelper.RandomInteger(1, 100);
                var book     = new Book(code: i);

                //Act
                basket.Add(item: book, qty: qtyToAdd);

                //Assert
                Assert.AreEqual(expected: qtyToAdd, actual: basket.Items.Count);
                Assert.AreEqual(expected: qtyToAdd * book.Price, actual: basket.Total);
            }
        }
Exemplo n.º 3
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);
        }