Inheritance: IAccount, IDepositable
コード例 #1
0
ファイル: Customer.cs プロジェクト: Chrille80/BankSystem
        public bool AddAccount(Account account)
        {
            foreach (Account acc in Accounts)
            {
                if(acc.GetAccountName().Equals(account.GetAccountName())) return false;
            }

            Accounts.Add(account);

            return true;
        }
コード例 #2
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestGetAccountBalance_SevenThousandAndFortyCents_SevenThousandAndFortyCents()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 7000.40, false);
            #endregion

            #region Act
            double resultBalance = account.GetAccountBalance();
            double expectedBalance = 7000.40;
            #endregion

            #region Assert
            Assert.AreEqual(expectedBalance, resultBalance);
            #endregion
        }
コード例 #3
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestDeposit_DepositTwoHundredAndFiftyCents_BalanceTwoHundredAndFiftyCents()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 0, true);
            #endregion

            #region Act
            account.Deposit(200.50);
            double resultBalance = account.GetAccountBalance();
            double expectedBalance = 200.50;
            #endregion

            #region Assert
            Assert.AreEqual(expectedBalance, resultBalance);
            #endregion
        }
コード例 #4
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestDeposit_DepositZero_BalanceZero()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 0, true);
            #endregion

            #region Act
            account.Deposit(0);
            double resultBalance = account.GetAccountBalance();
            double expectedBalance = 0;
            #endregion

            #region Assert
            Assert.AreEqual(expectedBalance, resultBalance);
            #endregion
        }
コード例 #5
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
        }
コード例 #6
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
        }
コード例 #7
0
ファイル: CustomerTests.cs プロジェクト: Chrille80/BankSystem
        public void TestAddAccount_AddOneAccount_OneAccountInListAndTrue()
        {
            #region Arrange
            Customer customer = new Customer("Sven Svensson");
            Account account = new Account("Savings", 250, false);
            List<Account> accountList = new List<Account>();
            #endregion

            #region Act
            accountList = customer.GetAllAccounts();
            bool result = customer.AddAccount(account);
            bool expected = true;
            int resultTwo = accountList.Count;
            int expectedTwo = 1;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            Assert.AreEqual(expectedTwo, resultTwo);
            #endregion
        }
コード例 #8
0
ファイル: CustomerTests.cs プロジェクト: Chrille80/BankSystem
        public void TestAddAccount_AddTwoAccountsWithUniqueNames_TwoAccountsInListAndTrue()
        {
            #region Arrange
            Customer customer = new Customer("Sven Svensson");
            Account account = new Account("Savings", 6500, false);
            Account accountTwo = new Account("Poker winnings", 3100, false);
            #endregion

            #region Act
            bool result = customer.AddAccount(account);
            bool expected = true;
            bool resultTwo = customer.AddAccount(accountTwo);
            bool expectedTwo = true;
            int resultThree = customer.GetAllAccounts().Count;
            int expectedThree = 2;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            Assert.AreEqual(expectedTwo, resultTwo);
            Assert.AreEqual(expectedThree, resultThree);
            #endregion
        }
コード例 #9
0
ファイル: BankHandler.cs プロジェクト: Chrille80/BankSystem
 public BankHandler()
 {
     theCustomer = new Customer("Customer");
     initialAccount = new Account("Vacation savings", 7700.50, false);
     theCustomer.AddAccount(initialAccount);
 }
コード例 #10
0
 public void AddAccount(Account account)
 {
     this.accounts.Add(account);
     this.accountsCount++;
 }
コード例 #11
0
ファイル: CustomerTests.cs プロジェクト: Chrille80/BankSystem
        public void TestGetAllAccounts_GetAccountsWhenTwoAccounts_ListWithTwoAccounts()
        {
            #region Arrange
            Customer customer = new Customer("Sven Svensson");
            Account accountOne = new Account("Poker winnings", 6500, false);
            Account accountTwo = new Account("Stryktipset winnings", 14500, false);
            customer.AddAccount(accountOne);
            customer.AddAccount(accountTwo);
            #endregion

            #region Act
            int result = customer.GetAllAccounts().Count;
            int expected = 2;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            #endregion
        }
コード例 #12
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestWithdraw_WithdrawAmountWhenAccountIsUnlocked_True()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 1000.7, false);
            #endregion

            #region Act
            bool result = account.Withdraw(194.50);
            bool expected = true;
            double resultBalance = account.GetAccountBalance();
            double expectedBalance = 806.2;
            #endregion

            #region Assert
            Assert.AreEqual(expectedBalance, resultBalance);
            Assert.AreEqual(expected, result);
            #endregion
        }
コード例 #13
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestWithdraw_WhitdrawFromPositiveToNegativeAmount_AccountGetsLocked()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 557.9, false);
            #endregion

            #region Act
            bool result = account.Withdraw(560.0);
            bool expected = true;
            double resultBalance = account.GetAccountBalance();
            double expectedBalance = -2.1;
            double errorMargin = 0.0000000000001;
            bool resultTwo = account.GetLockedStatus();
            bool expectedTwo = true;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            Assert.AreEqual(expectedBalance, resultBalance, errorMargin);
            Assert.AreEqual(expectedTwo, resultTwo);
            #endregion
        }
コード例 #14
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestSetLockedStatus_SetAccountToUnlocked_IsLockedFalse()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 1800, true);
            #endregion

            #region Act
            account.SetLockedStatus(false);
            bool result = account.GetLockedStatus();
            bool expected = false;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            #endregion
        }
コード例 #15
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestInstantiateAccount_NameSavingsBalanceFiveThousandIsLockedFalseOneTransaction_NameSavingsBalanceFiveThousandIsLockedFalseListWithOneTransaction()
        {
            #region Arrange
            Account account = new Account("Savings", 0, false);
            #endregion

            #region Act
            account.Deposit(5000);
            string resultName = account.GetAccountName();
            string expectedName = "Savings";
            double resultBalance = account.GetAccountBalance();
            double expectedBalance = 5000;
            bool resultIsLocked = account.GetLockedStatus();
            bool expectedIsLocked = false;
            int resultTransactions = account.GetAllTransactions().Count;
            int expectedTransactions = 1;
            #endregion

            #region Assert
            Assert.AreEqual(expectedName, resultName);
            Assert.AreEqual(expectedBalance, resultBalance);
            Assert.AreEqual(expectedIsLocked, resultIsLocked);
            Assert.AreEqual(expectedTransactions, resultTransactions);
            #endregion
        }
コード例 #16
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestInstantiateAccount_EmptyNameStringBalanceZeroIsLockedTrueZeroTransactions_EmptyNameStringBalanceZeroIsLockedTrueListWithZeroTransactions()
        {
            #region Arrange
            Account account = new Account("", 0, true);
            #endregion

            #region Act
            string resultName = account.GetAccountName();
            string expectedName = "";
            double resultBalance = account.GetAccountBalance();
            double expectedBalance = 0;
            bool resultIsLocked = account.GetLockedStatus();
            bool expectedIsLocked = true;
            int resultTransactions = account.GetAllTransactions().Count;
            int expectedTransactions = 0;
            #endregion

            #region Assert
            Assert.AreEqual(expectedName, resultName);
            Assert.AreEqual(expectedBalance, resultBalance);
            Assert.AreEqual(expectedIsLocked, resultIsLocked);
            Assert.AreEqual(expectedTransactions, resultTransactions);
            #endregion
        }
コード例 #17
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestGetLockedStatus_GetLockedStatusWhenLocked_IsLockedTrue()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 1800, true);
            #endregion

            #region Act
            bool result = account.GetLockedStatus();
            bool expected = true;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            #endregion
        }
コード例 #18
0
ファイル: BankHandler.cs プロジェクト: Chrille80/BankSystem
 public void AddAccountToCustomer(Account account)
 {
     theCustomer.AddAccount(account);
 }
コード例 #19
0
ファイル: Program.cs プロジェクト: Chrille80/BankSystem
        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();
        }
コード例 #20
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestWithdraw_WithdrawAmountWhenNegativeAccountBalance_False()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", -900.7, false);
            #endregion

            #region Act
            bool result = account.Withdraw(194.50);
            bool expected = false;
            double resultBalance = account.GetAccountBalance();
            double expectedBalance = -900.7;
            #endregion

            #region Assert
            Assert.AreEqual(expectedBalance, resultBalance);
            Assert.AreEqual(expected, result);
            #endregion
        }
コード例 #21
0
ファイル: CustomerTests.cs プロジェクト: Chrille80/BankSystem
        public void TestGetSpecificAccount_GetSpecificAccountWhenNameMatches_SpecificAccountWithMatchingName()
        {
            #region Arrange
            Customer customer = new Customer("Per Persson");
            Account account = new Account("Poker winnings", 6500, false);
            customer.AddAccount(account);
            #endregion

            #region Act
            Account matchingAccount = customer.GetSpecificAccount("Poker winnings");
            string result = matchingAccount.GetAccountName();
            string expected = "Poker winnings";
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            #endregion
        }
コード例 #22
0
ファイル: Bank.cs プロジェクト: Elinos/TelerikAcademy
 public void RemoveAccount(Account account)
 {
     this.accounts.Remove(account);
 }
コード例 #23
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestGetAllTransactions_GetTransactionsWhenNoTransactions_EmptyList()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 0, false);
            List<double> transactionList = new List<double>();
            #endregion

            #region Act
            transactionList = account.GetAllTransactions();
            int result = transactionList.Count;
            int expected = 0;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            #endregion
        }
コード例 #24
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestGetAllTransactions_GetTransactionsWhenThreeTransactions_ListWithThreeTransactions()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 1800, false);
            List<double> transactionList = new List<double>();
            #endregion

            #region Act
            account.Deposit(500);
            account.Withdraw(600);
            account.Deposit(700);
            account.Withdraw(0);
            account.Deposit(0);
            transactionList = account.GetAllTransactions();
            int result = transactionList.Count;
            int expected = 3;
            #endregion

            #region Assert
            Assert.AreEqual(expected, result);
            #endregion
        }
コード例 #25
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestGetAccountBalance_Zero_Zero()
        {
            #region Arrange
            Account account = new Account("Stryktipset winnings", 0, false);
            #endregion

            #region Act
            double resultBalance = account.GetAccountBalance();
            double expectedBalance = 0;
            #endregion

            #region Assert
            Assert.AreEqual(expectedBalance, resultBalance);
            #endregion
        }
コード例 #26
0
ファイル: AccountTests.cs プロジェクト: Chrille80/BankSystem
        public void TestGetAccountName_TravelAccount_TravelAccount()
        {
            #region Arrange
            Account account = new Account("Travel Account", 11700, false);
            #endregion

            #region Act
            string resultName = account.GetAccountName();
            string expectedName = "Travel Account";
            #endregion

            #region Assert
            Assert.AreEqual(expectedName, resultName);
            #endregion
        }