Example #1
0
        public void CalculateBasketTotal_ReturnsDecimal()
        {
            // Arrange
            Type expected = typeof(Decimal);
            // Act
            var actual = basketService.CalculateBasketTotal(new List <Product>());

            // Assert
            Assert.AreEqual(expected, actual.GetType());
        }
        public void CalculateBasketTotalWhenQuantityIsExplicitlySpecified()
        {
            var shelfItems = _shelfItemRepository.GetShelfItems().ToArray();

            _basketService.AddItemToBasket(shelfItems[0], 3);

            _basketService.AddItemToBasket(shelfItems[1], 2);

            _basketService.AddItemToBasket(shelfItems[2]);

            _basketService.AddItemToBasket(shelfItems[3]);

            Assert.AreEqual(3.39m, _basketService.CalculateBasketTotal());
        }
Example #3
0
        private static void PrintCustomerReceipt(SpecialOffer[] specialOffers, Discount[] discounts, IBasketService basketService)
        {
            var totalBill = basketService.CalculateBasketTotal();


            Write("\n\n\n");
            WriteLine("\t CUSTOMER RECEIPT");
            Write("\t ==============================================");

            foreach (var basketItem in basketService.GetBasketItems())
            {
                var discountAndSpecialOffer = GetApplicableDiscountAndSpecialOfferOnShelfItem(basketItem.ShelfItem.Id, discounts, specialOffers);
                var discount     = discountAndSpecialOffer.Item1;
                var specialOffer = discountAndSpecialOffer.Item2;

                var receiptItemDisplay = $"\n\t {basketItem.ShelfItem.Name} - {basketItem.ShelfItem.Price:C2} ";

                if (discount != null)
                {
                    receiptItemDisplay += $"@ ({discount.DiscountPercent}%) ";
                }

                receiptItemDisplay += $"* {basketItem.Quantity} => {basketItem.Price:C2}";

                if (specialOffer != null)
                {
                    receiptItemDisplay += $" ({specialOffer.Quantity} for {specialOffer.Price:C2})";
                }

                WriteLine(receiptItemDisplay);
            }

            Write("\t ==============================================");
            WriteLine($"\n\t YOUR TOTAL BILL IS: {totalBill:C2}");
            Write("\t ==============================================");
        }
Example #4
0
 public Decimal Checkout()
 {
     return(basketservice.CalculateBasketTotal(Basket));
 }