Example #1
0
        static void Main(string[] args)
        {
            var shoppingRepository = new ShoppingRepository();
            var shoppingOperation  = new ShoppingOperation(shoppingRepository);

            Console.WriteLine("Welcome to Retail Shop... Happy Shopping");
            var availableProducts = shoppingOperation.AddProducts();

            Console.WriteLine("------Product--------Price-------");
            foreach (var product in availableProducts)
            {
                Console.WriteLine($"        {product.Name}           {product.Price}");
            }

            Console.WriteLine("Please Enter Cart Items");
            var inputItems = Console.ReadLine();
            var cartItems  = shoppingOperation.ProcessCartItems(inputItems);

            var productDetails = shoppingOperation.GetProductDetails(cartItems, availableProducts);

            var total = shoppingOperation.GetTotalBill(productDetails);

            Console.WriteLine("-------Qunatity * Product------ Price----");
            foreach (var item in productDetails)
            {
                Console.WriteLine($"-------{item.Quantity} * {item.Product} ----- {item.Price}-----");
            }

            Console.WriteLine($"-------Total --------------{total}-------");
            Console.ReadLine();
        }
Example #2
0
        public void Test_ShoppingOperation_WhenCartIsSelected_GetTotalPrice()
        {
            var mockShoppingRepository = new Mock <IShoppingRepository>();
            var shoppingOperation      = new ShoppingOperation(mockShoppingRepository.Object);



            var productDetails = new List <ProductDetail>();

            productDetails.Add(new ProductDetail {
                Product = "A", Price = 50, Quantity = 2
            });
            productDetails.Add(new ProductDetail {
                Product = "B", Price = 30, Quantity = 1
            });

            var total = shoppingOperation.GetTotalBill(productDetails);

            Assert.True(total == 80);
        }