public void EnterPinTriggerTimeoutToRemoveCard() { this.TestContext.WriteLine("Given"); this.TestContext.WriteLine("* The ATM Machine"); this.TestContext.WriteLine("* In the Enter Pin state"); this.TestContext.WriteLine("When"); this.TestContext.WriteLine("* An Keypad Cancel is pressed"); this.TestContext.WriteLine("Then"); this.TestContext.WriteLine("* The StateMachine enters the Remove Card state"); this.TestContext.WriteLine("Test scenario completed in Exercise 3"); var testViewModel = new TestAtmViewModel(); // Create with a very short timeout var atmMachine = new AtmMachine(testViewModel) { AtmTimeout = TimeSpan.FromMilliseconds(100) }; try { // Turn the power on atmMachine.TurnPowerOn().WaitForWorkflow(); // Insert an valid card atmMachine.InsertCard(true).WaitForWorkflow(); // Wait for the workflow to get to the Remove Card state atmMachine.WaitForState(AtmState.RemoveCard); // Turn off the ATM atmMachine.TurnPowerOff().Wait(); // Verify the first three states occurred in the correct order. // Make sure you set the state name correctly AssertState.OccursInOrder( "ATM StateMachine", testViewModel.Records, AtmState.Initialize, AtmState.InsertCard, AtmState.EnterPin, AtmState.RemoveCard); // Verify that you added an InitializeAtm activity to the Entry actions of the Initialize State AssertHelper.OccursInOrder("Transitions", testViewModel.Transitions, AtmTransition.PowerOn, AtmTransition.CardInserted, AtmTransition.PowerOff); // Verify the prompts AssertHelper.OccursInOrder( "Prompts", testViewModel.Prompts.ConvertAll((prompt) => prompt.Text), Prompts.PleaseWait, Prompts.InsertCard, Prompts.EnterYourPin); // Verify the valid card Assert.AreEqual(1, testViewModel.CardReaderResults.Count); Assert.AreEqual(CardStatus.Valid, testViewModel.CardReaderResults[0].CardStatus); // Verify the exit action cleared the screen at least twice Assert.IsTrue(testViewModel.ClearCount >= 2, "Verify that you added a ClearView activity to the Exit Action of the Initialize State"); // Verify the camera control AssertHelper.OccursInOrder("CameraControl", testViewModel.CameraControl, true); } finally { testViewModel.Trace(this.TestContext); } }
public void PowerOnAtmScenario() { this.TestContext.WriteLine("Given"); this.TestContext.WriteLine("* A Powered Off ATM"); this.TestContext.WriteLine("When"); this.TestContext.WriteLine("* The Power Is Turned On"); this.TestContext.WriteLine("Then"); this.TestContext.WriteLine("* The ATM displays a please wait message."); this.TestContext.WriteLine("* and initializes the hardware "); this.TestContext.WriteLine("* After initialization it prompts the user to insert a card"); this.TestContext.WriteLine("Test scenario completed in Exercise 1"); var testViewModel = new TestAtmViewModel(); var target = new AtmMachine(testViewModel); try { // Turn the power on an wait for the CardInserted transition to enable target.TurnPowerOn().WaitForWorkflow(); // Turn it off and wait for the power off to complete target.TurnPowerOff().Wait(); // Verify the first three states occurred in the correct order. // Make sure you set the state name correctly AssertState.OccursInOrder("ATM StateMachine", testViewModel.Records, AtmState.Initialize, AtmState.InsertCard); // Verify the prompts AssertHelper.OccursInOrder("Prompts", testViewModel.Prompts.ConvertAll((prompt) => prompt.Text), Prompts.PleaseWait, Prompts.InsertCard); // Verify the exit action cleared the screen at least twice Assert.IsTrue(testViewModel.ClearCount >= 2, "Verify that you added a ClearView activity to the Exit Action of the Initialize State"); } finally { testViewModel.Trace(this.TestContext); } }
public void TransactionMenuToWithdraw() { this.TestContext.WriteLine("Given"); this.TestContext.WriteLine("* A user is at the transaction menu"); this.TestContext.WriteLine("When"); this.TestContext.WriteLine("* An Button1 is pressed"); this.TestContext.WriteLine("Then"); this.TestContext.WriteLine("* The transaction menu should enter the Withdraw state and immediately"); this.TestContext.WriteLine("* transition to the exit state via a null transition"); this.TestContext.WriteLine("Test scenario completed in Exercise 4"); var testViewModel = new TestAtmViewModel(); var atmMachine = new AtmMachine(testViewModel); try { // Turn the power on atmMachine.TurnPowerOn().WaitForWorkflow(); // Insert an valid card atmMachine.InsertCard(true).WaitForWorkflow(); // Enter a pin ends with Keypad Enter atmMachine.AcceptPin("1234").WaitForWorkflow(); // Press button 1 atmMachine.Withdraw().WaitForWorkflow(); // Turn off the ATM atmMachine.TurnPowerOff().Wait(); // Verify the states AssertState.OccursInOrder( "Transaction Menu StateMachine", testViewModel.Records, TransactionMenuState.TransactionMenu, TransactionMenuState.Withdraw, TransactionMenuState.Exit); AssertState.OccursInOrder( "ATM StateMachine", testViewModel.Records, AtmState.Initialize, AtmState.InsertCard, AtmState.EnterPin, AtmState.MainMenu); // Verify the transitions AssertHelper.OccursInOrder( "Transitions", testViewModel.Transitions, AtmTransition.PowerOn, AtmTransition.CardInserted, AtmTransition.KeypadEnter, AtmTransition.Withdraw, AtmTransition.PowerOff); // Verify the prompts AssertHelper.OccursInOrder( "Prompts", testViewModel.Prompts.ConvertAll((prompt) => prompt.Text), Prompts.PleaseWait, Prompts.InsertCard, Prompts.EnterYourPin); // Verify the valid card Assert.AreEqual(1, testViewModel.CardReaderResults.Count); Assert.AreEqual(CardStatus.Valid, testViewModel.CardReaderResults[0].CardStatus); // Verify the exit action cleared the screen at least twice Assert.IsTrue(testViewModel.ClearCount >= 4, "Verify that you added the ClearView activity to the Exit Action of states that require it"); // Verify the camera control AssertHelper.OccursInOrder("CameraControl", testViewModel.CameraControl, true); } finally { testViewModel.Trace(this.TestContext); } }
public void InsertValidCard() { this.TestContext.WriteLine("Given"); this.TestContext.WriteLine("* The ATM Machine"); this.TestContext.WriteLine("* In the Insert Card state"); this.TestContext.WriteLine("When"); this.TestContext.WriteLine("* An valid card is inserted"); this.TestContext.WriteLine("Then"); this.TestContext.WriteLine("* the camera is turned on"); this.TestContext.WriteLine("* The StateMachine enters the Enter Pin state "); this.TestContext.WriteLine("* and displays prompt Enter your pin"); this.TestContext.WriteLine("Test scenario completed in Exercise 2"); var testViewModel = new TestAtmViewModel(); var atmMachine = new AtmMachine(testViewModel); try { // Turn the power on an wait for the CardInserted transition to enable atmMachine.TurnPowerOn().WaitForWorkflow(); // Insert a valid card and wait for the KeypadEnter transition atmMachine.InsertCard(true).WaitForWorkflow(); // Enter a pin atmMachine.AcceptPin("1234").WaitForWorkflow(); // Turn off the ATM atmMachine.TurnPowerOff().Wait(); // Verify the first three states occurred in the correct order. // Make sure you set the state name correctly AssertState.OccursInOrder("ATM StateMachine", testViewModel.Records, AtmState.Initialize, AtmState.InsertCard, AtmState.EnterPin); // Verify that you added an InitializeAtm activity to the Entry actions of the Initialize State AssertHelper.OccursInOrder( "Transitions", testViewModel.Transitions, AtmTransition.PowerOn, AtmTransition.CardInserted, AtmTransition.KeypadEnter, AtmTransition.PowerOff); // Verify the prompts AssertHelper.OccursInOrder( "Prompts", testViewModel.Prompts.ConvertAll((prompt) => prompt.Text), Prompts.PleaseWait, Prompts.InsertCard, Prompts.EnterYourPin); // Verify the valid card Assert.AreEqual(1, testViewModel.CardReaderResults.Count); Assert.AreEqual(CardStatus.Valid, testViewModel.CardReaderResults[0].CardStatus); // Verify the exit action cleared the screen at least twice Assert.IsTrue(testViewModel.ClearCount >= 2, "Verify that you added a ClearView activity to the Exit Action of the Initialize State"); // Verify the camera control AssertHelper.OccursInOrder("CameraControl", testViewModel.CameraControl, true); } finally { testViewModel.Trace(this.TestContext); } }
public void InsertInvalidCard() { this.TestContext.WriteLine("Given"); this.TestContext.WriteLine("* The ATM Machine"); this.TestContext.WriteLine("* In the Insert Card state"); this.TestContext.WriteLine("When"); this.TestContext.WriteLine("* An invalid card is inserted"); this.TestContext.WriteLine("Then"); this.TestContext.WriteLine("* the camera is turned on"); this.TestContext.WriteLine("* The StateMachine enters the RemoveCard state "); this.TestContext.WriteLine("* and displays prompt Error reading card, Please remove your card"); this.TestContext.WriteLine("* and waits for the user to remove their card"); this.TestContext.WriteLine("* and then turns off the camera"); this.TestContext.WriteLine("Test scenario completed in Exercise 2"); var testViewModel = new TestAtmViewModel(); var atmMachine = new AtmMachine(testViewModel); try { // Run the insert card scenario atmMachine.TurnPowerOn().WaitForWorkflow(); // Insert an invalid card atmMachine.InsertCard(false).WaitForWorkflow(); // Remove the card atmMachine.RemoveCard().WaitForWorkflow(); // Turn off the ATM atmMachine.TurnPowerOff().Wait(); // Verify the states occurred in the correct order. // Make sure you set the state name correctly AssertState.OccursInOrder( "ATM StateMachine", testViewModel.Records, AtmState.Initialize, AtmState.InsertCard, AtmState.RemoveCard, AtmState.InsertCard); // Verify that you added an InitializeAtm activity to the Entry actions of the Initialize State AssertHelper.OccursInOrder( "Transitions", testViewModel.Transitions, AtmTransition.PowerOn, AtmTransition.CardInserted, AtmTransition.CardRemoved, AtmTransition.PowerOff); // Verify the prompts AssertHelper.OccursInOrder( "Prompts", testViewModel.Prompts.ConvertAll((prompt) => prompt.Text), Prompts.PleaseWait, Prompts.InsertCard, Prompts.ErrRemoveCard, Prompts.InsertCard); // Verify the invalid card Assert.AreEqual(1, testViewModel.CardReaderResults.Count); Assert.AreEqual(CardStatus.Invalid, testViewModel.CardReaderResults[0].CardStatus); // Verify the exit action cleared the screen at least twice Assert.IsTrue(testViewModel.ClearCount >= 2, "Verify that you added a ClearView activity to the Exit Action of the Initialize State"); // Verify the camera control AssertHelper.OccursInOrder("CameraControl", testViewModel.CameraControl, true, false); } finally { testViewModel.Trace(this.TestContext); } }