public void TestDeposit() { ledger.CreateAccount("testUsername", "testPassword"); ledger.LogIn("testUsername", "testPassword"); Assert.AreEqual(0, ledger.GetCurrentBalance()); ledger.Deposit(100); Assert.AreEqual(100, ledger.GetCurrentBalance()); }
// Prompts the user from stdin to record a deposit on their account private static void Deposit(Services.BankLedger ledger) { Console.WriteLine("Enter amount to deposit:"); Console.WriteLine($"Type {EXIT_KEYWORD} to return to menu."); Console.Write("$"); var amount = 0.0; var input = Console.ReadLine(); // verifying user typed valid input (can be parsed as double and > 0, or exit keyword) while (!input.Equals(EXIT_KEYWORD, StringComparison.OrdinalIgnoreCase) && !(double.TryParse(input, out amount) && amount >= 0)) { Console.WriteLine(); Console.WriteLine("Invalid amount entered."); Console.WriteLine($"Enter an amount to deposit, or type {EXIT_KEYWORD} to return to menu:"); Console.Write("$"); input = Console.ReadLine(); } // don't deposit if they typed exit keyword if (!input.Equals(EXIT_KEYWORD, StringComparison.OrdinalIgnoreCase)) { ledger.Deposit(amount); Console.WriteLine(); Console.WriteLine($"Deposit successful. New account balance: {ledger.GetCurrentBalance()}"); } Console.WriteLine(); }
// Prompts the user from stdin to record a withdrawal from their account private static void Withdrawal(Services.BankLedger ledger) { Console.WriteLine("Enter amount to withdraw:"); Console.WriteLine($"Type {EXIT_KEYWORD} to return to menu."); Console.Write("$"); var amount = -1.0; var input = Console.ReadLine(); var currentBalance = ledger.GetCurrentBalance(); // TODO add regex for $xx.xx //verifying user typed valid input (can be parsed as double and > 0, or exit keyword) while (!input.Equals(EXIT_KEYWORD, StringComparison.OrdinalIgnoreCase) && !(double.TryParse(input, out amount) && amount <= currentBalance && amount >= 0)) { Console.WriteLine(); if (amount > 0) { // user entered amount greater than their balance. Reset amount to -1 to continue loop Console.WriteLine($"Insufficient funds to withdraw ${amount}"); amount = -1.0; } else { Console.WriteLine("Invalid amount entered."); } Console.WriteLine($"Enter an amount to withdraw, or type {EXIT_KEYWORD} to return to menu:"); Console.Write("$"); input = Console.ReadLine(); } // don't withdraw if they typed the exit keyword if (!input.Equals(EXIT_KEYWORD, StringComparison.OrdinalIgnoreCase)) { ledger.Withdrawal(amount); Console.WriteLine(); Console.WriteLine($"Withdrawal successful. New account balance: {ledger.GetCurrentBalance()}"); } Console.WriteLine(); }
// Prints the current user's balance to stdout private static void CheckBalance(Services.BankLedger ledger) { Console.WriteLine($"Current account balance: {ledger.GetCurrentBalance()}"); Console.WriteLine(); }