Exemple #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();
        }
Exemple #2
0
        public void Test_ShoppingOperation_ShowAvailableProducts()
        {
            var            mockShoppingRepository = new Mock <IShoppingRepository>();
            List <Product> mockProducts           = new List <Product>();

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

            mockShoppingRepository.Setup(x => x.AddProducts()).Returns(mockProducts);

            var shoppingOperation = new ShoppingOperation(mockShoppingRepository.Object);
            var availableProducts = shoppingOperation.AddProducts();

            Assert.True(availableProducts.Count == 2);
            Assert.True(availableProducts[0].Name == "A");
            Assert.True(availableProducts[0].Price == 50);
            Assert.True(availableProducts[0].DiscountType == "DiscountA");
        }