Exemplo n.º 1
0
        public void InsertValidCard()
        {
            // Works with tracking
            var tracking = new MemoryTrackingParticipant();

            var atm = new AtmMachine();

            // Create a new state machine using enums to define the states I want
            var atmStateMachine = atm.StateMachine;

            // Add my tracking provider
            atmStateMachine.WorkflowApplication.Extensions.Add(tracking);

            try
            {
                // Turn the power on an wait for the CardInserted transition to enable
                atm.TurnPowerOn();

                // Insert a valid card and wait for the KeypadEnter transition
                atm.InsertCard(true);

                // Enter a pin
                atm.AcceptPin("1234");

                // Turn off the ATM
                atm.TurnPowerOff();

                // Verify the first three states occurred in the correct order.
                // Make sure you set the state name correctly
                AssertState.OccursInOrder(
                    "ATM StateMachine", tracking.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",
                    atm.Transitions,
                    AtmTrigger.PowerOn,
                    AtmTrigger.CardInserted,
                    AtmTrigger.KeypadEnter,
                    AtmTrigger.PowerOff);

                // Verify the prompts
                AssertHelper.OccursInOrder(
                    "Prompts", atm.DisplayedPrompts, Prompts.PleaseWait, Prompts.InsertCard, Prompts.EnterYourPin);

                // Verify the valid card
                Assert.AreEqual(1, atm.CardReaderResults.Count);
                Assert.AreEqual(CardStatus.Valid, atm.CardReaderResults[0].CardStatus);

                // Verify the exit action cleared the screen at least twice
                Assert.IsTrue(
                    atm.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
            {
                tracking.Trace();

                Trace.WriteLine(string.Empty);
                Trace.WriteLine("*** Workflow Definition ***");
                Trace.WriteLine(XamlServices.Save(atmStateMachine.WorkflowStateMachine));
            }
        }
Exemplo n.º 2
0
        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 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);
            }
        }
Exemplo n.º 4
0
        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 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);
            }
        }