public void CalcDiscountService_TotalPrice_5PercentDiscount()
        {
            Product product = new Product()
            {
                Type = ProductType.Bicycle, Quantity = 5, UnitPrice = 1000.0M
            };

            ICalcService calcService = new CalcService(product);

            ICalcService calcDiscountService = new PriceCalcDiscountDecorator(calcService);
            decimal      totalPrice          = calcDiscountService.CalculatePrice();

            Assert.AreEqual(totalPrice, 4750);
        }
        public void CalcDiscountService_TotalPrice_10PercentDiscount_StateAL()
        {
            Product product = new Product()
            {
                Type = ProductType.Bicycle, Quantity = 10, UnitPrice = 1200.0M
            };
            string stateCode = State.AL.ToString();

            ICalcService calcService = new CalcService(product);

            ICalcService calcDiscountService = new PriceCalcDiscountDecorator(calcService);
            decimal      totalPrice          = calcDiscountService.CalculatePrice();

            ICalcService calcStateTaxService = new PriceCalcStateTaxDecorator(stateCode, calcDiscountService);

            totalPrice = calcStateTaxService.CalculatePrice();

            Assert.AreEqual(totalPrice, decimal.Parse("11232"));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            string stateCode;

            Product product = new Product();

            Console.WriteLine(string.Format("Enter no. of {0}:", ProductType.Bicycle));
            product.Quantity = int.Parse(Console.ReadLine());

            Console.WriteLine(string.Format("Enter Price/{0}:", ProductType.Bicycle));
            product.UnitPrice = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter State Code:");
            stateCode = Console.ReadLine();

            ICalcService calcService = new CalcService(product);

            Console.WriteLine("---------------------");

            //Total price after Discount
            ICalcService calcDiscountService = new PriceCalcDiscountDecorator(calcService);
            decimal      totalPrice          = calcDiscountService.CalculatePrice();

            Console.WriteLine("Total Price after discount: " + totalPrice);

            //Total price after Discount and State Tax
            ICalcService calcStateTaxService = new PriceCalcStateTaxDecorator(stateCode, calcDiscountService);

            totalPrice = calcStateTaxService.CalculatePrice();

            Console.WriteLine("Total Price after discount & Tax: " + totalPrice);

            Console.WriteLine("\nPress any key to Exit..");

            Console.ReadLine();
        }