コード例 #1
0
        public void Test_Basket6()
        {
            // Arrage
            var shoppingBasket = new BLL.ShoppingBasket
            {
                BogofOffers = new List <BogofOffer>
                {
                    _bogoOfferRepository.GetBogofOffer(1)
                },
                OfferVoucher = _offerVoucherRepository.GetOffVoucher(2),
                LoyaltyOffer = _loyaltyOfferRepository.GetLoyaltyOffer(1)
            };

            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(10));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(10));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(10));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(9));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(9));

            var basketService = new BasketService(_basketProcessorFactory);

            // Act
            var basketServiceResponse = basketService.GetBasketTotal(shoppingBasket);

            // Assert
            Assert.AreEqual(35.28, basketServiceResponse.BasketTotal);
            Assert.AreEqual(3, basketServiceResponse.Notifications.Count);
        }
コード例 #2
0
        public void Test_Basket3()
        {
            // Arrage
            var shoppingBasket = new BLL.ShoppingBasket
            {
                BogofOffers = new List <BogofOffer>
                {
                    _bogoOfferRepository.GetBogofOffer(1)
                }
            };

            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(2));

            var basketService = new BasketService(_basketProcessorFactory);

            // Act
            var basketServiceResponse = basketService.GetBasketTotal(shoppingBasket);

            // Assert
            Assert.AreEqual(75.65, basketServiceResponse.BasketTotal);
            Assert.AreEqual(1, basketServiceResponse.Notifications.Count);
        }
コード例 #3
0
        public void Test_ShoppingBasket_AddItemToBasket()
        {
            // Arrange
            IShoppingBasket shoppingBasket = new BLL.ShoppingBasket();

            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(2));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(3));

            // Act
            var itemsCount = shoppingBasket.GetBasketItems().Count();

            // Assert
            Assert.AreEqual(3, itemsCount);
        }
コード例 #4
0
        public void Basket2()
        {
            // arrage
            var shoppingBasket = new BLL.ShoppingBasket
            {
                OfferVoucher = _offerVoucherRepository.GetOffVoucher(1)
            };

            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(3));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(4));
            var basetService = new BasketService(_basketProcessorFactory);

            // act
            var basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            // assert
            Assert.AreEqual(51.00, basketServiceResponse.BasketTotal);
            Assert.AreEqual(1, basketServiceResponse.Notifications.Count);
            Assert.AreEqual("There are no products in your basket applicable to voucher Voucher YYY-YYY.", basketServiceResponse.Notifications[0]);
        }
コード例 #5
0
        public void Basket5()
        {
            // arrage
            var shoppingBasket = new BLL.ShoppingBasket
            {
                OfferVoucher = _offerVoucherRepository.GetOffVoucher(2)
            };

            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(3));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(6));
            var basetService = new BasketService(_basketProcessorFactory);

            // act
            var basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            // assert
            Assert.AreEqual(55.00, basketServiceResponse.BasketTotal);
            Assert.AreEqual(1, basketServiceResponse.Notifications.Count);
            Assert.AreEqual("You have not reached the spend threshold for voucher YYY-YYY. Spend another £25.01 to receive £5.00 discount from your basket total.", basketServiceResponse.Notifications[0]);
        }
コード例 #6
0
        public void Basket3()
        {
            // arrage
            var shoppingBasket = new BLL.ShoppingBasket
            {
                OfferVoucher = _offerVoucherRepository.GetOffVoucher(1)
            };

            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(3));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(4));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(5));

            var basetService = new BasketService(_basketProcessorFactory);

            // act
            var basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            // assert
            Assert.AreEqual(51.00, basketServiceResponse.BasketTotal);
            Assert.AreEqual(0, basketServiceResponse.Notifications.Count);
        }
コード例 #7
0
        public void Basket1()
        {
            // arrage
            var shoppingBasket = new BLL.ShoppingBasket
            {
                GiftVouchers = new List <GiftVoucher>
                {
                    _giftVoucherRepository.GetGiftVoucher(1)
                }
            };

            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(2));
            var basetService = new BasketService(_basketProcessorFactory);

            // act
            var basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            // assert
            Assert.AreEqual(60.15, basketServiceResponse.BasketTotal);
            Assert.AreEqual(0, basketServiceResponse.Notifications.Count);
        }
コード例 #8
0
        public void Test_Verify_BasketTotal_After_Calling_BogofOfferProcessor_For_Basket1()
        {
            // Arrange
            var shoppingBasket = new BLL.ShoppingBasket
            {
                BogofOffers = new List <BogofOffer>
                {
                    _bogoOfferRepository.GetBogofOffer(3)
                }
            };

            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(7));
            shoppingBasket.AddtemToBasket(_productRepository.GetProduct(2));

            // Act
            var basketProcessor = new BogofOfferProcessor();

            shoppingBasket.Total = 65.15m;
            basketProcessor.Process(shoppingBasket);

            // Assert
            Assert.AreEqual(65.15m, shoppingBasket.Total);
        }
コード例 #9
0
        public static void Main(string[] args)
        {
            IProductRepository      productRepository      = new ProductRepository();
            IBogoOfferRepository    bogoOfferRepository    = new BogoOfferRepository();
            IOfferVoucherRepository offerVoucherRepository = new OfferVoucherRepository();
            ILoyaltyOfferRepository loyaltyOfferRepository = new LoyaltyOfferRepository();

            ConsoleSetup(0);
            // Basket 0: Empty Shopping Basket
            var shoppingBasket = new BLL.ShoppingBasket();

            IBasketProcessorFactory basketProcessorFactory = new BasketProcessorFactory();
            var basketService         = new BasketService(basketProcessorFactory);
            var basketServiceResponse = basketService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket0 - Total : £{basketServiceResponse.BasketTotal}");
            Console.WriteLine($"Basket0 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}");

            ConsoleSetup(1);

            /* Basket 1:
             * 1 Hat @ 10.50
             * 1 Jumper @ 54.65
             * BOGOF offer on Product Category:Hats
             * Total: £65.15
             */
            shoppingBasket = new BLL.ShoppingBasket
            {
                BogofOffers = new List <BogofOffer>
                {
                    bogoOfferRepository.GetBogofOffer(1)
                }
            };
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(2));

            basketService         = new BasketService(basketProcessorFactory);
            basketServiceResponse = basketService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket1 - Total : £{basketServiceResponse.BasketTotal}");


            ConsoleSetup(2);

            /* Basket 2:
             * 2 Hat @ 10.50
             * 1 Jumper @ 54.65
             * BOGOF offer on Product Category:Hats
             * Total: £65.15
             * Message: BOGOF discount £10.50 applied
             */
            shoppingBasket = new BLL.ShoppingBasket
            {
                BogofOffers = new List <BogofOffer>
                {
                    bogoOfferRepository.GetBogofOffer(1)
                }
            };
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(2));

            basketService         = new BasketService(basketProcessorFactory);
            basketServiceResponse = basketService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket2 - Total : £{basketServiceResponse.BasketTotal}");
            Console.WriteLine($"Basket2 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}");

            ConsoleSetup(3);

            /* Basket 3:
             * 3 Hat @ 10.50
             * 1 Jumper @ 54.65
             * BOGOF offer on Product Category:Hats
             * Total: £75.65
             * Message: BOGOF discount £10.50 applied
             */
            shoppingBasket = new BLL.ShoppingBasket
            {
                BogofOffers = new List <BogofOffer>
                {
                    bogoOfferRepository.GetBogofOffer(1)
                }
            };
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(2));

            basketService         = new BasketService(basketProcessorFactory);
            basketServiceResponse = basketService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket3 - Total : £{basketServiceResponse.BasketTotal}");
            foreach (var notification in basketServiceResponse.Notifications)
            {
                Console.WriteLine($"Basket3 - Message:{notification}");
            }

            ConsoleSetup(4);

            /* Basket 4:
             * 2 Hat @ 4.65
             * 1 Jumper @ 14.45
             * BOGOF offer on Product Category:Hats
             * 10% off on totals greater than £20 (after BOGOF)
             * Total: £19.10
             * Message: BOGOF discount £4.65 applied
             * Message: “You have not reached the spend threshold for voucher YYY-YYY. Spend another £0.91 or more to receive 10% off your basket total.”
             */
            shoppingBasket = new BLL.ShoppingBasket
            {
                BogofOffers = new List <BogofOffer>
                {
                    bogoOfferRepository.GetBogofOffer(1)
                },
                OfferVoucher = offerVoucherRepository.GetOffVoucher(2)
            };
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(3));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(3));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(4));

            basketService         = new BasketService(basketProcessorFactory);
            basketServiceResponse = basketService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket4 - Total : £{basketServiceResponse.BasketTotal}");
            foreach (var notification in basketServiceResponse.Notifications)
            {
                Console.WriteLine($"Basket4 - Message:{notification}");
            }

            ConsoleSetup(5);

            /* Basket 5:
             * 2 Hat @ 6.70
             * 2 Jumper @ 12.65
             * BOGOF offer on Product Category:Hats
             * 10% off on totals greater than £20 (after BOGOF) Applied
             * Total: £28.80
             * Message: BOGOF discount £6.70 applied
             * Message: OfferVoucher discount £3.20 applied.
             */
            shoppingBasket = new BLL.ShoppingBasket
            {
                BogofOffers = new List <BogofOffer>
                {
                    bogoOfferRepository.GetBogofOffer(1)
                },
                OfferVoucher = offerVoucherRepository.GetOffVoucher(2)
            };
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(8));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(8));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(11));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(11));

            basketService         = new BasketService(basketProcessorFactory);
            basketServiceResponse = basketService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket5 - Total : £{basketServiceResponse.BasketTotal}");
            foreach (var notification in basketServiceResponse.Notifications)
            {
                Console.WriteLine($"Basket5 - Message:{notification}");
            }

            ConsoleSetup(6);

            /* Basket 6:
             * 3 Hat @ 4.75
             * 2 Jumper @ 15.25
             * BOGOF offer fon Product Category:Hats
             * 10% off on totals greater than £20 (after BOGOF) Applied
             * Total: £26.10
             * Message: BOGOF discount £4.75 applied
             * Message: OfferVoucher discount £4.00 applied.
             * Message: Loyalty discount £0.72 applied.
             */
            shoppingBasket = new BLL.ShoppingBasket
            {
                BogofOffers = new List <BogofOffer>
                {
                    bogoOfferRepository.GetBogofOffer(1)
                },
                OfferVoucher = offerVoucherRepository.GetOffVoucher(2),
                LoyaltyOffer = loyaltyOfferRepository.GetLoyaltyOffer(1)
            };
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(10));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(10));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(10));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(9));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(9));

            basketService         = new BasketService(basketProcessorFactory);
            basketServiceResponse = basketService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket6 - Total : £{basketServiceResponse.BasketTotal}");
            foreach (var notification in basketServiceResponse.Notifications)
            {
                Console.WriteLine($"Basket6 - Message:{notification}");
            }
            Console.ReadLine();
        }
コード例 #10
0
        public static void Main(string[] args)
        {
            IProductRepository      productRepository      = new ProductRepository();
            IGiftVoucherRepository  giftVoucherRepository  = new GiftVoucherRepository();
            IOfferVoucherRepository offerVoucherRepository = new OfferVoucherRepository();

            ConsoleSetup(0);
            // Empty Basket
            var shoppingBasket = new BLL.ShoppingBasket();

            IBasketProcessorFactory basketProcessorFactory = new BasketProcessorFactory();
            var basetService          = new BasketService(basketProcessorFactory);
            var basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket0 - Total : £{basketServiceResponse.BasketTotal}");
            Console.WriteLine($"Basket0 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}");

            ConsoleSetup(0);
            // Basket 1:
            shoppingBasket = new BLL.ShoppingBasket
            {
                GiftVouchers = new List <GiftVoucher>
                {
                    giftVoucherRepository.GetGiftVoucher(1)
                }
            };

            shoppingBasket.AddtemToBasket(productRepository.GetProduct(1));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(2));
            basetService          = new BasketService(basketProcessorFactory);
            basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket1 - Total : £{basketServiceResponse.BasketTotal}");

            ConsoleSetup(0);
            // Basket 2:

            shoppingBasket = new BLL.ShoppingBasket
            {
                OfferVoucher = offerVoucherRepository.GetOffVoucher(1)
            };

            shoppingBasket.AddtemToBasket(productRepository.GetProduct(3));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(4));

            basetService          = new BasketService(basketProcessorFactory);
            basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket2 - Total : £{basketServiceResponse.BasketTotal}");
            Console.WriteLine($"Basket2 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}");

            ConsoleSetup(0);
            // Basket 3:

            shoppingBasket = new BLL.ShoppingBasket
            {
                OfferVoucher = offerVoucherRepository.GetOffVoucher(1)
            };

            shoppingBasket.AddtemToBasket(productRepository.GetProduct(3));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(4));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(5));

            //basketProcessorFactory = new BasketProcessorFactory();
            basetService          = new BasketService(basketProcessorFactory);
            basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket3 - Total : £{basketServiceResponse.BasketTotal}");
            Console.WriteLine($"Basket3 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}");

            ConsoleSetup(0);
            // Basket 4:

            shoppingBasket = new BLL.ShoppingBasket
            {
                GiftVouchers = new List <GiftVoucher>
                {
                    giftVoucherRepository.GetGiftVoucher(1)
                },
                OfferVoucher = offerVoucherRepository.GetOffVoucher(2)
            };

            shoppingBasket.AddtemToBasket(productRepository.GetProduct(3));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(4));

            basetService          = new BasketService(basketProcessorFactory);
            basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket4 - Total : £{basketServiceResponse.BasketTotal}");
            Console.WriteLine($"Basket4 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}");

            ConsoleSetup(0);
            // Basket 5:

            shoppingBasket = new BLL.ShoppingBasket
            {
                OfferVoucher = offerVoucherRepository.GetOffVoucher(2)
            };

            shoppingBasket.AddtemToBasket(productRepository.GetProduct(3));
            shoppingBasket.AddtemToBasket(productRepository.GetProduct(6));

            basetService          = new BasketService(basketProcessorFactory);
            basketServiceResponse = basetService.GetBasketTotal(shoppingBasket);

            Console.WriteLine($"Basket5 - Total : £{basketServiceResponse.BasketTotal}");
            Console.WriteLine($"Basket5 - Message:{basketServiceResponse.Notifications.ToList().FirstOrDefault()}");

            Console.ReadLine();
        }