Beispiel #1
0
        public void Basket_when1GiftVoucherAnd1OfferVoucherIsApplied_return_Total()
        {
            Cart         cart         = new Cart();
            Product      product1     = cart.Add(new Product("Hat", 25.00), 1);
            Product      product2     = cart.Add(new Product("Jumper", 26.00), 1);
            GiftVoucher  giftVoucher  = new GiftVoucher("XXX-XXX", 5.00);
            OfferVoucher offerVoucher = new OfferVoucher("YYY-YYY", 5.00, 50.00);
            Basket       basket       = new Basket(cart);

            basket.AddVoucher(giftVoucher);
            basket.AddVoucher(offerVoucher);
            bool IsCodeValid1 = basket.ApplyVoucher("XXX-XXX");
            bool IsCodeValid2 = basket.ApplyVoucher("YYY-YYY");

            Assert.AreEqual(41.00, basket.Total);
        }
Beispiel #2
0
        public void Basket_whenOfferVoucherIsAppliedAndTreshholdreached_return_Total()
        {
            Cart    cart     = new Cart();
            Product product1 = cart.Add(new Product("Hat", 25.00), 1);
            Product product2 = cart.Add(new Product("£30 Gift Voucher", 30.00), 1);

            product2.BlockVouchers = true;
            OfferVoucher offerVoucher = new OfferVoucher("YYY-YYY", 5.00, 50.00);
            Basket       basket       = new Basket(cart);

            basket.AddVoucher(offerVoucher);
            double thresholdReached = basket.ThresholdReached;

            Assert.AreEqual(55.00, basket.Total);
            thresholdReached.Should().Equals(25.01);
            // .BeTrue("You have not reached the spend threshold for voucher YYY-YYY. Spend another £25.01 to receive £5.00 discount from your basket total.");
        }
        public void AddVoucher_DelegatesToValidator()
        {
            var discountToAddMock        = new Mock <IMayApplyDiscount>();
            var expectedValidationResult = DiscountApplicationResult.CreateSuccess();

            _discountValidatorMock
            .Setup(x => x.CanApplyDiscount(It.IsAny <IEnumerable <IMayApplyDiscount> >(), discountToAddMock.Object))
            .Returns(expectedValidationResult)
            .Verifiable();

            var basket = new Basket(_discountValidatorMock.Object);

            var applicationResult = basket.AddVoucher(discountToAddMock.Object);

            Assert.Equal(expectedValidationResult, applicationResult);
            _discountValidatorMock.Verify(x => x.CanApplyDiscount(It.IsAny <IEnumerable <IMayApplyDiscount> >(), discountToAddMock.Object), Times.Once);
        }
        public void Basket_CalulatesWithoutVoucherForTooLargeDiscount()
        {
            var testProduct = new Product("Hat", 10.50m);
            var testVoucher = new GiftVoucher(15m);

            _basket.AddProduct(testProduct);
            _basket.AddVoucher(testVoucher);

            _basket.Total().Should().Be(10.50m);
        }
        public void Basket_AcceptsGiftVoucher()
        {
            var testProduct = new Product("Hat", 10m);
            var testVoucher = new GiftVoucher(5m);

            _sut.AddProduct(testProduct);
            _sut.AddVoucher(testVoucher);

            _sut.Vouchers.Should().HaveCount(1);
            _sut.Vouchers.Single().Should().Be(testVoucher);
        }