Exemple #1
0
        public void ShouldNotAllowToWithdrawIfAtmOutOfMoney_SchemeLeastNumberOfItems()
        {
            AtmMoneyStore    moneyStore = new AtmMoneyStore();
            WithdrawalScheme withdrawal = new WithdrawalByLeastNumberOfItems(moneyStore);

            Assert.Throws <OutOfMoneyException>(() => withdrawal.Withdraw(5000));
        }
        public void ShouldWithdrawReturningLeastNumberOfNotesOrCoins(double amountToWithdraw, double balance, params object[] denominations)
        {
            AtmMoneyStore moneyStore = new AtmMoneyStore();
            IWithdrawal   withdrawal = new WithdrawalByLeastNumberOfItems(moneyStore);

            Cash cash = withdrawal.Withdraw(amountToWithdraw);

            Assert.Equal(denominations.Length / 2, cash.CoinOrNotes.Count);

            for (int i = 0; i < denominations.Length; i++)
            {
                if (i % 2 == 0)
                {
                    var type  = (DenominationType)denominations[i];
                    var count = (int)denominations[i + 1];
                    Assert.Equal(count, cash.CoinOrNotes.Find(c => c.Type == type)?.Count);
                }
            }

            Assert.Equal(balance, moneyStore.GetBalance());
        }