Beispiel #1
0
        public void Basket3Scenario()
        {
            // Arrange
            var cartManager    = new CartManager();
            var cartItem1      = new ShoppingCartItem(new Product(ProductCategory.Hat, "Hat"), 1, 25.00M);
            var cartItem2      = new ShoppingCartItem(new Product(ProductCategory.Jumper, "Jumper"), 1, 26.00M);
            var cartItem3      = new ShoppingCartItem(new Product(ProductCategory.HeadGear, "Head Light"), 1, 3.50M);
            var voucherFactory = new VoucherFactory();
            var offerVoucher5PoundsOffBasketsOver50PoundsHeadGearOnly = voucherFactory.Create(VoucherFactoryType.OfferVoucher5PoundsOffBasketsOver50PoundsHeadGearOnly, "YYY-YYY", "£5.00 off Head Gear in baskets over £50.00 Offer Voucher");

            // Act
            cartManager.AddItem(cartItem1);
            cartManager.AddItem(cartItem2);
            cartManager.AddItem(cartItem3);
            cartManager.ApplyVoucher(offerVoucher5PoundsOffBasketsOver50PoundsHeadGearOnly);

            // Assert
            cartManager.Cart.CartItems.Should().HaveCount(3);
            cartManager.Cart.CartItems.Should().Contain(cartItem1);
            cartManager.Cart.CartItems.Should().Contain(cartItem2);
            cartManager.Cart.CartItems.Should().Contain(cartItem3);
            cartManager.Cart.CartNonDiscountedPrice.Should().Be(54.50M);
            cartManager.Cart.CartDiscountValue.Should().Be(3.50M);
            cartManager.Cart.CartDiscountedPrice.Should().Be(51.00M);
            cartManager.Cart.ContainsOfferVoucher().Should().BeTrue();
            cartManager.Cart.ContainsGiftVoucher().Should().BeFalse();
            cartManager.Cart.ContainsGiftVoucherProducts().Should().BeFalse();
        }
Beispiel #2
0
        public void Basket4Scenario()
        {
            // Arrange
            var cartManager           = new CartManager();
            var cartItem1             = new ShoppingCartItem(new Product(ProductCategory.Hat, "Hat"), 1, 25.00M);
            var cartItem2             = new ShoppingCartItem(new Product(ProductCategory.Jumper, "Jumper"), 1, 26.00M);
            var voucherFactory        = new VoucherFactory();
            var giftVoucher5PoundsOff = voucherFactory.Create(VoucherFactoryType.GiftVoucher5PoundsOff, "XXX-XXX", "£5.00 Gift Voucher");
            var offerVoucher5PoundsOffBasketsOver50Pounds = voucherFactory.Create(VoucherFactoryType.OfferVoucher5PoundsOffBasketsOver50Pounds, "YYY-YYY", "£5.00 off baskets over £50.00 Offer Voucher");

            // Act
            cartManager.AddItem(cartItem1);
            cartManager.AddItem(cartItem2);
            cartManager.ApplyVoucher(giftVoucher5PoundsOff);
            cartManager.ApplyVoucher(offerVoucher5PoundsOffBasketsOver50Pounds);

            // Assert
            cartManager.Cart.CartItems.Should().HaveCount(2);
            cartManager.Cart.CartItems.Should().Contain(cartItem1);
            cartManager.Cart.CartItems.Should().Contain(cartItem2);
            cartManager.Cart.CartNonDiscountedPrice.Should().Be(51.00M);
            cartManager.Cart.CartDiscountValue.Should().Be(10.00M);
            cartManager.Cart.CartDiscountedPrice.Should().Be(41.00M);
            cartManager.Cart.ContainsOfferVoucher().Should().BeTrue();
            cartManager.Cart.ContainsGiftVoucher().Should().BeTrue();
            cartManager.Cart.ContainsGiftVoucherProducts().Should().BeFalse();
        }
Beispiel #3
0
        public void Basket1Scenario()
        {
            // Arrange
            var cartManager           = new CartManager();
            var cartItem1             = new ShoppingCartItem(new Product(ProductCategory.Hat, "Hat"), 1, 10.50M);
            var cartItem2             = new ShoppingCartItem(new Product(ProductCategory.Jumper, "Jumper"), 1, 54.65M);
            var voucherFactory        = new VoucherFactory();
            var giftVoucher5PoundsOff = voucherFactory.Create(VoucherFactoryType.GiftVoucher5PoundsOff, "XXX-XXX", "£5.00 Gift Voucher");

            // Act
            cartManager.AddItem(cartItem1);
            cartManager.AddItem(cartItem2);
            cartManager.ApplyVoucher(giftVoucher5PoundsOff);

            // Assert
            cartManager.Cart.CartItems.Should().HaveCount(2);
            cartManager.Cart.CartItems.Should().Contain(cartItem1);
            cartManager.Cart.CartItems.Should().Contain(cartItem2);
            cartManager.Cart.CartNonDiscountedPrice.Should().Be(65.15M);
            cartManager.Cart.CartDiscountValue.Should().Be(5.00M);
            cartManager.Cart.CartDiscountedPrice.Should().Be(60.15M);
            cartManager.Cart.ContainsOfferVoucher().Should().BeFalse();
            cartManager.Cart.ContainsGiftVoucher().Should().BeTrue();
            cartManager.Cart.ContainsGiftVoucherProducts().Should().BeFalse();
        }
Beispiel #4
0
        public void Basket5Scenario()
        {
            // Arrange
            var cartManager    = new CartManager();
            var cartItem1      = new ShoppingCartItem(new Product(ProductCategory.Hat, "Hat"), 1, 25.00M);
            var cartItem2      = new ShoppingCartItem(new Product(ProductCategory.GiftVoucher, "£30 Gift Voucher"), 1, 30.00M);
            var voucherFactory = new VoucherFactory();
            var offerVoucher5PoundsOffBasketsOver50Pounds = voucherFactory.Create(VoucherFactoryType.OfferVoucher5PoundsOffBasketsOver50Pounds, "YYY-YYY", "£5 Off Baskets Over £50.00 Voucher");

            // Act
            cartManager.AddItem(cartItem1);
            cartManager.AddItem(cartItem2);
            cartManager.ApplyVoucher(offerVoucher5PoundsOffBasketsOver50Pounds);

            // Assert
            cartManager.Cart.CartItems.Should().HaveCount(2);
            cartManager.Cart.CartItems.Should().Contain(cartItem1);
            cartManager.Cart.CartItems.Should().Contain(cartItem2);
            cartManager.Cart.CartNonDiscountedPrice.Should().Be(55.00M);
            cartManager.Cart.CartDiscountValue.Should().Be(0.00M);
            cartManager.Cart.CartDiscountedPrice.Should().Be(55.00M);
            cartManager.Cart.ContainsOfferVoucher().Should().BeFalse();
            cartManager.Cart.ContainsGiftVoucher().Should().BeFalse();
            cartManager.Cart.ContainsGiftVoucherProducts().Should().BeTrue();
            cartManager.Cart.Message.Should().Be("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 NonImplementedVoucherFactoryTypeRaisesException()
        {
            // Arrange
            var    factory = new VoucherFactory();
            Action action  = () => factory.Create(VoucherFactoryType.GiftVoucher10PoundsOff, string.Empty, String.Empty);

            // Assert
            Assert.Throws <InvalidVoucherFactoryTypeException>(action.Invoke);
        }
        //This would be some ORM (likely dapper) to access gift vouchers stored in a DB
        //For the purposes of this task, I have just stubbed what I would expect
        public List <GiftVoucher> GetAllAvailableGiftVouchers()
        {
            VoucherFactory voucherFactory = new VoucherFactory();

            return(new List <GiftVoucher>()
            {
                (GiftVoucher)voucherFactory.GenerateVoucher(VouchersEnum.Gift_5PoundOff)
            });
        }
        //This would be some ORM (likely dapper) to access gift vouchers stored in a DB
        //For the purposes of this task, I have just stubbed what I would expect
        public List <OfferVoucher> GetAllAvailableOfferVouchers()
        {
            VoucherFactory voucherFactory = new VoucherFactory();

            return(new List <OfferVoucher>()
            {
                (OfferVoucher)voucherFactory.GenerateVoucher(VouchersEnum.Offer_5PoundOffHeadgear_Threshold50),
                (OfferVoucher)voucherFactory.GenerateVoucher(VouchersEnum.Offer_5PoundOff_Threshold50)
            });
        }
        public void OfferVoucher5PoundsOffBasketsOver50PoundsHeadGearOnlyIsCreated()
        {
            // Arrange
            var factory = new VoucherFactory();

            // Act
            var voucherCreated = factory.Create(VoucherFactoryType.OfferVoucher5PoundsOffBasketsOver50PoundsHeadGearOnly, string.Empty, String.Empty);

            // Assert
            voucherCreated.Should().BeOfType <OfferVoucher>();
            ((OfferVoucher)voucherCreated).Value.Should().Be(5.00M);
        }
        public void GiftVoucher5PoundsOffIsCreated()
        {
            // Arrange
            var factory = new VoucherFactory();

            // Act
            var voucherCreated = factory.Create(VoucherFactoryType.GiftVoucher5PoundsOff, string.Empty, String.Empty);

            // Assert
            voucherCreated.Should().BeOfType <GiftVoucher>();
            ((GiftVoucher)voucherCreated).Value.Should().Be(5.00M);
        }
Beispiel #10
0
        public CartManager Basket1()
        {
            var cartManager           = new CartManager();
            var cartItem1             = new ShoppingCartItem(new Product(ProductCategory.Hat, "Hat"), 1, 10.50M);
            var cartItem2             = new ShoppingCartItem(new Product(ProductCategory.Jumper, "Jumper"), 1, 54.65M);
            var voucherFactory        = new VoucherFactory();
            var giftVoucher5PoundsOff = voucherFactory.Create(VoucherFactoryType.GiftVoucher5PoundsOff, "XXX-XXX", "£5.00 Gift Voucher");

            cartManager.AddItem(cartItem1);
            cartManager.AddItem(cartItem2);
            cartManager.ApplyVoucher(giftVoucher5PoundsOff);

            return(cartManager);
        }
Beispiel #11
0
        public CartManager Basket5()
        {
            var cartManager    = new CartManager();
            var cartItem1      = new ShoppingCartItem(new Product(ProductCategory.Hat, "Hat"), 1, 25.00M);
            var cartItem2      = new ShoppingCartItem(new Product(ProductCategory.GiftVoucher, "£30 Gift Voucher"), 1, 30.00M);
            var voucherFactory = new VoucherFactory();
            var offerVoucher5PoundsOffBasketsOver50Pounds = voucherFactory.Create(VoucherFactoryType.OfferVoucher5PoundsOffBasketsOver50Pounds, "YYY-YYY", "£5 Off Baskets Over £50.00 Voucher");

            cartManager.AddItem(cartItem1);
            cartManager.AddItem(cartItem2);
            cartManager.ApplyVoucher(offerVoucher5PoundsOffBasketsOver50Pounds);

            return(cartManager);
        }
Beispiel #12
0
        public CartManager Basket2()
        {
            var cartManager    = new CartManager();
            var cartItem1      = new ShoppingCartItem(new Product(ProductCategory.Hat, "Hat"), 1, 25.00M);
            var cartItem2      = new ShoppingCartItem(new Product(ProductCategory.Jumper, "Jumper"), 1, 26.00M);
            var voucherFactory = new VoucherFactory();
            var offerVoucher5PoundsOffBasketsOver50PoundsHeadGearOnly = voucherFactory.Create(VoucherFactoryType.OfferVoucher5PoundsOffBasketsOver50PoundsHeadGearOnly, "YYY-YYY", "£5.00 off Head Gear in baskets over £50.00 Offer Voucher");

            cartManager.AddItem(cartItem1);
            cartManager.AddItem(cartItem2);
            cartManager.ApplyVoucher(offerVoucher5PoundsOffBasketsOver50PoundsHeadGearOnly);

            return(cartManager);
        }
Beispiel #13
0
        public CartManager Basket4()
        {
            var cartManager           = new CartManager();
            var cartItem1             = new ShoppingCartItem(new Product(ProductCategory.Hat, "Hat"), 1, 25.00M);
            var cartItem2             = new ShoppingCartItem(new Product(ProductCategory.Jumper, "Jumper"), 1, 26.00M);
            var voucherFactory        = new VoucherFactory();
            var giftVoucher5PoundsOff = voucherFactory.Create(VoucherFactoryType.GiftVoucher5PoundsOff, "XXX-XXX", "£5.00 Gift Voucher");
            var offerVoucher5PoundsOffBasketsOver50Pounds = voucherFactory.Create(VoucherFactoryType.OfferVoucher5PoundsOffBasketsOver50Pounds, "YYY-YYY", "£5.00 off baskets over £50.00 Offer Voucher");

            cartManager.AddItem(cartItem1);
            cartManager.AddItem(cartItem2);
            cartManager.ApplyVoucher(giftVoucher5PoundsOff);
            cartManager.ApplyVoucher(offerVoucher5PoundsOffBasketsOver50Pounds);

            return(cartManager);
        }
Beispiel #14
0
 public void Setup()
 {
     _basketCalculator = new BasketCalculator();
     _prodFactory      = new ProductFactory();
     _vouchFactory     = new VoucherFactory();
 }