public void BasicAccountWithdrawRuleTest(string acctNum, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdraw RuleTest = new BasicAccountWithdrawRule(); Account acct = new Account() { AccountNumber = acctNum, Name = name, Balance = balance, Type = accountType }; AccountWithdrawResponse response = RuleTest.Withdraw(acct, amount); bool actual = response.Success; Assert.AreEqual(expectedResult, actual); }
public void BasicAccountWithdrawRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal expectedBalance, bool expectedResult) { IWithdraw withdrawResponse = new FreeAccountWithdrawlRule(); Account accountVariable = new Account() { AccountNumber = accountNumber, Name = name, Balance = balance, Type = accountType }; AccountWithdrawResponse accountWithdrawResponse = withdrawResponse.Withdraw(accountVariable, amount); Assert.AreEqual(expectedResult, accountWithdrawResponse.Success); Assert.AreEqual(expectedBalance, accountWithdrawResponse.Account.Balance); }
[TestCase("33333", "Basic Account", 100, AccountType.Basic, -150, -60, true)] //pass, overdraft fee deducted public void BasicAccountWithdrawRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdraw withdraw = new BasicAccountWithdrawRule(); Account account = new Account { AccountNumber = accountNumber, Balance = balance, Name = name, Type = accountType }; AccountWithdrawResponse response = withdraw.Withdraw(account, amount); Assert.AreEqual(expectedResult, response.Success); Assert.AreEqual(newBalance, response.Account.Balance); }
public void FreeAccountWithdrawRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, bool expectResult) { IWithdraw rule = new FreeAccountWithdrawRule(); Account account = new Account(); account.AccountNumber = accountNumber; account.Balance = balance; account.Name = name; account.Type = accountType; AccountWithdrawResponse response = rule.Withdraw(account, amount); Assert.AreEqual(expectResult, response.Success); }
public void PremiumAccountWithdrawRuleTest(string accountNumber, string Name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdraw withdraw = new PremiumAccountWithdrawRule(); Account account = new Account(); account.Name = Name; account.AccountNumber = accountNumber; account.Balance = balance; account.Type = accountType; AccountWithdrawResponse response = withdraw.Withdraw(account, amount); Assert.AreEqual(expectedResult, response.Success); }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); if (account.Type != AccountType.Basic) { response.Success = false; response.Message = "Error: a non-basic account hit the basic Withdraw Rule, Contact IT"; return(response); } if (amount >= 0) { response.Success = false; response.Message = "Withdrawal amounts must be negative"; return(response); } if (amount < -500) { response.Success = false; response.Message = "Basic accounts cannot withdraw more than $500!"; return(response); } if (account.Balance + amount < -100) { response.Success = false; response.Message = "This amount with overdraft more than your $100 dollar limit"; return(response); } response.OldBalance = account.Balance; account.Balance = account.Balance + amount; response.Account = account; if (account.Balance < 0) { Console.WriteLine("Looks like someone has an overdraft fee"); account.Balance = account.Balance - 10; } response.amount = amount; response.Success = true; return(response); }
public void PremiumAccountWithdrawTests(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdraw premiumWithdraw = new PremiumAccountWithdrawRule(); Account account = new Account() { AccountNumber = accountNumber, Name = name, Balance = balance, Type = accountType }; AccountWithdrawResponse result = premiumWithdraw.Withdraw(account, amount); var actual = result.Success; var actual2 = account.Balance; Assert.AreEqual(expectedResult, actual); Assert.AreEqual(newBalance, actual2); }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); if (account.Type != AccountType.Basic) { response.Success = false; response.Message = "Withdrawal amounts must be negative!"; return(response); } if (amount >= 0) { response.Success = false; response.Message = "Withdrawal amounts must be negative!"; return(response); } if (amount < -500) { response.Success = false; response.Message = "Basic accounts cannot withdraw more than $500!"; return(response); } if (account.Balance + amount < -100) { response.Success = false; response.Message = "This amount will overdraft your account by more than your $100 limit!"; return(response); } response.Success = true; response.Account = account; response.Amount = amount; response.OldBalance = account.Balance; response.Account.Balance += amount; if (response.Account.Balance < 0) { response.Account.Balance -= 10; Console.WriteLine("\nBalance was reduced by an additional $10 due to overdraft fee!"); } return(response); }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); if (account.Type != AccountType.Basic) { response.Success = false; response.Message = "Error: a non-basic account hit the Basic Withdraw Rule. Contact IT"; return(response); } if (amount >= 0) { response.Success = false; response.Message = "Withdrawal amounts must be negative!"; return(response); } if (amount < -500) { response.Success = false; response.Message = "Basic accounts cannot withdraw more than $500!"; return(response); } if (amount + account.Balance < -100) { response.Success = false; response.Message = "This amount will overdraft more than your $100 limit!"; return(response); } response.OldBalance = account.Balance; account.Balance += amount; response.Account = account; response.Amount = amount; response.Success = true; if (account.Balance < 0) { account.Balance -= 10; } return(response); }
[TestCase("44444", "Premium Account", 100, AccountType.Premium, -10, true)] //sucessful withdrawal //sucessful withdrawal public void PremiumAccountWithdrawalTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, bool expectedResult) { IWithdraw withdraw = new PremiumAccountWithdrawRule(); Account account = new Account() { Name = name, AccountNumber = accountNumber, Balance = balance, Type = accountType }; AccountWithdrawResponse response = withdraw.Withdraw(account, amount); Assert.AreEqual(expectedResult, response.Success); }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); response.Account = account; response.OldBalance = account.Balance; if (account.Type != AccountType.Basic) { response.Success = false; Console.WriteLine("“Error: a non-basic account hit the Basic Withdraw Rule. Contact IT"); return(response); } if (amount >= 0) { response.Success = false; Console.WriteLine("Withdrawal amounts must be negative!"); return(response); } if (amount < -500) { response.Success = false; Console.WriteLine("Free accounts cannot withdraw more than $500!"); return(response); } if ((amount + account.Balance) < -100) { response.Success = false; Console.WriteLine("Basic accounts cannot overdraft more than 100 dollar limit!"); return(response); } else { account.Balance += amount; if (account.Balance < 0) { account.Balance -= 10; Console.WriteLine(account.Balance); Console.WriteLine("Negative balance so here is a 10 dollar overdraft fee"); } response.Amount = amount; response.Success = true; return(response); } }
public void Execute() { AccountManager accountManager = AccountManagerFactory.Create(); Console.Clear(); Console.Write("Enter an account number: "); string accountNumber = Console.ReadLine(); decimal amount; while (true) { Console.Write("Enter a withdrawal amount: "); string input = Console.ReadLine(); bool result = decimal.TryParse(input, out amount); if (result) { break; } Console.WriteLine("Please enter a valid amount."); Console.WriteLine("Press any key to continue...."); Console.ReadKey(); } AccountWithdrawResponse response = accountManager.Withdraw(accountNumber, amount); if (response.Success) { Console.WriteLine("Withdraw Completed!"); Console.WriteLine($"Account Number: {response.Account.AccountNumber}"); Console.WriteLine($"Old balance: {response.OldBalance:C}"); Console.WriteLine($"Amount withdrawn: {response.Amount:C}"); Console.WriteLine($"New balance: {response.Account.Balance:C}"); } else { Console.Write("An error occured: "); Console.WriteLine(response.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); if (account.Type != AccountType.Basic) { response.Success = false; response.Account = account; response.Message = "Error: a non-basic account hit the basic withdraw rule. Contact IT."; return(response); } if (amount >= 0) { response.Success = false; response.Account = account; response.Message = "Error: withdrawal amounts must be negative."; return(response); } if (amount < -500) { response.Success = false; response.Account = account; response.Message = "Error: basic accounts cannot withdraw more than $500 at once."; return(response); } if (amount + account.Balance < -100) { response.Success = false; response.Account = account; response.Message = "Error: basic account cannot overdraft more than $100."; return(response); } response.Success = true; response.Account = account; response.Amount = amount; response.OldBalance = account.Balance; account.Balance += amount; if (account.Balance < 0) { account.Balance -= 10; } return(response); }
public void BasicAccountWithdrawRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdraw withdraw = new BasicAccountWithdrawRule(); Account account = new Account(); account.AccountNumber = accountNumber; account.Name = name; account.Balance = balance; account.Type = accountType; AccountWithdrawResponse response = withdraw.IWithdraw(account, amount); response.Account = account; response.Amount = amount; Assert.AreEqual(response.Success, expectedResult); Assert.AreEqual(response.Account.Balance, newBalance); }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); if (account.Type != AccountType.Basic) { response.Success = false; response.Message = "Error: a non-basic account hit the Basic Withdraw Rule. Contact IT"; return(response); } else if (amount >= 0) { response.Success = false; response.Message = "Withdrawal amounts must be negative!"; return(response); } else if (amount < -500) { response.Success = false; response.Message = "Basic accounts cannot withdraw more than $500!"; return(response); } else if ((account.Balance + amount) < -100) { response.Success = false; response.Message = "This amount will overdraft more than your $100 limit!"; return(response); } response.Success = true; response.Account = account; response.Amount = amount; response.OldBalance = account.Balance; account.Balance += amount; if (account.Balance < 0.00M) { decimal overdraft = 10.00M; account.Balance -= overdraft; Console.WriteLine("A $10 overdraft fee was applied."); } return(response); }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); if (account.Type != AccountType.Free) { response.Success = false; response.Message = "Error: a non-free account hit the Free Withdraw Rule. Contact IT"; return(response); } if (amount >= 0) { response.Success = false; response.Message = "Withdrawal amounts must be negative!"; return(response); } if (amount < -100) { response.Success = false; response.Message = "Free accounts cannot withdraw more than $100!"; return(response); } // huh??? if ((account.Balance += amount) < 0) { response.Success = false; response.Message = "Free accounts cannot overdraft!"; return(response); } response.Success = true; response.account = account; response.Amount = amount; response.OldBalance = account.Balance; account.Balance = (account.Balance + amount); return(response); }
public void Execute() { string amountToParse; decimal amount; bool parse; do { Console.Clear(); AccountManager accountManager = AccountManagerFactory.Create(); Console.WriteLine("Enter an account number: "); string accountNumber = Console.ReadLine(); Console.Write("Enter a withdraw(-) amount: "); amountToParse = Console.ReadLine(); parse = decimal.TryParse(amountToParse, out amount); if (parse) { AccountWithdrawResponse response = accountManager.Withdraw(accountNumber, amount); if (response.Success) { Console.WriteLine("Withdraw completed!"); Console.WriteLine($"Account Number: {response.Account.AccountNumber}"); Console.WriteLine($"Old balance: {response.OldBalance:c}"); Console.WriteLine($"Amount Withdrawn: {response.Amount:c}"); Console.WriteLine($"New balance: {response.Account.Balance:c}"); } else { Console.WriteLine("An error occurred: "); Console.WriteLine(response.Message); } } else { Console.WriteLine("Error with amount. Please enter a decimal."); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } } while (!parse); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); if (account.Type != AccountType.Basic) { response.Success = false; response.Message = ("Error: a non-basic account hit the Basic Withdraw Rule. Contact IT"); return(response); } else if (amount >= 0) { response.Success = false; response.Message = ("Withdrawal amounts gotta be negative!"); return(response); } else if (amount < -500) { response.Success = false; response.Message = "You can't take out that much money. Basic accounts are limited to $500 withdrawals"; return(response); } else if (account.Balance + amount < -100) { response.Success = false; response.Message = "This amount will overdraft more than your $100 limit"; return(response); } else { response.Success = true; response.Account = account; response.Amount = amount; response.OldBalance = account.Balance; account.Balance += amount; if (account.Balance < 0) //gettin dat overdraft fee { account.Balance -= 10; } return(response); } }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); if (account.Type != AccountType.Basic) { response.Success = false; response.Message = "Error: a non-basic account hit the Basic Withdraw Rule. \nContact IT!"; return(response); } if (amount >= 0M) { response.Success = false; response.Message = "Withdrawl amounts must be negativ!"; return(response); } if (amount < -500M) { response.Success = false; response.Message = "Basic accounts cannot withdraw more than $500 at a time!"; return(response); } if (account.Balance + amount < -100) { response.Success = false; response.Message = "Basic accounts have a $100 overdraft limit!"; return(response); } response.OldBalance = account.Balance; account.Balance += amount; if (account.Balance < 0) { account.Balance -= 10M; //Basic accounts have a $10 fee for overdrafts } response.Account = account; response.Amount = amount; response.Success = true; return(response); }
public void PremiumAccountWithdrawRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdraw ruke = new BasicAccountWithdrawRule(); Account juke = new Account(); juke.AccountNumber = accountNumber; juke.Name = name; juke.Balance = balance; juke.Type = accountType; AccountWithdrawResponse adr = ruke.Withdraw(juke, amount); Assert.AreEqual(expectedResult, adr.Success); if (adr.Success == true) { Assert.AreEqual(newBalance, balance); } ; }
public void Execute() { Console.Clear(); AccountManager accountManager = AccountManagerFactory.Create(); Console.Write("Enter an account number: "); string accountNumber = Console.ReadLine(); bool validWithdraw = false; decimal amount; while (true) { Console.Write("Enter a withdraw amount: "); validWithdraw = decimal.TryParse(Console.ReadLine(), out amount); if (validWithdraw == false) { Console.WriteLine("Please enter a valid number"); } else { break; } } AccountWithdrawResponse response = accountManager.Withdraw(accountNumber, amount); if (response.Success) { Console.WriteLine("Withdraw completed!"); Console.WriteLine($"Account Number: {response.Account.AccountNumber}"); Console.WriteLine($"Old balance: {response.OldBalance:c}"); Console.WriteLine($"Amount Deposited: {response.Amount:c}"); Console.WriteLine($"New balance: {response.Account.Balance:c}"); } else { Console.WriteLine("An error occurred: "); Console.WriteLine(response.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public void Execute() { Console.Clear(); AccountManager accountManager = AccountManagerFactory.Create(); Console.Write("Enter an account number: "); string accountNumber = Console.ReadLine(); Console.Write("Enter a withdrawal amount: "); bool validInput = ConsoleIO.TryParseCurrency(Console.ReadLine(), out decimal amount); AccountWithdrawResponse response; if (validInput) { response = accountManager.Withdraw(accountNumber, amount); } else { response = new AccountWithdrawResponse() { Success = false, Message = "Withdrawal amount was not formatted correctly" }; } if (response.Success) { Console.WriteLine("Withdrawal completed!"); Console.WriteLine($"Account Number: {response.Account.AccountNumber}"); Console.WriteLine($"Old balance: {response.OldBalance:c}"); Console.WriteLine($"Amount Withdrawn: {response.Amount:c}"); Console.WriteLine($"New balance: {response.Account.Balance:c}"); } else { Console.WriteLine("An error occurred: "); Console.WriteLine(response.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
[TestCase("99999", "Basic Account", 100, AccountType.Premium, -600, -500, true)] //Success!!! Also verify that there is NO overdraft fee... public void PremiumAccountWithdrawRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdraw myWithdrawRule = new PremiumAccountWithdrawRule(); Account myAccount = new Account() { AccountNumber = accountNumber, Name = name, Balance = balance, Type = accountType }; AccountWithdrawResponse response = myWithdrawRule.Withdraw(myAccount, amount); Assert.AreEqual(expectedResult, response.Success); if (response.Success) { Assert.AreEqual(newBalance, response.Account.Balance); } ; }
public void BasicAccountWithdrawtRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdraw withdraw = new BasicAccountWithdrawalRule(); Account account = new Account(); account.Type = accountType; account.AccountNumber = accountNumber; account.Name = name; account.Balance = balance; AccountWithdrawResponse response = withdraw.Withdraw(account, amount); Assert.AreEqual(expectedResult, response.Success); if (response.Success == true) { Assert.AreEqual(newBalance, actual: account.Balance); } }
public void Execute() { Console.Clear(); AccountManager accountManager = AccountManagerFactory.Create(); Console.Write("Enter an account number: "); string accountNumber = Console.ReadLine(); bool parsedDecimal = true; decimal amount; do { Console.Write("Enter a deposit withdraw: "); decimal result; bool parsed = decimal.TryParse(Console.ReadLine(), out result); if (parsed) { parsedDecimal = false; } amount = result; } while (parsedDecimal); AccountWithdrawResponse response = accountManager.Withdraw(accountNumber, amount); if (response.Success) { Console.WriteLine("Withdraw completed!"); Console.WriteLine($"Account Number: {response.Account.AccountNumber}"); Console.WriteLine($"Old balance: {response.OldBalance:c}"); Console.WriteLine($"Amount Withdrawn: {response.Amount:c}"); Console.WriteLine($"New balance: {response.Account.Balance:c}"); } else { Console.WriteLine("An error occurred: "); Console.WriteLine(response.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public void PremiumAccountWithdrawRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalence, bool expectedResult) { Account account = new Account(); account.AccountNumber = accountNumber; account.Name = name; account.Balance = balance; account.Type = accountType; IWithdraw manager = new PremiumAccountWithdrawRule(); AccountWithdrawResponse response = manager.Withdraw(account, amount); Assert.AreEqual(expectedResult, response.Success); if (response.Success) { Assert.AreEqual(newBalence, account.Balance); } }
public void BasicAccountWithdrawRuleTest(string accountNumber, string name, decimal balance, AccountType accountType, decimal amount, decimal newBalance, bool expectedResult) { IWithdraw withdraw; BasicAccountWithdrawRule basicAccountWithdrawRule = new BasicAccountWithdrawRule(); withdraw = basicAccountWithdrawRule; Account account = new Account { Name = name, Balance = balance, AccountNumber = accountNumber, Type = accountType }; AccountWithdrawResponse actualResult = withdraw.Withdraw(account, amount); Assert.AreEqual(expectedResult, actualResult.Success); }
public AccountWithdrawResponse Withdraw(string accountNumber, decimal amount) { AccountWithdrawResponse response = new AccountWithdrawResponse(); response.Account = _accountRepository.LoadAccount(accountNumber); if (response.Account == null) { response.Success = false; response.Message = "Invalid account number"; return(response); } IWithdraw withdraw = WithdrawRulesFactory.Create(response.Account.Type); response = withdraw.Withdraw(response.Account, amount); if (response.Success) { _accountRepository.SaveAccount(response.Account); } return(response); }
public AccountWithdrawResponse Withdraw(Account account, decimal amount) { AccountWithdrawResponse accountWithdrawResponse = new AccountWithdrawResponse(); if (account.Type != AccountType.Basic) { accountWithdrawResponse.Message = "ERROR: Contact IT"; accountWithdrawResponse.Success = false; return(accountWithdrawResponse); } if (amount > 0) { accountWithdrawResponse.Success = false; accountWithdrawResponse.Message = "ERROR: Withdrawl must be negative"; return(accountWithdrawResponse); } if (amount < -500) { accountWithdrawResponse.Message = "ERROR: Withdrawl limited to -$500 per withdrawl"; accountWithdrawResponse.Success = false; return(accountWithdrawResponse); } if (account.Balance + amount < -100) { accountWithdrawResponse.Message = "ERROR: Basic accounts have -$100 overdraft limit"; accountWithdrawResponse.Success = false; return(accountWithdrawResponse); } accountWithdrawResponse.Success = true; accountWithdrawResponse.Amount = amount; accountWithdrawResponse.Account = account; accountWithdrawResponse.OldBalance = account.Balance; accountWithdrawResponse.Account.Balance += amount; if (accountWithdrawResponse.Account.Balance < 0) { accountWithdrawResponse.Account.Balance += -10; } return(accountWithdrawResponse); }
public void Execute() { Console.Clear(); AccountManager accountManager = AccountManagerFactory.Create(); Console.Write("Enter an account number: "); string accountNumber = Console.ReadLine(); bool validWithdraw; decimal withdrawAmount; do { validWithdraw = true; Console.Write("Enter a deposit amount: "); validWithdraw = decimal.TryParse(Console.ReadLine(), out withdrawAmount); if (!validWithdraw) { Console.WriteLine("Withdrawal amount must be a number!"); } } while (validWithdraw == false); AccountWithdrawResponse response = accountManager.Withdraw(accountNumber, withdrawAmount); if (response.Success) { Console.WriteLine("Withdraw completed!"); Console.WriteLine($"Account number: {response.Account.AccountNumber}"); Console.WriteLine($"Old balance: {response.OldBalance:c}"); Console.WriteLine($"Amount withdrawn: {response.Amount:c}"); Console.WriteLine($"New balance: {response.Account.Balance:c}"); } else { Console.Write("An error occured: "); Console.WriteLine(response.Message); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }