Esempio n. 1
0
        public void TestGetSpecificCustomerAccount_GetSpecificAccountWhenNameMatches_SpecificAccountWithMatchingName()
        {
            #region Arrange
            BankHandler bankHandler = new BankHandler();
            #endregion

            #region Act
            Account account = bankHandler.GetSpecificCustomerAccount("Vacation savings");
            string result = account.GetAccountName();
            string expected = "Vacation savings";
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            #endregion
        }
Esempio n. 2
0
        public void TestAddAccountToCustomer_AddOneAccount_ListWithTwoAccounts()
        {
            #region Arrange
            //The BankHandler constructor adds a customer with one account, named "Vacation savings"
            BankHandler bankHandler = new BankHandler();
            Account account = new Account("Gasoline account", 2500, false);
            #endregion

            #region Act
            bankHandler.AddAccountToCustomer(account);
            int result = bankHandler.GetAllCustomerAccounts().Count;
            int expected = 2;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            #endregion
        }
Esempio n. 3
0
        public void TestGetAllCustomerAccounts_GetAllAccountsWhenThreeAccounts_ListWithThreeAccounts()
        {
            #region Arrange
            //The BankHandler constructor adds a customer with one account, named "Vacation savings"
            BankHandler bankHandler = new BankHandler();
            Account account = new Account("Gasoline account", 2500.75, false);
            Account accountTwo = new Account("Travel account", 8500.12, false);
            #endregion

            #region Act
            bankHandler.AddAccountToCustomer(account);
            bankHandler.AddAccountToCustomer(accountTwo);
            int result = bankHandler.GetAllCustomerAccounts().Count;
            int expected = 3;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            #endregion
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            BankHandler bankHandler = new BankHandler();
            List<Account> accountList;
            Account tmpAccount;
            string accountName;
            int parsedWithdrawalInt, parsedDepositInt;

            int parsedInt = 1;

            while (parsedInt != 0)
            {
                Console.WriteLine("\n*********************************************************");
                Console.WriteLine("Please navigate through the menu by inputting the number \n(1, 2, 3 ,4, 5, 6, 7, or 0) of your choice:\n"
                + "\n1. Add an account."
                + "\n2. Display a list of all accounts."
                + "\n3. Display detailed information of a specific account."
                + "\n4. Make account deposit."
                + "\n5. Make account withdrawal."
                + "\n6. Make transfer between accounts."
                + "\n7. Lock/unlock an account."
                + "\n0. Exit the application");

                while (!int.TryParse(Console.ReadLine(), out parsedInt))
                {
                    Console.WriteLine("Try again:");
                }

                switch (parsedInt)
                {
                    case 1:
                        int parsedBalanceInt;

                        Console.Clear();
                        Console.WriteLine("Type the name of the account:");

                        accountName = Console.ReadLine();

                        Console.WriteLine("Set the initial account balance:");

                        while (!int.TryParse(Console.ReadLine(), out parsedBalanceInt))
                        {
                            Console.WriteLine("Try again:");
                        }

                        tmpAccount = new Account(accountName, parsedBalanceInt, false);

                        bankHandler.AddAccountToCustomer(tmpAccount);

                        Console.WriteLine("Added the account '" + accountName + "' to customer!");

                        break;
                    case 2:

                        Console.Clear();

                        Console.WriteLine("Listing all customer accounts:\n");

                        accountList = bankHandler.GetAllCustomerAccounts();

                        foreach (Account acc in accountList)
                        {
                            Console.WriteLine(acc);
                        }

                        break;
                    case 3:
                        Console.Clear();

                        accountList = bankHandler.GetAllCustomerAccounts();

                        foreach (Account acc in accountList)
                        {
                            Console.WriteLine(acc);
                        }

                        Console.WriteLine("\nType the name of the account you want to show details from:\n");

                        accountName = Console.ReadLine();
                        tmpAccount = bankHandler.GetSpecificCustomerAccount(accountName);

                        if(tmpAccount != null)
                        {
                            List<double> transactionList = tmpAccount.GetAllTransactions();

                            Console.WriteLine("Detailed information of account " + tmpAccount.GetAccountName() + ":\n");
                            Console.WriteLine("Balance: " + tmpAccount.GetAccountBalance());
                            Console.WriteLine("Locked for withdrawals: " + tmpAccount.GetLockedStatus());

                            Console.WriteLine("Transactions: ");

                            foreach (double ta in transactionList)
                            {
                                Console.WriteLine(ta);
                            }
                        }
                        else
                            Console.WriteLine("The account does not exist!");

                        break;
                    case 4:

                        Console.Clear();

                        accountList = bankHandler.GetAllCustomerAccounts();

                        foreach (Account acc in accountList)
                        {
                            Console.WriteLine(acc);
                        }

                        Console.WriteLine("\nEnter the name of the account you want to make a deposit to:\n");

                        accountName = Console.ReadLine();
                        tmpAccount = bankHandler.GetSpecificCustomerAccount(accountName);

                        if(tmpAccount != null)
                        {
                            Console.WriteLine("Enter the amount you want to deposit to the account:\n");

                            while (!int.TryParse(Console.ReadLine(), out parsedDepositInt))
                            {
                                Console.WriteLine("Try again:");
                            }

                            tmpAccount.Deposit(parsedDepositInt);

                            Console.WriteLine("Deposited " + parsedDepositInt + " to the account!\n");
                        }
                        else
                            Console.WriteLine("The account does not exist!");

                        break;
                    case 5:

                        Console.Clear();

                        accountList = bankHandler.GetAllCustomerAccounts();

                        foreach (Account acc in accountList)
                        {
                            Console.WriteLine(acc);
                        }

                        Console.WriteLine("\nEnter the name of the account you want to make a withdrawal from:\n");

                        accountName = Console.ReadLine();
                        tmpAccount = bankHandler.GetSpecificCustomerAccount(accountName);

                        if(tmpAccount != null)
                        {
                            Console.WriteLine("Enter the amount you want to withdraw from the account:\n");

                            while (!int.TryParse(Console.ReadLine(), out parsedWithdrawalInt))
                            {
                                Console.WriteLine("Try again:");
                            }

                            if(tmpAccount.Withdraw(parsedWithdrawalInt))
                            {
                                Console.WriteLine("Withdrew " + parsedWithdrawalInt + " from the account!\n");
                            }
                            else
                            {
                                Console.WriteLine("Withdrawal from the account is not possible at the moment");
                            }
                        }
                        else
                            Console.WriteLine("The account does not exist!");

                        break;
                    case 6:

                        Console.Clear();

                        int parsedTransferInt = 0;
                        accountList = bankHandler.GetAllCustomerAccounts();

                        foreach (Account acc in accountList)
                        {
                            Console.WriteLine(acc);
                        }

                        Console.WriteLine("\nEnter the name of the account you want to transfer from:\n");
                        string accountNameWdr = Console.ReadLine();
                        Account tmpAccountOne = bankHandler.GetSpecificCustomerAccount(accountNameWdr);

                        Console.WriteLine("\nEnter the name of the account you want to transfer to:\n");
                        string accountNameDep = Console.ReadLine();
                        Account tmpAccountTwo = bankHandler.GetSpecificCustomerAccount(accountNameDep);

                        if(tmpAccountOne != null && tmpAccountTwo != null && !tmpAccountOne.GetLockedStatus())
                        {
                            Console.WriteLine("\nEnter the amount to transfer between the accounts:\n");

                            while (!int.TryParse(Console.ReadLine(), out parsedTransferInt))
                            {
                                Console.WriteLine("Try again:");
                            }

                            tmpAccountOne.Withdraw(parsedTransferInt);
                            tmpAccountTwo.Deposit(parsedTransferInt);

                            Console.WriteLine("\nTransfered " + parsedTransferInt + " from " + accountNameWdr + " to " + accountNameDep + "!");
                        }

                        else
                            Console.WriteLine("One or both of the accounts does not exist, or the withdrawal account is locked.");
                        break;
                    case 7:
                        Console.Clear();

                        accountList = bankHandler.GetAllCustomerAccounts();

                        foreach (Account acc in accountList)
                        {
                            Console.WriteLine(acc);
                        }

                        Console.WriteLine("\nEnter the name of the account you want to lock/unlock:\n");

                        accountName = Console.ReadLine();
                        tmpAccount = bankHandler.GetSpecificCustomerAccount(accountName);

                        if(tmpAccount != null)
                        {
                            if(tmpAccount.GetLockedStatus())
                            {
                                tmpAccount.SetLockedStatus(false);
                                Console.WriteLine("The account is now unlocked!");
                            }
                            else
                            {
                                tmpAccount.SetLockedStatus(true);
                                Console.WriteLine("The account is now locked!");
                            }
                        }
                        else
                            Console.WriteLine("The account does not exist!");

                        break;
                    case 0:
                        return;

                    default:
                        Console.WriteLine("\nPlease enter some valid input (1, 2, 3, 4, 5, 6, 7 or 0)\n");

                        break;
                }
            }

            Console.ReadKey();
        }