public void TestSelect() { // setup the tested class instance and dependencies with the test case initialization. var mockDisplayPanel = new MockDisplayPanel(); // !!! define the simulation key pad command var mockReadKeypadInput = new MockReadKeypadInput() { SimInputAs = 'A' }; var mockVendingMessageRepository = new MockVendingMessageRepository(); IProductRepository product = new ProductRepository(); product.RegisterOrUpdateProduct(PrdA); product.RegisterOrUpdateProduct(PrdB); product.AddToStock('a', 1); product.AddToStock('b', 1); var orderPanel = new OrderPanel(mockDisplayPanel, mockReadKeypadInput, product, mockVendingMessageRepository); OrderCmdEvent cmd = OrderCmdEvent.OutOfStock; Product objPrd = null; // !! define the action test listener orderPanel.OrderAction += (c, p) => { cmd = c; objPrd = p; // off after getting the event orderPanel.Off(); }; bool exception = false; orderPanel.FailtException += ex => exception = true; // Test subject Action - select a product orderPanel.On(); Thread.Sleep(10000); // verify - selected product A Assert.False(exception); Assert.Equal(OrderCmdEvent.Select, cmd); Assert.Equal(objPrd, PrdA); // verify the message flow List <MessageCode> TestCatchedCodes = new List <MessageCode> { MessageCode.MakeYourOrder, MessageCode.SelectOrderLine, MessageCode.SelectOrderLine, MessageCode.SelectOrder, MessageCode.Ok }; Assert.Equal((IEnumerable <MessageCode>)TestCatchedCodes, (IEnumerable <MessageCode>)mockVendingMessageRepository.CatchedCodes); Assert.Equal((IEnumerable <string>)mockVendingMessageRepository.ReturnList, (IEnumerable <string>)mockDisplayPanel.DisplayList); }
public void TestPayment() { // setup the tested class instance and dependencies with the test case initialization. var mockDisplayPanel = new MockDisplayPanel(); var mockReadKeypadInput = new MockReadKeypadInput(); var mockVendingMessageRepository = new MockVendingMessageRepository(); var paymentPanel = new PaymentReceiver(mockDisplayPanel, mockReadKeypadInput, mockVendingMessageRepository); PaymentCmdEvent cmd = PaymentCmdEvent.Cancel; INotionValue objCoin = null; // !!! define the simulation key pad command of payment var firstCoin = paymentPanel.MapToCoins.First(); mockReadKeypadInput.SimInputAs = firstCoin.Key; // !! define the action test listener paymentPanel.CoinAction += (c, p) => { cmd = c; objCoin = p; // off after getting the event paymentPanel.Off(); }; bool exception = false; paymentPanel.FailtException += ex => exception = true; // Test subject Action - on payment receiver and get simulated payment paymentPanel.On(); Thread.Sleep(10000); // verify - payment Assert.False(exception); Assert.Equal(PaymentCmdEvent.Payment, cmd); Assert.Equal(firstCoin.Value, objCoin); // verify the message flow List <MessageCode> TestCatchedCodes = new List <MessageCode> { MessageCode.MakeYourPayment, MessageCode.Ok }; Assert.Equal((IEnumerable <MessageCode>)TestCatchedCodes, (IEnumerable <MessageCode>)mockVendingMessageRepository.CatchedCodes); Assert.Equal((IEnumerable <string>)mockVendingMessageRepository.ReturnList, (IEnumerable <string>)mockDisplayPanel.DisplayList); }