public AccountWithdrawalResponse Withdraw(string accountNumber, decimal amount) { AccountWithdrawalResponse response = new AccountWithdrawalResponse { Success = false, Account = _accountRepository.LoadAccount(accountNumber) }; if (response.Account == null) { response.Message = $"{accountNumber} is not a valid account."; } else { //var someThing = DIContainer.Kernel.GetBindings(DIContainer.Kernel.GetService().Withdraw() IWithdrawal depositRule = WithdrawalRulesFactory.Create(response.Account.Type); response = depositRule.Withdraw(response.Account, amount); } if (response.Success) { _accountRepository.SaveAccount(response.Account); } return(response); }
[TestCase("33333", "BasicAccount", 100, AccountType.Basic, 150, -60, true)] //Pass, Overdraft public void BasicAccount_WithdrawalRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdrawal withdrawalRule = WithdrawalRulesFactory.Create(AccountType.Basic); Account account = new Account() { AccountNumber = accountNumber, Balance = balance, Name = name, Type = accountType }; AccountWithdrawalResponse response = withdrawalRule.Withdraw(account, amount); Assert.AreEqual(expectedResult, response.Success); }