static void Main(string[] args) { Container container = new Container(); container.Register <IBillingProcessor, BillingProcessor>(); container.Register <ICustomer, Customer>(); container.Register <INotifier, Notifier>(); container.Register <ILogger, Logger>(); Console.WriteLine("Poor-Man's DI Container Example"); Console.WriteLine(); OrderInfo orderInfo = new OrderInfo() { CustomerName = "Miguel Castro", Email = "*****@*****.**", Product = "Laptop", Price = 1200, CreditCard = "1234567890" }; Console.WriteLine("Production:"); Console.WriteLine(); Commerce commerce = container.CreateType <Commerce>(); commerce.ProcessOrder(orderInfo); Console.WriteLine(); Console.WriteLine("Press [Enter] to exit..."); Console.ReadLine(); }
public void TestMethod1() { Mock<IBillingProcessor> mockBilling = new Mock<IBillingProcessor>(); Mock<ICustomer> mockCustomer = new Mock<ICustomer>(); Mock<INotifier> mockNotifier = new Mock<INotifier>(); Mock<ILogger> mockLogger = new Mock<ILogger>(); mockBilling.Setup( obj => obj.ProcessPayment(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<double>())); mockCustomer.Setup( obj => obj.UpdateCustomerOrder(It.IsAny<string>(), It.IsAny<string>())); mockNotifier.Setup( obj => obj.SendReceipt(It.IsAny<OrderInfo>())); mockLogger.Setup( obj => obj.Log(It.IsAny<string>())); Commerce commerce = new Commerce(mockBilling.Object, mockCustomer.Object, mockNotifier.Object, mockLogger.Object); commerce.ProcessOrder(new OrderInfo()); Assert.IsTrue(1 == 1); // this test just asserts that ProcessOrder can be called without error }