Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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));
        }