Beispiel #1
0
        static void Run(ICart cart, IDeliveryCostCalculator deliveryCostCalculator)
        {
            ICategory categoryConsumerElectronics = new Category("Consumer Electronics");
            IProduct  productAppleWatch           = new Product(categoryConsumerElectronics, "Apple Watch", 2000.0);
            IProduct  productAppleMacbookPro      = new Product(categoryConsumerElectronics, "Apple Macbook Pro", 10000.0);

            ICategory categoryToysAndGames = new Category("Toys & Games");
            IProduct  productLego          = new Product(categoryToysAndGames, "Lego Classic Pack", 100.0);

            cart.Add(productAppleWatch, 2);
            cart.Add(productAppleMacbookPro, 1);
            cart.Add(productLego, 10);

            ICollection <ICampaign> campaigns = new Collection <ICampaign>();
            ICollection <ICoupon>   coupons   = new Collection <ICoupon>();

            IRateCampaign   inapplicableRateCampaign = new RateCampaign(categoryToysAndGames, "80% discount on Toys & Games category", .5, true, true, 50000.0, 20);
            IAmountCampaign lowAmountCampaign        = new AmountCampaign(categoryConsumerElectronics, "100 TL discount on Toys & Games category", 100, false, false, 0.0, 0);
            IAmountCampaign bestAmountCampaign       = new AmountCampaign(categoryConsumerElectronics, "1400 TL discount on Toys & Games category", 1400, false, true, 0.0, 3);
            IAmountCoupon   inapplicableAmountCoupon = new AmountCoupon(5000, "5000 TL discount coupon", true, true, 50000, 50);
            IRateCoupon     lowRateCoupon            = new RateCoupon(.1, "10% discount coupon", false, false, 0.0, 0);
            IRateCoupon     bestRateCoupon           = new RateCoupon(.5, "50% discount coupon", true, true, 10000, 13);

            campaigns.Add(inapplicableRateCampaign);
            campaigns.Add(lowAmountCampaign);
            campaigns.Add(bestAmountCampaign);
            coupons.Add(inapplicableAmountCoupon);
            coupons.Add(lowRateCoupon);
            coupons.Add(bestRateCoupon);

            cart.ApplyDiscounts(campaigns, coupons);

            cart.DeliveryCost = deliveryCostCalculator.Calculate(cart);

            var response = cart.Print();

            Console.Write(response);
        }
 public decimal GetDeliveryCost()
 {
     return(deliveryCostCalculator.Calculate(this));
 }