Esempio n. 1
0
        public void Cart_With_MulipleTypeSkus_OneItemEach_FlatPrice_PromotionTest()
        {
            var cart     = new PR.Cart();
            var productA = new PR.Product(PR.SKUType.A, 50);
            var productB = new PR.Product(PR.SKUType.B, 30);
            var productC = new PR.Product(PR.SKUType.C, 20);

            //Add 1 A and 1 B and 1 C

            cart.AddItem(productA);
            cart.AddItem(productB);
            cart.AddItem(productC);


            var flatPriceRule1 = new PR.ProductPromoter(productA.SkuType, productA.Price, 3, 130, 1);
            var flatPriceRule2 = new PR.ProductPromoter(productB.SkuType, productB.Price, 2, 45, 1);
            var flatPriceRule3 = new PR.ProductPromoter(productC.SkuType, productC.Price, 1, 20, 1);

            var promoRuleList = new List <PR.ProductPromoter>();

            promoRuleList.Add(flatPriceRule1);
            promoRuleList.Add(flatPriceRule2);
            promoRuleList.Add(flatPriceRule3);


            PR.ProductPromotionStrategy promoRules = new PR.FlatPricePromotion(promoRuleList);
            cart.PromotionStrategy = promoRules;
            var totalPrice = cart.GetCartTotal();

            Assert.Equal(100, totalPrice);
        }
        public void OneTypeSkuFlatPricePromotionTest()
        {
            var cart    = new PR.Cart();
            var product = new PR.Product(PR.SKUType.A, 50);

            cart.AddItem(product);
            var flatPriceRule = new PR.ProductPromoter(product.SkuType, product.Price, 3, 130, 1);
            var promoRuleList = new List <PR.ProductPromoter>();

            promoRuleList.Add(flatPriceRule);

            //PR.IPromotion promotion = new PR.FlatPricePromotion(promoRuleList);
            PR.ProductPromotionStrategy promotion = new PR.FlatPricePromotion(promoRuleList);
            Assert.Equal(" 3 A(s) @ 130$", promotion.ToString());
        }
Esempio n. 3
0
        [Fact] //Scenario C
        public void Cart_With_MulipleTypeSkus_Combo_FlatPrice_PromotionTest()
        {
            var cart     = new PR.Cart();
            var productA = new PR.Product(PR.SKUType.A, 50);
            var productB = new PR.Product(PR.SKUType.B, 30);
            var productC = new PR.Product(PR.SKUType.C, 20);
            var productD = new PR.Product(PR.SKUType.D, 15);

            //Add 3 A
            for (int i = 0; i < 3; i++)
            {
                cart.AddItem(productA);
            }
            //Add  5 B
            for (int i = 0; i < 5; i++)
            {
                cart.AddItem(productB);
            }
            //Add 1 C
            cart.AddItem(productC);
            //Add 1 D
            cart.AddItem(productD);


            var flatPriceRule1 = new PR.ProductPromoter(productA.SkuType, productA.Price, 3, 130, 1);
            var flatPriceRule2 = new PR.ProductPromoter(productB.SkuType, productB.Price, 2, 45, 1);
            var flatPriceRule3 = new PR.ProductPromoter(productC.SkuType, productC.Price, 1, 15, 1);
            var flatPriceRule4 = new PR.ProductPromoter(productD.SkuType, productD.Price, 1, 15, 1);

            var promoRuleList = new List <PR.ProductPromoter>();

            promoRuleList.Add(flatPriceRule1);
            promoRuleList.Add(flatPriceRule2);
            promoRuleList.Add(flatPriceRule3);
            promoRuleList.Add(flatPriceRule4);


            PR.ProductPromotionStrategy promoRules = new PR.FlatPricePromotion(promoRuleList);
            cart.PromotionStrategy = promoRules;
            var totalPrice = cart.GetCartTotal();

            Assert.Equal(280, totalPrice);
        }
        public void Promotion_AddMultipleSkuTest()
        {
            var cart     = new PR.Cart();
            var productA = new PR.Product(PR.SKUType.A, 50);
            var productB = new PR.Product(PR.SKUType.B, 30);

            cart.AddItem(productA);
            for (int i = 0; i < 2; i++)
            {
                cart.AddItem(productB);
            }

            var flatPriceRule1 = new PR.ProductPromoter(productA.SkuType, productA.Price, 1, 50, 1);
            var flatPriceRule2 = new PR.ProductPromoter(productB.SkuType, productB.Price, 2, 30, 1);
            var promoRuleList  = new List <PR.ProductPromoter>();

            promoRuleList.Add(flatPriceRule1);
            promoRuleList.Add(flatPriceRule2);

            PR.ProductPromotionStrategy promotion = new PR.FlatPricePromotion(promoRuleList);
            Assert.Equal(" 1 A @ 50$ 2 B(s) @ 30$", promotion.ToString());
        }
Esempio n. 5
0
        public void Cart_With_OneTypeSkus_FlatPrice_PromotionTest()
        {
            var cart     = new PR.Cart();
            var productA = new PR.Product(PR.SKUType.A, 50);

            //Add 5 As
            for (int i = 0; i < 5; i++)
            {
                cart.AddItem(productA);
            }

            var flatPriceRule1 = new PR.ProductPromoter(productA.SkuType, productA.Price, 3, 130, 1);

            var promoRuleList = new List <PR.ProductPromoter>();

            promoRuleList.Add(flatPriceRule1);


            PR.ProductPromotionStrategy promoRules = new PR.FlatPricePromotion(promoRuleList);
            cart.PromotionStrategy = promoRules;
            var totalPrice = cart.GetCartTotal();

            Assert.Equal(230, totalPrice);
        }
        public void Promotion_CreateTest()
        {
            var promotion = new PR.FlatPricePromotion(null);

            Assert.IsAssignableFrom <PR.ProductPromotionStrategy>(promotion);
        }