Beispiel #1
0
            public IPromotionRule Create(PromotionRuleType type)
            {
                // Guarantee that the pricelist in the context contains the
                // sku(s) that is/are needed to activate the rule
                switch (type)
                {
                case PromotionRuleType.PairOfDifferentForFixedPrice:
                    return(new PairOfDifferentSkusForRule(this.testContext.CartFactory,
                                                          testContext.CreateNewSku(SkuAId, 100),
                                                          testContext.CreateNewSku(SkuBId, 200),
                                                          100));

                default:
                case PromotionRuleType.BatchOfSameForFixedPrice:
                    return(new CollectionOfSameSkuForRule(this.testContext.CartFactory,
                                                          testContext.CreateNewSku(SkuAId, 100), BatchOfSameForFixedPriceSize, 50));
                }
            }
Beispiel #2
0
            public ICart Create(PromotionRuleType type)
            {
                // Guarantee that the cart in the context contains the
                // sku(s) that is/are needed to activate the rule
                var cart = this.testContext.CartFactory.Create();

                switch (type)
                {
                case PromotionRuleType.PairOfDifferentForFixedPrice:
                    cart.Add(testContext.PriceList.First(entry => entry.Key.Id == PromotionRuleFactory.SkuAId).Key, 1);
                    cart.Add(testContext.PriceList.First(entry => entry.Key.Id == PromotionRuleFactory.SkuBId).Key, 1);
                    break;

                default:
                case PromotionRuleType.BatchOfSameForFixedPrice:
                    cart.Add(testContext.PriceList.First(entry => entry.Key.Id == PromotionRuleFactory.SkuAId).Key,
                             PromotionRuleFactory.BatchOfSameForFixedPriceSize);
                    break;
                }

                return(cart);
            }
Beispiel #3
0
        public void RulesApplicationGeneratesNonStrictlyMonotonicDescendingPriceTrend(PromotionRuleType type)
        {
            var testContext = new TestContext();

            IPromotionRule rule          = new PromotionRuleFactory(testContext).Create(type);
            ICart          cart          = new CartFactory(testContext).Create(type);
            decimal        originalPrice = cart.Total;

            ICart   newCart  = rule.Evaluate(cart);
            decimal newPrice = newCart.Total;

            Assert.True(newPrice <= originalPrice);
        }
Beispiel #4
0
        public void RulesApplicationChangesNothingWhenAllEntriesAreAlreadyMarkedAsHandled(PromotionRuleType type)
        {
            var testContext = new TestContext();

            IPromotionRule rule = new PromotionRuleFactory(testContext).Create(type);
            ICart          cart = new CartFactory(testContext).Create(type);

            var     invariantPromotionRule    = new InvariantPromotionRule(testContext.CartFactory);
            ICart   cartWithNoPromotableItems = invariantPromotionRule.Evaluate(cart);
            decimal originalPrice             = cartWithNoPromotableItems.Total;
            int     originalQuantity          = cartWithNoPromotableItems.Quantity;
            int     originalCount             = cartWithNoPromotableItems.Count;

            ICart   newCart     = rule.Evaluate(cartWithNoPromotableItems);
            decimal newPrice    = newCart.Total;
            int     newQuantity = newCart.Quantity;
            int     newCount    = newCart.Count;

            Assert.Equal(originalPrice, newPrice);
            Assert.Equal(originalQuantity, newQuantity);
            Assert.Equal(originalCount, newCount);
        }
Beispiel #5
0
        public void RulesApplicationGeneratesNonStrictlyMonotonicDescendingQuantityTrend(PromotionRuleType type)
        {
            var testContext = new TestContext();

            IPromotionRule rule             = new PromotionRuleFactory(testContext).Create(type);
            ICart          cart             = new CartFactory(testContext).Create(type);
            int            originalQuantity = cart.Quantity;

            ICart newCart     = rule.Evaluate(cart);
            int   newQuantity = newCart.Quantity;

            Assert.True(newQuantity <= originalQuantity);
        }