public void AbsoluteDiscountApplies()
        {
            var absoluteDiscount = new DiscountStub(4)
            {
                Discount = 10,
                Comment  = "Absolute discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { absoluteDiscount });

            CheckDiscounts(cart, new[] { 0, 0, 0.5M }, new[] { absoluteDiscount.Comment, absoluteDiscount.Comment, absoluteDiscount.Comment });
        }
        public void ThirtyOffWholeCatalogYieldsThirtyOffRebate()
        {
            var discount = new DiscountStub(4)
            {
                DiscountPercent = 30,
                Comment         = "30% off the whole catalog"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { discount });

            CheckDiscount(cart, 0.7M, discount.Comment);
        }
        public void RoleNotFoundDiscountDoesntApply()
        {
            var roleDiscount = new DiscountStub(4)
            {
                DiscountPercent = 10,
                Roles           = new[] { "Administrator", "Employee" },
                Comment         = "Role discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { roleDiscount });

            CheckDiscount(cart, 1, "");
        }
        public void RoleFoundDiscountApplies()
        {
            var roleDiscount = new DiscountStub(4)
            {
                DiscountPercent = 10,
                Roles           = new[] { "Employee", "Reseller" },
                Comment         = "Role discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { roleDiscount });

            CheckDiscount(cart, 0.9M, roleDiscount.Comment);
        }
        public void ExclusionPatternExcludesRightItems()
        {
            var patternDiscount = new DiscountStub(4)
            {
                DiscountPercent  = 10,
                ExclusionPattern = "foo",
                Comment          = "Pattern discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { patternDiscount });

            CheckDiscounts(cart, new[] { 1, 0.9M, 1 }, new[] { "", patternDiscount.Comment, "" });
        }
        public void PatternAppliesToRightItems()
        {
            var patternDiscount = new DiscountStub(4)
            {
                DiscountPercent = 10,
                Pattern         = "foo/ba",
                Comment         = "Pattern discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { patternDiscount });

            CheckDiscounts(cart, new[] { 0.9M, 1, 0.9M }, new[] { patternDiscount.Comment, "", patternDiscount.Comment });
        }
        public void CurrentlyValidDiscountApplies()
        {
            var currentDiscount = new DiscountStub(4)
            {
                DiscountPercent = 5,
                StartDate       = new DateTime(2012, 11, 24, 10, 0, 0, DateTimeKind.Utc),
                EndDate         = new DateTime(2012, 11, 24, 14, 0, 0, DateTimeKind.Utc),
                Comment         = "Currently valid discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { currentDiscount });

            CheckDiscount(cart, 0.95M, currentDiscount.Comment);
        }
        public void ExclusionPatternExcludesRightItemsAfterPatternHasIncluded()
        {
            var patternDiscount = new DiscountStub(4)
            {
                DiscountPercent  = 10,
                Pattern          = "bar",
                ExclusionPattern = "baz",
                Comment          = "Pattern discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { patternDiscount });

            CheckDiscounts(cart, new[] { 0.9M, 1, 1 }, new[] { patternDiscount.Comment, "", "" });
        }
        public void QuantityDiscountAppliesToRightItems()
        {
            var selectiveDiscount = new DiscountStub(4)
            {
                DiscountPercent = 10,
                StartQuantity   = 4,
                EndQuantity     = 6,
                Comment         = "4-5 item discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { selectiveDiscount });

            CheckDiscounts(cart, new[] { 1, 0.9M, 0.9M }, new[] { "", selectiveDiscount.Comment, selectiveDiscount.Comment });
        }
        public void WideEnoughQuantityDiscountApplies()
        {
            var wideEnoughDiscount = new DiscountStub(4)
            {
                DiscountPercent = 10,
                StartQuantity   = 3,
                EndQuantity     = 6,
                Comment         = "Wide enough discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { wideEnoughDiscount });

            CheckDiscount(cart, 0.9M, wideEnoughDiscount.Comment);
        }
        public void TooLowAndTooHighQuantityDiscountDoesNotApply()
        {
            var tooLowDiscount = new DiscountStub(4)
            {
                DiscountPercent = 5,
                StartQuantity   = 1,
                EndQuantity     = 2,
                Comment         = "Too low discount"
            };
            var tooHighDiscount = new DiscountStub(5)
            {
                DiscountPercent = 5,
                StartQuantity   = 7,
                EndQuantity     = 10,
                Comment         = "Too high discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { tooLowDiscount, tooHighDiscount });

            CheckDiscount(cart, 1, "");
        }
        public void OldAndFutureDiscountsDontApply()
        {
            var oldDiscount = new DiscountStub(4)
            {
                DiscountPercent = 5,
                StartDate       = new DateTime(2012, 11, 1, 12, 0, 0, DateTimeKind.Utc),
                EndDate         = new DateTime(2012, 11, 2, 12, 0, 0, DateTimeKind.Utc),
                Comment         = "Old discount"
            };
            var futureDiscount = new DiscountStub(5)
            {
                DiscountPercent = 5,
                StartDate       = new DateTime(2012, 12, 24, 12, 0, 0, DateTimeKind.Utc),
                EndDate         = new DateTime(2012, 12, 25, 12, 0, 0, DateTimeKind.Utc),
                Comment         = "Future discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { oldDiscount, futureDiscount });

            CheckDiscount(cart, 1, "");
        }
        public void LowestPriceWins()
        {
            var mediocreDiscount = new DiscountStub(4)
            {
                DiscountPercent = 5,
                Comment         = "Mediocre discount"
            };
            var betterDiscount = new DiscountStub(5)
            {
                DiscountPercent = 10,
                Comment         = "Better discount"
            };
            var bestDiscount = new DiscountStub(6)
            {
                DiscountPercent = 20,
                Comment         = "Best discount"
            };
            var cart = ShoppingCartHelpers.PrepareCart(new[] { mediocreDiscount, bestDiscount, betterDiscount });

            CheckDiscount(cart, 0.8M, bestDiscount.Comment);
        }