public ATMResponse GetAccountBalance(CustomerAccount account, Int32 pinNumber, out decimal accountBalance) { accountBalance = 0; if (IsPinValid(account, pinNumber)) { accountBalance = account.GetBalance(); return ATMResponse.SUCCESS; } return ATMResponse.ACCOUNT_ERR; }
public void ATMMachine_IfWitdrawalIsMoreThanATMHolds_ShouldReturnExpectedErrorCode(decimal openingBalance, Int32 accountNumber) { ATMMachine cashpoint = new ATMMachine(openingBalance); CustomerAccount customerAccount = new CustomerAccount(100m, accountNumber, 1234, 100); var amountToWithdraw = openingBalance + 1; decimal customerBalance; ATMResponse result = cashpoint.WithdrawFunds(amountToWithdraw, customerAccount, 1234, out customerBalance); Assert.That(result, Is.EqualTo(ATMResponse.ATM_ERR)); //also check that the opening balance is still the same ie no money has been removed Assert.That(cashpoint.MachineBalance, Is.EqualTo(openingBalance)); }
public void ATMMachine_WhenPinNumberIncorrect_ShouldReturndExpectedAccountErrorCode(decimal machineBalance, Int32 accountNumber, decimal accountBalance, decimal overDraft, Int32 realPinNumber, Int32 testPinNumber) { var cashPoint = new ATMMachine(machineBalance); var account = new CustomerAccount(accountBalance, accountNumber, realPinNumber, overDraft); decimal actualBalance; ATMResponse result = cashPoint.GetAccountBalance(account, testPinNumber, out actualBalance); Assert.That(result, Is.EqualTo(ATMResponse.ACCOUNT_ERR)); }
public void ATMMachine_WhenUserTriesToWithdrawMoreThantheirAccountTotal_ReturnsFundsError(decimal machineBalance, Int32 accountNumber, decimal initialAccountBalance, decimal overDraft, Int32 pinNumber) { var cashPoint = new ATMMachine(machineBalance); var account = new CustomerAccount(initialAccountBalance, accountNumber, pinNumber, overDraft); decimal excessiveWithdrawalAmount = initialAccountBalance + overDraft + 1; decimal customerBalance; ATMResponse result = cashPoint.WithdrawFunds(excessiveWithdrawalAmount, account, pinNumber, out customerBalance); Assert.That(result, Is.EqualTo(ATMResponse.FUNDS_ERR)); Assert.That(account.GetWithdrawalBalance(), Is.EqualTo(initialAccountBalance + overDraft)); }
public ATMResponse WithdrawFunds(decimal withdrawalAmount, CustomerAccount account, Int32 pinNumber, out decimal accountBalance) { accountBalance = 0; if (!IsPinValid(account, pinNumber)) return ATMResponse.ACCOUNT_ERR; // check if the cashmachine has enough cash for the withdrawal request if (withdrawalAmount > _machineBalance) return ATMResponse.ATM_ERR; if (withdrawalAmount <= account.GetWithdrawalBalance()) { account.WithdrawFunds(withdrawalAmount); accountBalance = account.GetBalance(); } else { return ATMResponse.FUNDS_ERR; } return ATMResponse.SUCCESS; }
public void ATMMachine_TestData_ProducesExpectedOutcome(Int32 accountNumber, decimal initialAccountBalance, decimal overDraft, Int32 pinNumber, decimal withdrawalAmount) { var cashPoint = new ATMMachine(8000m); var customerAccount = new CustomerAccount(initialAccountBalance, accountNumber, pinNumber, overDraft); decimal customerBalance; ATMResponse balanceResponse = cashPoint.GetAccountBalance(customerAccount, pinNumber, out customerBalance); Assert.That(customerBalance, Is.EqualTo(initialAccountBalance)); Console.WriteLine(string.Format("InitialBalance: {0}", customerBalance)); Console.WriteLine(String.Format("ResultCode {0}", balanceResponse)); ATMResponse withdrawalResponse = cashPoint.WithdrawFunds(withdrawalAmount, customerAccount, pinNumber,out customerBalance); Console.WriteLine(String.Format("Withdrawawl Amount: {0}", withdrawalAmount)); Console.WriteLine(String.Format("Balance AfterWithdrawal {0}", customerBalance)); Console.WriteLine(String.Format("ResultCode: {0}", withdrawalResponse)); }
private bool IsPinValid(CustomerAccount account, int pinNumber) { return account.IsValid(pinNumber); }