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()); }
private static void SetupWithdrawalScheme(WithdrawalType type) { //TODO : this is poor man's injection. For now, since its a basic application we can live without have a container and DI logic //to inject the scheme. Open to extension though. switch (type) { case WithdrawalType.PreferredDenominationRules: DenominationPreferenceRules rules = new DenominationPreferenceRules(new List <DenominationType> { DenominationType.TwentyPound }); withdrawalScheme = new WithdrawalByPreferedDenomination(moneyStore, rules); break; case WithdrawalType.LeastNumberOfItems: withdrawalScheme = new WithdrawalByLeastNumberOfItems(moneyStore); break; default: throw new Exception("This schema is not supported yet"); } }
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()); }