public void InitializeTest()
        {
            var hasher  = new PasswordHasher <string>();
            var manager = new AccountManager(hasher);

            ledger = new BankLedger.Services.BankLedger(manager);
        }
Exemple #2
0
        // 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();
        }
Exemple #3
0
        // Prompts the user from stdin to create a new account
        private static void CreateAccount(Services.BankLedger ledger)
        {
            Console.WriteLine();
            Console.WriteLine($"Enter your desired username (or \"{EXIT_KEYWORD}\" to return to the main menu):");
            var username = Console.ReadLine();

            // verifying account doesn't already exist with given username
            while (!username.Equals(EXIT_KEYWORD, StringComparison.OrdinalIgnoreCase) && ledger.UserExists(username))
            {
                Console.WriteLine($"Username {username} is already taken. Please enter a different username:"******"Enter your desired password:"******"Re-enter your password:"******"The passwords you entered did not match. Please try again.");
                    Console.WriteLine("Enter your desired password:"******"Re-enter your password:"******"Account successfully created! Please log in.");
                Console.WriteLine();
            }
        }
Exemple #4
0
        /// <summary>
        /// Gets an action from stdin that the user wishes to perform on
        /// their account.
        /// </summary>
        /// <param name="ledger">The BankLedger used to manage user accounts</param>
        /// <returns>The action the user wishes to take</returns>
        private static UserAction GetUserAccountAction(Services.BankLedger ledger)
        {
            PrintUserWelcome(ledger);
            var option = 0;

            while (!Int32.TryParse(Console.ReadLine(), out option) || option < 1 || option > 5)
            {
                PrintUserError();
            }
            Console.WriteLine();
            // adding two to ignore first to UserActions, LogIn and CreateAccount
            return((UserAction)(option + 2));
        }
Exemple #5
0
        // Prints the current users's transaction history to stdout
        private static void PrintTransactions(Services.BankLedger ledger)
        {
            Console.WriteLine("Transaction history:");
            var transactions = ledger.GetTransactionHistory();

            foreach (var transaction in transactions)
            {
                Console.WriteLine($"{transaction.Time.ToLocalTime()}: {transaction.Action}");
                if (null != transaction.Description)
                {
                    Console.WriteLine($"\t{transaction.Description}");
                    Console.WriteLine();
                }
            }
            Console.WriteLine();
        }
Exemple #6
0
        // 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();
        }
Exemple #7
0
        // Logs in the user using the given BankLedger by prompting for their username
        // and password until a successful match is found (or the user decides to exit).
        private static void LogIn(Services.BankLedger ledger)
        {
            // initial prompt to log in
            Console.WriteLine();
            Console.WriteLine($"Enter your username (or \"{EXIT_KEYWORD}\" to return to the main menu):");
            var username = Console.ReadLine();

            if (!username.Equals(EXIT_KEYWORD, StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine("Enter your password:"******"Invalid username/password combination, or account does not exist. Please try again.");
                    Console.WriteLine($"If you need to create an account, type \"{EXIT_KEYWORD}\" to return to the main menu.");
                    Console.WriteLine();
                    Console.WriteLine("Enter your username:"******"Enter your password:"******"Returning to main menu...");
                Console.WriteLine();
            }
        }
 public void Cleanup()
 {
     ledger = null;
 }
Exemple #9
0
 private static void PrintUserWelcome(Services.BankLedger ledger)
 {
     Console.WriteLine($"Welcome {ledger.GetCurrentUser()}! Please choose one of the following options:");
     PrintAccountOptions();
 }
Exemple #10
0
 // Logs out the current user from the system
 private static void LogOut(Services.BankLedger ledger)
 {
     Console.WriteLine("Logging out...");
     Console.WriteLine();
     ledger.LogOut();
 }
Exemple #11
0
 // Prints the current user's balance to stdout
 private static void CheckBalance(Services.BankLedger ledger)
 {
     Console.WriteLine($"Current account balance: {ledger.GetCurrentBalance()}");
     Console.WriteLine();
 }