Beispiel #1
0
 public void Test_Deposit_Success()
 {
     AccountsLib.Account acc = new AccountsLib.Account(3);
     acc.Deposit(3);
     acc.Deposit(2);
     Assert.AreEqual(5, acc.Balance);
 }
Beispiel #2
0
 public void Test_Withdraw_Success()
 {
     AccountsLib.Account acc = new AccountsLib.Account(3);
     acc.Deposit(3);
     acc.Withdraw(2);
     Assert.AreEqual(1, acc.Balance);
 }
Beispiel #3
0
 public void Test_TransferNegative_Failed()
 {
     AccountsLib.Account acc  = new AccountsLib.Account(3);
     AccountsLib.Account acc2 = new AccountsLib.Account(5);
     acc.Deposit(3);
     Assert.AreEqual(false, acc.Transfer(acc2, 4));
 }
Beispiel #4
0
        static void ApplyChoise(string choise)
        {
            switch (choise)
            {
                case "1":
                    AccountsController.CheckBalance(_firstAccount);
                    break;

                case "2":
                    AccountsController.DepositToAccount(_firstAccount);
                    break;

                case "3":
                    AccountsController.WithdrawFromAccount(_firstAccount);
                    break;

                case "4":
                    _secondAccount = AccountsController.CreateAccount();
                    break;

                case "5":
                    AccountsController.TransferToAccount(_firstAccount, _secondAccount);
                    break;

                default:
                    Console.Write("Invalid choise. ");
                    break;
            }
        }
        private static void MakeTransferAttempt(Account fromAccount, Account toAccount)
        {
            var transferAmount = GetAmountFromUser("Enter the amount to transfer: ");
            fromAccount.Transfer(toAccount, transferAmount);

            MessagesPrinter.SuccessMessage("Amount transfered successfully");
        }
        public static void WithdrawFromAccount(Account account)
        {
            var withdrawAmount = GetAmountFromUser("Enter the amount to withdraw: ");
            account.Withdraw(withdrawAmount);

            var successMessage = string.Format("{0}$ has been withdrawn from Account {1}",withdrawAmount,account.Id);
            MessagesPrinter.SuccessMessage(successMessage);
        }
        public static void DepositToAccount(Account account)
        {
            var depositAmount = GetAmountFromUser("Enter the amount to deposit: ");
            account.Deposit(depositAmount);

            var successMessage = string.Format("{0}$ has been deposited to Account {1}", depositAmount, account.Id);
            MessagesPrinter.SuccessMessage(successMessage);
        }
 public static void WithdrawFromAccount(Account account)
 {
     var withdrawAmount = GetAmountFromUser("Enter the amount to withdraw: ");
     var canWithdraw = account.Withdraw(withdrawAmount);
     if (!canWithdraw)
     {
         Console.WriteLine("Cannot withdraw this amount");
     }
 }
Beispiel #9
0
 public void Test_Transfer_Success()
 {
     AccountsLib.Account acc  = new AccountsLib.Account(3);
     AccountsLib.Account acc2 = new AccountsLib.Account(5);
     acc.Deposit(3);
     Assert.AreEqual(true, acc.Transfer(acc2, 2));
     Assert.AreEqual(1, acc.Balance);
     Assert.AreEqual(2, acc2.Balance);
 }
Beispiel #10
0
        static void RunAccountsConsole()
        {
            if (_firstAccount == null)
                _firstAccount = AccountsController.CreateAccount();

            ShowUserMenu();
            var choise = Console.ReadLine();

            if (choise == "exit")
                Environment.Exit(0);

            ApplyChoise(choise);
        }
Beispiel #11
0
 public void Test_WithdrawTooMuch_Failed()
 {
     AccountsLib.Account acc = new AccountsLib.Account(3);
     acc.Deposit(2);
     try
     {
         acc.Withdraw(3);
         Assert.Fail();
     }
     catch (InsufficentFundsException)
     {
         Assert.Pass();
     }
 }
Beispiel #12
0
 public void Test_WithdrawNegative_Failed()
 {
     AccountsLib.Account acc = new AccountsLib.Account(3);
     acc.Deposit(3);
     try
     {
         acc.Withdraw(-2);
         Assert.Fail();
     }
     catch (Exception e)
     {
         Assert.AreEqual("NegativeExc", e.Message);
     }
 }
Beispiel #13
0
 public void Test_DepositMax_Failed()
 {
     AccountsLib.Account acc = new AccountsLib.Account(3);
     acc.Deposit(3);
     try
     {
         acc.Deposit(int.MaxValue);
         Assert.Fail();
     }
     catch (OverflowException)
     {
         Assert.Pass();
     }
 }
        public static void TransferToAccount(Account fromAccount, Account toAccount)
        {
            if (toAccount == null)
            {
                Console.WriteLine("There is no second account");
                return;
            }

            var transferAmount = GetAmountFromUser("Enter the amount to transfer: ");
            var canTransfer = fromAccount.Transfer(toAccount, transferAmount);
            if (!canTransfer)
            {
                Console.WriteLine("Cannot transfer this amount");
            }
        }
        public static void TransferToAccount(Account fromAccount, Account toAccount)
        {
            if (toAccount == null)
            {
                MessagesPrinter.ErrorMessage("There is no second account!");
                return;
            }

            var previousBalance = fromAccount.Balance;

            try
            {
                MakeTransferAttempt(fromAccount, toAccount);
            }
            finally
            {
                var statusMessage = string.Format("Transfer attempt has been made: Previous balance:{0}$. Current balance:{1}$",
                    previousBalance,fromAccount.Balance);
                MessagesPrinter.StatusMessage(statusMessage);

            }
        }
Beispiel #16
0
 static void Main(string[] args)
 {
     AccountsLib.Account newAcc = AccountsLib.AccountFactory.CreateAccount(0);
     newAcc.Deposit(50);
     try
     {
         newAcc.Withdraw(51);
     }
     //You are not handling the ArgumentOutOfRangeException/Exception that you throwed if the amount is negative.
     catch (InsufficentFundsException e)
     {
         //You should have used the message from the exception
         Console.WriteLine("there has been an InsufficentFundsException");
     }
     finally //didn't understood why we need the finally now but i did it
     {
         newAcc.Withdraw(29);
         AccountsLib.Account newAcc2 = AccountsLib.AccountFactory.CreateAccount(0);
         newAcc.Transfer(newAcc2, 5);
         Console.WriteLine("{0} {1}", newAcc.Balance, newAcc2.Balance);
         Console.ReadLine();
     }
 }
Beispiel #17
0
        static void Main()
        {
            _firstAccount = AccountsController.CreateAccount();

            RunAccountsConsole();
        }
 public static void CheckBalance(Account account)
 {
     var balanceStatus = string.Format("The Balance is: {0}$", account.Balance);
     MessagesPrinter.StatusMessage(balanceStatus);
 }
 public static void DepositToAccount(Account account)
 {
     var depositAmount = GetAmountFromUser("Enter the amount to deposit: ");
     account.Deposit(depositAmount);
 }