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_WhenDiscountAIsApplied_DisplayDiscountedPrice()
        {
            var mockShoppingRepository = new Mock <IShoppingRepository>();
            var shoppingOperation      = new ShoppingOperation(mockShoppingRepository.Object);

            var cartItems = new List <Cart>();

            cartItems.Add(new Cart {
                Product = "A", Quantity = 3
            });
            cartItems.Add(new Cart {
                Product = "B", Quantity = 1
            });

            var products = new List <Product>();

            products.Add(new Product {
                Name = "A", Price = 50, DiscountType = "DiscountA"
            });
            products.Add(new Product {
                Name = "B", Price = 30, DiscountType = null
            });

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

            Assert.True(productDetails.Count == 2);
            Assert.True(productDetails.First(x => x.Product == "A").Price == 130);
            Assert.True(productDetails.First(x => x.Product == "B").Price == 30);
        }