コード例 #1
0
        public void When_Buy1Book_Expect_ItsPrice()
        {
            IBasketCalculator calc = new InfrastructureLayer.BasketCalculators.BasketCalcTechRule();

            decimal price = calc.CalculateCatalogPrice(new List <Catalog>()
            {
                Book1
            });

            Assert.AreEqual(price, Book1.Price);
        }
コード例 #2
0
        public void When_BuyBooksInSameGroup_Expect_DiscountForTheFirstOnly()
        {
            IBasketCalculator calc = new InfrastructureLayer.BasketCalculators.BasketCalcTechRule();

            decimal price = calc.CalculateCatalogPrice(new List <Catalog>()
            {
                Book1, Book1, Book1,
                Book2, Book2
            });

            Assert.AreEqual(Book1.Price * 3 + Book2.Price * (1 - Book2.Category.Discount) + Book2.Price, price);
        }
コード例 #3
0
        public void When_BuyMoreThanAvaliableBooks_Expect_Exception()
        {
            IBasketCalculator calc = new InfrastructureLayer.BasketCalculators.BasketCalcTechRule();

            NotEnoughInventoryException exception = Assert.Throws <NotEnoughInventoryException>(() => calc.CalculateCatalogPrice(new List <Catalog>()
            {
                Book2, Book2, Book2
            }));

            Assert.AreEqual(Book2.Name, exception.Missing.First().Name);
            Assert.AreEqual(Book2.Quantity, exception.Missing.First().Quantity);
        }
コード例 #4
0
        public void When_BuyNullBooks_Expect_Exception()
        {
            IBasketCalculator calc = new InfrastructureLayer.BasketCalculators.BasketCalcTechRule();

            Assert.Throws <ArgumentOutOfRangeException>(() => calc.CalculateCatalogPrice(null));
        }