Exemplo n.º 1
0
        public void Can_Checkout_And_Get_Best_Sale_Price()
        {
            Dictionary <int, ISale> discounts = new Dictionary <int, ISale>(2);

            discounts.Add(2141, new Sale(2141, 1.99m));
            discounts.Add(4011, new Sale(4011, 0.89m));
            _storeRepository.Setup(foo => foo.GetSalePrices()).Returns(discounts);

            _cart = new Cart(_storeRepository.Object);
            _cart.AddItem(new CartItem(2141, "Apple"));
            _cart.AddItem(new CartItem(3001, "Grapes"));
            _cart.AddItem(new CartItem(4011, "Banana"));

            Receipt receipt = _cart.Checkout();
            List <ReceiptLineItem> receiptLineItems = receipt.GetLineItems().ToList();

            Assert.Equal(2, receiptLineItems.Count);
            Assert.Equal(1, receipt.IgnoredItems.Count);

            Assert.Equal(2141, receiptLineItems[0].PLU);
            Assert.Equal(1.99m, receiptLineItems[0].FinalPrice);

            Assert.Equal(4011, receiptLineItems[1].PLU);
            Assert.Equal(0.89m, receiptLineItems[1].FinalPrice);
            Assert.Equal(2.88m, receipt.GrandTotal);
        }
Exemplo n.º 2
0
        public IHttpActionResult Checkout([FromBody] Guid cartID)
        {
            //get the cart
            var cart = _Cart.GetCart(cartID);

            var userID                = cart.UserID;
            var cartXBookList         = cart.BookList;
            List <BookModel> bookList = new List <BookModel>();

            foreach (var book in cartXBookList)
            {
                bookList.Add(_Book.GetBookByBookID(book.BookID));
            }

            //var currentUser = await _UserManager.FindByIdAsync(userID.ToString());
            var currentUser = UserManager.FindByEmail(User.Identity.Name);
            var user        = _Account.GetUserInfo(currentUser);

            //checkout the cart
            var list = _Cart.Checkout(cartID);

            CheckoutEmail(user, bookList, cartXBookList);


            if (list)
            {
                return(Ok());
            }
            return(BadRequest());
        }
        static void Main(string[] args)
        {
            RegisterServices();

            ICart cart = _serviceProvider.GetService <ICart>();
            var   log  = _serviceProvider.GetService <ILogger>();

            //Declare Products
            DeclareProducts();

            //Add Promotions
            CreatePromotions();

            UpdateProductForCoupon();

            //Make order
            PrepareOrders();
            cart.AddOrdersToCart(_orders);

            Console.WriteLine("Proceed to checkout? y/n");
            if ("y" == Console.ReadLine().ToLower())
            {
                cart.Checkout();
            }

            DisposeServices();
            Console.ReadLine();
        }
Exemplo n.º 4
0
        public void Can_Checkout_And_Get_Best_Sale_Price_Or_Promotion()
        {
            Dictionary <int, ISale> discounts = new Dictionary <int, ISale>(2);

            discounts.Add(2141, new Sale(2141, 1.56m));
            discounts.Add(4011, new Sale(4011, 0.89m));
            _storeRepository.Setup(foo => foo.GetSalePrices()).Returns(discounts);

            Dictionary <int, IPromotion> promotions = new Dictionary <int, IPromotion>(2);

            promotions.Add(2141, new Promotion("GroupPromotionalPrice", 2141, 4, 0, 1.56m));
            promotions.Add(4011, new Promotion("AdditionalProductDiscount", 4011, 3, 1, 100));
            _storeRepository.Setup(fn => fn.GetPromotions()).Returns(promotions);

            _cart = new Cart(_storeRepository.Object);
            _cart.AddItem(new CartItem(2141, "Apple"));
            _cart.AddItem(new CartItem(2141, "Apple"));
            _cart.AddItem(new CartItem(2141, "Apple"));

            _cart.AddItem(new CartItem(4011, "Banana"));
            _cart.AddItem(new CartItem(4011, "Banana"));
            _cart.AddItem(new CartItem(4011, "Banana"));
            _cart.AddItem(new CartItem(4011, "Banana"));

            _cart.AddItem(new CartItem(3001, "Grapes"));
            _cart.AddItem(new CartItem(3291, "Pineapple"));
            _cart.AddItem(new CartItem(2101, "Orange"));


            Receipt receipt = _cart.Checkout();
            List <ReceiptLineItem> receiptLineItems = receipt.GetLineItems().ToList();

            Assert.Equal(4, receiptLineItems.Count);
            Assert.Equal(1, receipt.IgnoredItems.Count);

            Assert.Equal(2141, receiptLineItems[0].PLU);
            Assert.Equal(4.68m, receiptLineItems[0].FinalPrice);

            Assert.Equal(4011, receiptLineItems[1].PLU);
            Assert.Equal(2.97m, receiptLineItems[1].FinalPrice);

            Assert.Equal(3291, receiptLineItems[2].PLU);
            Assert.Equal(4.55m, receiptLineItems[2].FinalPrice);

            Assert.Equal(2101, receiptLineItems[3].PLU);
            Assert.Equal(2.49m, receiptLineItems[3].FinalPrice);

            Assert.Equal(14.69m, receipt.GrandTotal);
        }
Exemplo n.º 5
0
        public void Can_Checkout_And_Get_Best_Promotion()
        {
            Dictionary <int, IPromotion> promotions = new Dictionary <int, IPromotion>(2);

            promotions.Add(2141, new Promotion("GroupPromotionalPrice", 2141, 4, 0, 2.12m));
            promotions.Add(2101, new Promotion("AdditionalProductDiscount", 2101, 3, 1, 100));
            _storeRepository.Setup(fn => fn.GetPromotions()).Returns(promotions);

            _cart = new Cart(_storeRepository.Object);
            _cart.AddItem(new CartItem(2141, "Apple"));
            _cart.AddItem(new CartItem(2141, "Apple"));
            _cart.AddItem(new CartItem(2141, "Apple"));
            _cart.AddItem(new CartItem(2141, "Apple"));
            _cart.AddItem(new CartItem(2141, "Apple"));

            _cart.AddItem(new CartItem(2101, "Orange"));
            _cart.AddItem(new CartItem(2101, "Orange"));
            _cart.AddItem(new CartItem(2101, "Orange"));
            _cart.AddItem(new CartItem(2101, "Orange"));
            _cart.AddItem(new CartItem(2101, "Orange"));
            _cart.AddItem(new CartItem(2101, "Orange"));

            _cart.AddItem(new CartItem(3001, "Grapes"));

            _cart.AddItem(new CartItem(4011, "Banana"));
            _cart.AddItem(new CartItem(4011, "Banana"));

            Receipt receipt = _cart.Checkout();
            List <ReceiptLineItem> receiptLineItems = receipt.GetLineItems().ToList();

            Assert.Equal(3, receiptLineItems.Count);
            Assert.Equal(1, receipt.IgnoredItems.Count);

            Assert.Equal(2141, receiptLineItems[0].PLU);
            Assert.Equal(11.60m, receiptLineItems[0].FinalPrice);

            Assert.Equal(2101, receiptLineItems[1].PLU);
            Assert.Equal(12.45m, receiptLineItems[1].FinalPrice);

            Assert.Equal(4011, receiptLineItems[2].PLU);
            Assert.Equal(1.98m, receiptLineItems[2].FinalPrice);

            Assert.Equal(26.03m, receipt.GrandTotal);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Checkout()
        {
            var result = await _repo.Checkout();

            return(Ok(result));
        }