示例#1
0
        static void Main(string[] args)
        {
            ShoppingCart cart1 = new ShoppingCart();

            //Case 1
            cart1.Add(new PercentOffOnNextItem(10));
            cart1.Add(new SaleableItem(10));
            cart1.Add(new SaleableItem(20));
            Console.WriteLine("Cart 1 Total:" + cart1.getTotal());

            ShoppingCart cart2 = new ShoppingCart();

            //Case 2
            cart2.Add(new SaleableItem(10));
            cart2.Add(new PercentOffOnNextItem(10));
            cart2.Add(new SaleableItem(20));
            Console.WriteLine("Cart 2 Total:" + cart2.getTotal());

            ShoppingCart cart3 = new ShoppingCart();

            //Case 3
            cart3.Add(new SaleableItem(10));
            cart3.Add(new FlatCoupon(2));
            cart3.Add(new DiscountInPercent(25));
            cart3.Add(new PercentOffOnNextItem(10));
            cart3.Add(new SaleableItem(10));


            Console.WriteLine("Cart 3 Total:" + cart3.getTotal());
            Console.ReadLine();
        }
        public void CalAmountTest_一二集各買了一本_第三集買了兩本_價格應為370()
        {
            //arrange
            ShoppingCart target = new ShoppingCart();
            target.Add(new ProductModel() { ID = 1, Price = 100m });
            target.Add(new ProductModel() { ID = 2, Price = 100m });
            target.Add(new ProductModel() { ID = 3, Price = 100m });
            target.Add(new ProductModel() { ID = 3, Price = 100m });
            decimal expected = 370;

            //act
            decimal actual;
            actual = target.CalAmount();

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void CalAmountTest_第一集買了一本_其他都沒買_價格應為100()
        {
            //arrange
            ShoppingCart target = new ShoppingCart();
            target.Add(new ProductModel() { ID = 1, Price = 100m });
            decimal expected = 100m;

            //act
            decimal actual;
            actual = target.CalAmount();

            //assert
            Assert.AreEqual(expected, actual);
        }