Exemple #1
0
        [InlineData(100, 200, 0, 3, 3)]   // No residuals
        public void CorrectTotalPriceWhenBatching(
            decimal basePrice1, decimal basePrice2,
            decimal batchPrice,
            int itemsNumberToAdd1, int itemsNumberToAdd2)
        {
            var testContext = new TestContext();

            int  batchesNumber      = Math.Min(itemsNumberToAdd1, itemsNumberToAdd2);
            int  residualsNumber    = Math.Max(itemsNumberToAdd1, itemsNumberToAdd2) - batchesNumber;
            bool residualsAreOfSku1 = itemsNumberToAdd1 - itemsNumberToAdd2 > 0;

            var sku1 = testContext.CreateNewSku("A", basePrice1);
            var sku2 = testContext.CreateNewSku("B", basePrice2);

            var cart = testContext.CartFactory.Create();

            cart.Add(sku1, itemsNumberToAdd1);
            cart.Add(sku2, itemsNumberToAdd2);
            Assert.Equal(itemsNumberToAdd1 + itemsNumberToAdd2, cart.Quantity);
            Assert.Equal(2, cart.Count());

            var rule    = new PairOfDifferentSkusForRule(testContext.CartFactory, sku1, sku2, batchPrice);
            var newCart = rule.Evaluate(cart);

            Assert.Equal(
                basePrice1 * residualsNumber * (residualsAreOfSku1 ? 1 : 0) +
                basePrice2 * residualsNumber * (residualsAreOfSku1 ? 0 : 1) +
                batchPrice * batchesNumber,
                newCart.Total);
        }
Exemple #2
0
        [InlineData(100, 200, 150, 2, 3)] // 1 residual
        public void WhenNotSameAmountOfBothSkuTypesThenSomeResidualsAreLeft(
            decimal basePrice1, decimal basePrice2,
            decimal batchPrice,
            int itemsNumberToAdd1, int itemsNumberToAdd2)
        {
            var testContext = new TestContext();

            if (itemsNumberToAdd1 == itemsNumberToAdd2)
            {
                throw new TestClassException("Invalid configuration");
            }

            int batchesNumber   = Math.Min(itemsNumberToAdd1, itemsNumberToAdd2);
            int residualsNumber = Math.Max(itemsNumberToAdd1, itemsNumberToAdd2) - batchesNumber;

            var sku1 = testContext.CreateNewSku("A", basePrice1);
            var sku2 = testContext.CreateNewSku("B", basePrice2);

            var cart = testContext.CartFactory.Create();

            cart.Add(sku1, itemsNumberToAdd1);
            cart.Add(sku2, itemsNumberToAdd2);
            Assert.Equal(itemsNumberToAdd1 + itemsNumberToAdd2, cart.Quantity);
            Assert.Equal(2, cart.Count());

            var rule    = new PairOfDifferentSkusForRule(testContext.CartFactory, sku1, sku2, batchPrice);
            var newCart = rule.Evaluate(cart);

            Assert.Equal(batchesNumber + residualsNumber, newCart.Quantity);

            Action <SkuCartEntry> batchChecker = entry =>
            {
                entry.CheckCartEntryWasProcessedByRule();
                Assert.Equal(1, entry.Quantity);
                Assert.Equal(batchPrice, entry.Price);
            };
            Action <SkuCartEntry> residualChecker = entry =>
            {
                entry.CheckCartEntryWasNotProcessedByRule();
                Assert.Equal(1, entry.Quantity);
                Assert.True(entry.Price == basePrice1 || entry.Price == basePrice2);
            };

            Assert.Collection(newCart,
                              Enumerable.Repeat(batchChecker, batchesNumber)
                              .Concat(Enumerable.Repeat(residualChecker, residualsNumber))
                              .ToArray());
        }
Exemple #3
0
        public void WhenOneAmountOfSkuBatchableTypesIsZeroThenNoBatchesAreCreated(
            decimal basePrice1, decimal basePrice2,
            decimal batchPrice,
            int itemsNumberToAdd1, int itemsNumberToAdd2)
        {
            var testContext = new TestContext();

            if (itemsNumberToAdd1 > 0 && itemsNumberToAdd2 > 0)
            {
                throw new TestClassException("Invalid configuration");
            }

            var sku1 = testContext.CreateNewSku("A", basePrice1);
            var sku2 = testContext.CreateNewSku("B", basePrice2);

            var cart = testContext.CartFactory.Create();

            if (itemsNumberToAdd1 > 0)
            {
                cart.Add(sku1, itemsNumberToAdd1);
            }
            if (itemsNumberToAdd2 > 0)
            {
                cart.Add(sku2, itemsNumberToAdd2);
            }
            Assert.Equal(itemsNumberToAdd1 + itemsNumberToAdd2, cart.Quantity);
            Assert.Single(cart);

            var rule    = new PairOfDifferentSkusForRule(testContext.CartFactory, sku1, sku2, batchPrice);
            var newCart = rule.Evaluate(cart);

            Assert.Equal(itemsNumberToAdd1 + itemsNumberToAdd2, newCart.Quantity);

            Action <SkuCartEntry> residualChecker = entry =>
            {
                entry.CheckCartEntryWasNotProcessedByRule();
                Assert.Equal(1, entry.Quantity);
                Assert.True(entry.Price == basePrice1 || entry.Price == basePrice2);
            };

            Assert.Collection(newCart, Enumerable.Repeat(residualChecker, itemsNumberToAdd1 + itemsNumberToAdd2)
                              .ToArray());
        }