Ejemplo n.º 1
0
        public WithdrawalResponse Withdraw(decimal amount, string inputPin)
        {
            if (amount <= 0)
            {
                return(new WithdrawalResponse(WithdrawalStatus.Error, ErrorCodes.WithdrawalInvalidAmount));
            }

            if (!_pinValidationService.IsPinCorrect(Pin, inputPin))
            {
                // On a more fully fledged implementation I would keep track of pin attempts and block the card if exceeded
                return(new WithdrawalResponse(WithdrawalStatus.Error, ErrorCodes.InvalidPin));
            }

            if (amount <= Balance)
            {
                lock (_cardLock)
                {
                    if (amount <= Balance)
                    {
                        Balance -= amount;
                        return(new WithdrawalResponse(WithdrawalStatus.Successful));
                    }
                }
            }

            return(new WithdrawalResponse(WithdrawalStatus.InsufficientFunds));
        }
Ejemplo n.º 2
0
 public void Initialise()
 {
     _pinValidationService = Substitute.For <IPinValidationService>();
     _pinValidationService.RequiredPinDigits.Returns(4);
     _pinValidationService.GetEncryptedPin(TestPin).Returns(EncryptedPin.EncryptPin(TestPin));
     _pinValidationService.IsPinCorrect(Arg.Any <EncryptedPin>(), TestPin).Returns(true);
 }