public void Cant_Verified_Account_Is_Not_Open() { _sut = new Account(true, false, false, 1000, "Germán Küber", () => { }); _atmMachine = new AtmMachine(_sut); Assert.Throws <AccountClosedException>(() => _atmMachine.HolderVirfied()); }
static void Main(string[] args) { var withdrawalStrategy = new LargestBillsOnly(); var inventory = new AtmInventory(); inventory.ResetInventory(AtmInventory.DefaultInventory()); var atm = new AtmMachine(withdrawalStrategy, inventory); var commandFactory = new CommandFactory(); var done = false; do { var input = Console.ReadLine(); var command = commandFactory.CreateCommand(input); if (command.IsExit) { done = true; } else { command.Execute(atm); } } while (done != true); }
static void Main(string[] args) { // Initially ATM Machine in DebitCardNotInsertedState AtmMachine atmMachine = new AtmMachine(); Console.WriteLine("ATM Machine Current state : " + atmMachine.AtmMachineState.GetType().Name); Console.WriteLine(); atmMachine.EnterPin(); atmMachine.WithdrawMoney(); atmMachine.EjectDebitCard(); atmMachine.InsertDebitCard(); Console.WriteLine(); // Debit Card has been inserted so internal state of ATM Machine // has been changed to DebitCardInsertedState Console.WriteLine("ATM Machine Current state : " + atmMachine.AtmMachineState.GetType().Name); Console.WriteLine(); atmMachine.EnterPin(); atmMachine.WithdrawMoney(); atmMachine.InsertDebitCard(); atmMachine.EjectDebitCard(); Console.WriteLine(""); // Debit Card has been ejected so internal state of ATM Machine // has been changed to DebitCardNotInsertedState Console.WriteLine("ATM Machine Current state : " + atmMachine.AtmMachineState.GetType().Name); Console.Read(); }
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 Cant_WithDraw_Money_Is_Not_Closed() { _sut = new Account(true, false, false, 1000, "Germán Küber", () => { }); _atmMachine = new AtmMachine(_sut); Assert.Throws <AccountClosedException>(() => _atmMachine.WithDraw(100)); }
public void RestockTest() { AtmMachine atmMachine = new AtmMachine(); atmMachine.Restock(); Assert.IsTrue(atmMachine.NumberOfBills(50) == 10); }
public void GetDenominationsTestWithSomeInvalidBills() { AtmMachine machine = GetTestAtmMachine(); var result = AtmMachineManagerHelper.GetDenominations("I $50 $37 $100", machine); Assert.IsTrue(result.Count() == 2); }
public void EnterPin_cannot_enter_pin_if_theres_no_card() { // Given: There's no card inserted in the ATM IAtmMachine atmMachine = new AtmMachine(); // When: We try to enter a pin atmMachine.EnterPin("1234"); // Then: Exception }
private AtmMachine GetTestAtmMachine() { AtmMachine machine = new AtmMachine(); machine.AddBills(100, 10); machine.AddBills(50, 10); machine.AddBills(20, 10); return(machine); }
public void Execute_UnFrozen() { var execute = false; var sut = new Account(true, true, true, 1000, "Germán Küber - Demo", () => { execute = true; }); var atmMachine = new AtmMachine(sut); atmMachine.WithDraw(1000); Assert.True(execute); }
public void InsertCard_card_not_inserted() { // Given: We have an ATM card IAtmCard atmCard = new AtmCard(); IAtmMachine atmMachine = new AtmMachine(); // When: we don't inserts the ATM Card // Then: The card must be inserted Assert.IsFalse(atmMachine.CardInserted); }
public void InsertCard_can_insert_card() { // Given: We have an ATM card IAtmCard atmCard = new AtmCard(); IAtmMachine atmMachine = new AtmMachine(); // When: we inserts the ATM Card atmMachine.InsertCard(atmCard); // Then: The card must be inserted Assert.IsTrue(atmMachine.CardInserted); }
public void InsertCard_insert_and_eject_card() { // Given: We have an ATM card IAtmCard atmCard = new AtmCard(); IAtmMachine atmMachine = new AtmMachine(); // When: we insert and eject the card atmMachine.InsertCard(atmCard); atmMachine.EjectCard(); // Then: The card must be inserted Assert.IsFalse(atmMachine.CardInserted); }
public void DisplayDenominationsTest() { AtmMachine atmMachine = new AtmMachine(); atmMachine.Restock(); List <int> denominations = new List <int> { 100, 50 }; var result = atmMachine.DisplayDenominations(denominations); Assert.IsTrue(result.IndexOf("$50 - 10") != -1); }
public void EnterPin_enter_correct_pin() { // Given: We insert the card in the machine ICustomer customer = new Customer(); IAtmCard atmCard = new AtmCard(); IAtmMachine atmMachine = new AtmMachine(); // When: We enter the pin the correct pin atmMachine.InsertCard(atmCard); atmMachine.EnterPin(customer.MySecretPin); // Then: ATM Machine status should be Authenticated Assert.IsTrue(atmMachine.Authenticated); }
public void EnoughBalanceNoFiveDollarBillsEnoughOnes() { AtmMachine atmMachine = new AtmMachine(); atmMachine.AddBills(1000, 10); atmMachine.AddBills(50, 10); atmMachine.AddBills(20, 10); atmMachine.AddBills(10, 10); atmMachine.AddBills(5, 0); atmMachine.AddBills(1, 10); var result = atmMachine.Dispense(5); Assert.IsTrue(result.IndexOf(successMessage) != -1); }
public void CheckBalance_balance_0_for_new_account() { // Given: The customer opened a new account and didn't deposit any cash yet ICustomer customer = new Customer(); IAtmCard atmCard = new AtmCard(); IAtmMachine atmMachine = new AtmMachine(); // When: He checks his back balance atmMachine.InsertCard(atmCard); atmMachine.EnterPin("1234"); var balance = atmMachine.CheckBalance(); // Then: The balance should be 0 Assert.AreEqual(0, balance); }
public void EnoughBalanceNoFiveDollarBillsNotEnoughOnes() { AtmMachine atmMachine = new AtmMachine(); atmMachine.AddBills(1000, 10); atmMachine.AddBills(50, 10); atmMachine.AddBills(20, 10); atmMachine.AddBills(10, 10); atmMachine.AddBills(5, 0); atmMachine.AddBills(1, 3); var result = atmMachine.Dispense(5); Assert.AreEqual(result, insufficientFundsMessage); }
static void Main(string[] args) { AtmMachine machine = new AtmMachine(); machine.Restock(); AtmMachineManager manager = new AtmMachineManager(machine); string input = Console.ReadLine(); while (string.Compare(input, "Q", false) != 0) { manager.DoWork(input); input = Console.ReadLine(); } }
public static void Run() { AtmMachine atm = new AtmMachine(1000); Console.WriteLine("Testing state with right pin"); atm.InsertCard(); atm.EnterPinCode(123); atm.RequestCash(600); atm.EjectCard(); //Wrong pin Console.WriteLine("Testing state with wrong pin"); atm.InsertCard(); atm.EnterPinCode(890); atm.RequestCash(600); atm.EjectCard(); }
/// <summary> /// Initializes a new instance of the <see cref = "AtmViewModel" /> class. /// </summary> public AtmViewModel() { this.atmMachine = new AtmMachine(this); this.DisplayRow1 = "ATM Machine Simulator"; this.Level = TraceLevel.Info; this.DebugEvents = new ObservableCollection<Tuple<string, string>>(); // TODO remove this // Debug.Listeners.Add(this); this.ClearDebugEvents = new RelayCommand(this.ExecuteClearDebugEvents); this.PowerOnCommand = new RelayCommand(this.ExecutePowerOn, this.CanExecutePowerOn); this.PowerOffCommand = new RelayCommand(this.ExecutePowerOff, this.CanExecutePowerOff); this.InsertCardCommand = new RelayCommand(this.ExecuteInsertCard, this.CanExecuteInsertCard); this.RemoveCardCommand = new RelayCommand(this.ExecuteRemoveCard, this.CanExecuteRemoveCard); this.KeyPadCommand = new RelayCommand(this.ExecuteKeyPad, this.CanExecuteKeyPad); this.SideButtonCommand = new RelayCommand(this.ExecuteSideButton, this.CanExecuteSideButton); this.Write(TraceLevel.Info, "Click PowerOn to turn on the ATM machine"); }
/// <summary> /// Initializes a new instance of the <see cref = "AtmViewModel" /> class. /// </summary> public AtmViewModel() { this.atmMachine = new AtmMachine(this); this.DisplayRow1 = "ATM Machine Simulator"; this.Level = TraceLevel.Info; this.DebugEvents = new ObservableCollection <Tuple <string, string> >(); // TODO remove this // Debug.Listeners.Add(this); this.ClearDebugEvents = new RelayCommand(this.ExecuteClearDebugEvents); this.PowerOnCommand = new RelayCommand(this.ExecutePowerOn, this.CanExecutePowerOn); this.PowerOffCommand = new RelayCommand(this.ExecutePowerOff, this.CanExecutePowerOff); this.InsertCardCommand = new RelayCommand(this.ExecuteInsertCard, this.CanExecuteInsertCard); this.RemoveCardCommand = new RelayCommand(this.ExecuteRemoveCard, this.CanExecuteRemoveCard); this.KeyPadCommand = new RelayCommand(this.ExecuteKeyPad, this.CanExecuteKeyPad); this.SideButtonCommand = new RelayCommand(this.ExecuteSideButton, this.CanExecuteSideButton); this.Write(TraceLevel.Info, "Click PowerOn to turn on the ATM machine"); }
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 PowerOnAtmScenario() { // 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 { // Start the state machine until it goes idle with the PowerOff trigger enabled atmStateMachine.Start(AtmTrigger.PowerOff); // Validate the current state is what you think it is Assert.AreEqual(AtmState.InsertCard, atmStateMachine.State); // Will block until the transition can fire (or timeout) atmStateMachine.Fire(AtmTrigger.PowerOff); // WaitForComplete for the atmStateMachine workflow to complete atmStateMachine.WaitForComplete(); // 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); // Verify the prompts AssertHelper.OccursInOrder("Prompts", atm.DisplayedPrompts, Prompts.PleaseWait, Prompts.InsertCard); // Verify the exit action on Initialize and Entry action on PowerOff cleared the screen Assert.AreEqual(2, atm.ClearCount); } finally { tracking.Trace(); Trace.WriteLine(string.Empty); Trace.WriteLine("*** Workflow Definition ***"); Trace.WriteLine(XamlServices.Save(atmStateMachine.WorkflowStateMachine)); } }
public AccountTestsShould() { _sut = AccountBuilder.CreateCloseAccount(Money.Create(1000), "Germán Küber"); _atmMachine = new AtmMachine(_sut); }
public void EnterPinTriggerKeypadCancelToRemoveCard() { 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(); 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.Cancel().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, 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.KeypadCancel, AtmTransition.PowerOff); // Verify the prompts AssertHelper.OccursInOrder( "Prompts", testViewModel.Prompts.ConvertAll((prompt) => prompt.Text), Prompts.PleaseWait, Prompts.InsertCard, Prompts.EnterYourPin, Prompts.RemoveCard); // 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 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 AtmMachineProxy() { _machine = new AtmMachine(1000); }
public HasPinState(AtmMachine context) : base(context) { }
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)); } }
public AtmMachine SetNext(AtmMachine handler) => Handler = handler;
public AccountTestsShould() { _sut = new Account(false, false, 1000, "Germán Küber"); _atmMachine = new AtmMachine(_sut); }
public AtmMachineState(AtmMachine context) { _context = context; }
public HasCardState(AtmMachine context) : base(context) { }
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); } }