Пример #1
0
        public void ShouldNotAllowToWithdrawIfAtmOutOfMoney_SchemePreferedDenomination()
        {
            AtmMoneyStore    moneyStore = new AtmMoneyStore();
            WithdrawalScheme withdrawal = new WithdrawalByPreferedDenomination(moneyStore, null);

            Assert.Throws <OutOfMoneyException>(() => withdrawal.Withdraw(5000));
        }
Пример #2
0
        public void ShouldDispenseMostTenPoundNotes(double amountToWithdraw, double balance)
        {
            var rules = new DenominationPreferenceRules(new List <DenominationType> {
                DenominationType.TenPound
            });
            AtmMoneyStore moneyStore = new AtmMoneyStore();
            IWithdrawal   withdrawal = new WithdrawalByPreferedDenomination(moneyStore, rules);

            Cash cash = withdrawal.Withdraw(amountToWithdraw);

            Assert.Equal(DenominationType.TenPound, cash.CoinOrNotes.SingleOrDefault().Type);
            Assert.Equal(12, cash.CoinOrNotes.FirstOrDefault().Count);
            Assert.Equal(10, cash.CoinOrNotes.FirstOrDefault().Value);
            Assert.Equal(balance, moneyStore.GetBalance());
        }
Пример #3
0
        public void ShouldDispenseMostTwentyPoundNotes(double amountToWithdraw, double balance, params object[] denominations)
        {
            var rules = new DenominationPreferenceRules(new List <DenominationType> {
                DenominationType.TwentyPound
            });
            AtmMoneyStore moneyStore = new AtmMoneyStore();
            IWithdrawal   withdrawal = new WithdrawalByPreferedDenomination(moneyStore, rules);

            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());
        }