コード例 #1
0
 public void Init()
 {
     _vendingMachine = new VendingMachineObj();
     _bankAccount    = new BankAccount();
     _cashCardA      = new CashCard(_bankAccount);
     _cashCardB      = new CashCard(_bankAccount);
 }
コード例 #2
0
 private void BuyCans(int cansnumber, ICashCard card, int pinCode)
 {
     while (cansnumber > 0)
     {
         _vendingMachine.BuyCan(card, pinCode);
         cansnumber--;
     }
 }
コード例 #3
0
 public void ProcessOrder(ICashCard cashCard, int pin, int quantity)
 {
     if (VerifyAccount(cashCard.Account, pin))
     {
         _orderManager.UpdateAccountAndInventory(this, quantity);
     }
     else
     {
         throw new InvalidAccountCredentialsException();
     }
 }
コード例 #4
0
        public void BuyCan(ICashCard cashCard, int pin)
        {
            if (pin == cashCard.PinCode)
            {
                lock (this)
                {
                    if (_inventory > 0)
                    {
                        cashCard.WithdrawFromAccount(CAN_PRICE);
                        _inventory--;
                    }
                }

                Console.WriteLine("Correct pin");
            }
            else
            {
                Console.WriteLine("Wrong pin");
            }
            Console.WriteLine(string.Format("Cans remaining: {0}", CansInventory));
        }
コード例 #5
0
 public User(ICashCard cashCardA, ICashCard cashCardB)
 {
     CashCardA = cashCardA;
     CashCardB = cashCardB;
 }
コード例 #6
0
 private void BuyCansWithCorrectPin(int cansnumber, ICashCard card)
 {
     BuyCans(cansnumber, card, card.PinCode);
 }
コード例 #7
0
        private void BuyCansWithInCorrectPin(int cansnumber, ICashCard card)
        {
            var differentPin = card.PinCode == 1000 ? 1001 : 1000;

            BuyCans(cansnumber, card, differentPin);
        }