コード例 #1
0
        public void CalcDiscountServiceNullValueCheck_NotNull()
        {
            Product product = new Product()
            {
                Type = ProductType.Bicycle, Quantity = 3, UnitPrice = 500.0M
            };

            ICalcService calcService         = new CalcService(product);
            ICalcService calcDiscountService = new PriceCalcDiscountDecorator(calcService);

            Assert.IsNotNull(calcDiscountService);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: SreeniC/PriceCalcService
        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();
        }