Ejemplo n.º 1
0
        private static void OrderWithInterFace_ManualDependancyInjection()
        {
            var productStockRepository_WithDI = new ProductStockRepository_WithDI();
            var orderMgr = new OrderManager_WithDI(
                productStockRepository: productStockRepository_WithDI,
                paymentProcessor: new PaymentProcessor_WithDI(),
                shippingProcessor: new ShippingProcessor_WithDI(productStockRepository: productStockRepository_WithDI)
                );

            var cmd = string.Empty;

            while (cmd != "exit")
            {
                Console.WriteLine(@"Enter a Product: 
Keyboard = 0, 
Mouse=1, 
Mic=2, 
Speaker=3");
                cmd = Console.ReadLine();

                try
                {
                    if (Enum.TryParse(cmd, out ProductEnum productEnum))
                    {
                        Console.WriteLine("Please enter valid craeditcard number: xxxxxxxxxxxxxxxx;MMYY");
                        var paymentNumber = Console.ReadLine();
                        if (string.IsNullOrEmpty(paymentNumber) || !(paymentNumber.Split(";").Length == 2))
                        {
                            throw new Exception("Invalid payment method");
                        }

                        orderMgr.Submit(productEnum, paymentNumber.Split(";")[0], paymentNumber.Split(";")[1]);
                        Console.WriteLine($"{productEnum.ToString()} order has been completed..");
                    }
                    else
                    {
                        Console.WriteLine("invalid cmd");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine(Environment.NewLine);
            }
        }
Ejemplo n.º 2
0
        public void Test_OrderManager_DI_OutOfStock_ErrorMessage()
        {
            var productStockRepository_Mock = new Mock <IProductStockRepository_WithDI>();

            productStockRepository_Mock
            .Setup(m => m.IsInStock(It.IsAny <ProductEnum>()))
            .Returns(false);

            var paymentProcessorMock  = new Mock <IPaymentProcessor_WithDI>();
            var shippingProcessorMock = new Mock <IShippingProcessor_WithDI>();


            var orderManager = new OrderManager_WithDI(productStockRepository_Mock.Object, paymentProcessorMock.Object, shippingProcessorMock.Object);


            Assert.ThrowsAny <Exception>(() => orderManager.Submit(ProductEnum.KeyBoard, "1234567891234567", "1021"));
        }