Ejemplo n.º 1
0
        public Task <bool> DoesAccountHaveBalance(CashCard cashCard)
        {
            var result = _accountRepo.GetAccountBalance(cashCard.AccountNumber);

            if (result >= 0.5m)
            {
                return(Task.FromResult <bool>(true));
            }
            else
            {
                return(Task.FromResult <bool>(false));
            }
        }
Ejemplo n.º 2
0
        public void BuyCan(CashCard cashCard)
        {
            if (isEmpty())
            {
                throw new VendingMachineEmptyException();
            }

            if (!cashCard.HasSufficientFundsFor(PriceOfCan))
            {
                throw new InsufficientFundsException();
            }

            cashCard.Deduct(PriceOfCan);

            if (isThreadSafe)
            {
                Interlocked.Decrement(ref _inventory);
            }
            else
            {
                _inventory--;
            }
        }
Ejemplo n.º 3
0
        public Task <bool> Vend(CashCard cashCard, int PinNumber)
        {
            var isVendingSuccess = false;

            // No point proceeding if PIN is incorrect
            if (_cardManager.IsAuthorised(cashCard, PinNumber))
            {
                var isVendingPossible  = _inventoryManager.IsVendingPossible();
                var doesAccHaveBalance = _accountManager.DoesAccountHaveBalance(cashCard);


                if (isVendingPossible.Result && doesAccHaveBalance.Result)
                {
                    var updateAccount   = _accountManager.UpdateAccount(cashCard);
                    var updateInventory = _inventoryManager.UpdateInventory();
                    if (updateAccount && updateInventory)
                    {
                        isVendingSuccess = true;
                    }
                }
            }

            return(Task.FromResult <bool>(isVendingSuccess));
        }
Ejemplo n.º 4
0
 public bool UpdateAccount(CashCard card)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 5
0
 public bool IsAuthorised(CashCard cashCard, int pin)
 {
     return(_cashCardRepo.IsAuthorised(cashCard.CardNumber, pin));
 }