// 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(); }
public void TestDeposit_LoggedOut() { Assert.ThrowsException <NullReferenceException>(() => ledger.Deposit(0)); }