Ejemplo n.º 1
0
        public void ShouldNotAllowToWithdrawIfAtmOutOfMoney_SchemeLeastNumberOfItems()
        {
            AtmMoneyStore    moneyStore = new AtmMoneyStore();
            WithdrawalScheme withdrawal = new WithdrawalByLeastNumberOfItems(moneyStore);

            Assert.Throws <OutOfMoneyException>(() => withdrawal.Withdraw(5000));
        }
Ejemplo n.º 2
0
        public void ShouldNotAllowToWithdrawIfAtmOutOfMoney_SchemePreferedDenomination()
        {
            AtmMoneyStore    moneyStore = new AtmMoneyStore();
            WithdrawalScheme withdrawal = new WithdrawalByPreferedDenomination(moneyStore, null);

            Assert.Throws <OutOfMoneyException>(() => withdrawal.Withdraw(5000));
        }
Ejemplo n.º 3
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());
        }
        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());
        }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
0
 private static void SetupMachineFirstTime()
 {
     Console.WriteLine("Initialising money store for the first time...");
     moneyStore = new AtmMoneyStore();
     Console.WriteLine($"Available balance is : {moneyStore.GetBalance()}");
 }
        public void ShouldShowAvailableBalanceOnStarupCorrectly()
        {
            AtmMoneyStore moneyStore = new AtmMoneyStore();

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