Exemplo 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);
        }
Exemplo n.º 2
0
        [Fact] //Scenario A
        public void GetCartTotal_With_No_Promotion_Test()
        {
            //Arrange
            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);

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

            var noPromoRuleA  = new PR.ProductPromoter(productA.SkuType, productA.Price, 1, productA.Price, 1);
            var noPromoRuleA1 = new PR.ProductPromoter(productA.SkuType, productA.Price, 1, productA.Price, 1);
            var noPromoRuleB  = new PR.ProductPromoter(productB.SkuType, productB.Price, 1, productB.Price, 1);
            var noPromoRuleC  = new PR.ProductPromoter(productC.SkuType, productC.Price, 1, productC.Price, 1);

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

            promoRuleList.Add(noPromoRuleA);
            promoRuleList.Add(noPromoRuleA1);
            promoRuleList.Add(noPromoRuleB);
            promoRuleList.Add(noPromoRuleC);


            //PR.ProductPromotionStrategy promoRules = new PR.NoPromotion(promoRuleList);
            //cart.PromotionRules = promoRules;
            //Act
            double totalPrice = cart.GetCartTotal();

            //Assert
            Assert.IsAssignableFrom <PR.Cart>(cart);
            Assert.True(cart.Count == 3);
            Assert.Equal(100.0, totalPrice, 1);
        }
Exemplo n.º 3
0
        public override double CalculatePrice(int itemCount, ProductPromoter currentRule)
        {
            double price = 0.0;
            var    chunk = itemCount / currentRule.Count;

            price += chunk * currentRule.PromotionPrice + (itemCount - (currentRule.Count * chunk)) * currentRule.ProudctPrice;

            return(price);
        }
Exemplo n.º 4
0
        public void OneType_Sku_DiscountPrice_PromotionTest()
        {
            var cart     = new PR.Cart();
            var productA = new PR.Product(PR.SKUType.A, 50);

            cart.AddItem(productA);
            var discountPriceRule1 = new PR.ProductPromoter(productA.SkuType, productA.Price, 2, 50, 0.1);
            var promoRuleList      = new List <PR.ProductPromoter>();

            promoRuleList.Add(discountPriceRule1);

            PR.ProductPromotionStrategy promotion = new PR.DiscountedPricePromotion(promoRuleList);
            Assert.Equal(" 2 A(s) @ 10% OFF on Total Price", promotion.ToString());
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
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 abstract double CalculatePrice(int itemCount, ProductPromoter currentRule);
Exemplo n.º 10
0
 public override double CalculatePrice(int itemCount, ProductPromoter currentRule) => base.CalculatePrice(itemCount, currentRule);