Exemplo n.º 1
0
        public void Test_PromoHit_A_OneTime()
        {
            List <CartItem> shoppingCart = new List <CartItem> {
                new CartItem {
                    Key = "A", Count = 3
                },
                new CartItem {
                    Key = "B", Count = 0
                },
                new CartItem {
                    Key = "C", Count = 0
                },
                new CartItem {
                    Key = "D", Count = 0
                }
            };

            var log = new PromoEngineEventLogTrace(shoppingCart);

            promotionRuleEngine.Process(shoppingCart, log.HandlePromoDiscount, log.CalculateTotal);

            Assert.True(log.Details.Values.Where(x => x.Item1 == A3).Any());
            Assert.Single(log.Details);
            Assert.Equal(Pricing.PromoPrice(A3), log.TotalAmount);
        }
Exemplo n.º 2
0
        public void Test_PromoHit_A1Time_B2Time()
        {
            List <CartItem> shoppingCart = new List <CartItem> {
                new CartItem {
                    Key = "A", Count = 3
                },
                new CartItem {
                    Key = "B", Count = 5
                },
                new CartItem {
                    Key = "C", Count = 0
                },
                new CartItem {
                    Key = "D", Count = 0
                }
            };

            var log = new PromoEngineEventLogTrace(shoppingCart);

            promotionRuleEngine.Process(shoppingCart, log.HandlePromoDiscount, log.CalculateTotal);

            Assert.True(log.Details.Values.Where(x => x.Item1 == A3).Count() == 1);
            Assert.True(log.Details.Values.Where(x => x.Item1 == B2).Count() == 2);

            Assert.Equal(3, log.Details.Count);
            Assert.Equal(1 * Pricing.PromoPrice(A3) + 2 * Pricing.PromoPrice(B2) + Pricing.Price("B"), log.TotalAmount);
        }
Exemplo n.º 3
0
        public void Test_PromoHit_CD_10Time()
        {
            List <CartItem> shoppingCart = new List <CartItem> {
                new CartItem {
                    Key = "A", Count = 0
                },
                new CartItem {
                    Key = "B", Count = 0
                },
                new CartItem {
                    Key = "C", Count = 15
                },
                new CartItem {
                    Key = "D", Count = 10
                }
            };

            var log = new PromoEngineEventLogTrace(shoppingCart);

            promotionRuleEngine.Process(shoppingCart, log.HandlePromoDiscount, log.CalculateTotal);

            Assert.True(log.Details.Values.Where(x => x.Item1 == C1D1).Count() == 10);
            Assert.Equal(10, log.Details.Count);
            Assert.Equal(10 * Pricing.PromoPrice(C1D1) + 5 * Pricing.Price("C"), log.TotalAmount);
        }
Exemplo n.º 4
0
        public void Test_No_PromoHit()
        {
            List <CartItem> shoppingCart = new List <CartItem> {
                new CartItem {
                    Key = "A", Count = 1
                },
                new CartItem {
                    Key = "B", Count = 1
                },
                new CartItem {
                    Key = "C", Count = 1
                },
                new CartItem {
                    Key = "D", Count = 0
                }
            };

            var log = new PromoEngineEventLogTrace(shoppingCart);

            promotionRuleEngine.Process(shoppingCart, log.HandlePromoDiscount, log.CalculateTotal);

            Assert.Empty(log.Details);
            Assert.Equal(Pricing.Price("A") + Pricing.Price("B") + Pricing.Price("C"), log.TotalAmount);
        }