Exemplo n.º 1
0
        private string TransferAmount(BankTransaction trans)
        {
            BankAccount sourceAcct = _lib.GetBankAccountByAccountNumber(trans.SourceAccountNumber);
            BankAccount targetAcct = _lib.GetBankAccountByAccountNumber(trans.TargetAccountNumber);

            if (sourceAcct != null && targetAcct != null && trans.TransactionAmount < 0)
            {
                return("Transaction Amount cannot be negative or less than zero");
            }
            else if (sourceAcct != null && targetAcct != null && sourceAcct.Balance > trans.TransactionAmount)
            {
                //sourceAcct.Balance = sourceAcct.Balance - trans.TransactionAmount;

                //targetAcct.Balance = targetAcct.Balance + trans.TransactionAmount;

                _lib.UpdateBankAccount(sourceAcct, targetAcct, trans.TransactionType, trans.TransactionAmount);
            }
            else if (sourceAcct != null && targetAcct != null && sourceAcct.Balance < trans.TransactionAmount)
            {
                return("Transaction Amount must be less than Balance Amount.");
            }
            else if (sourceAcct != null && targetAcct == null)
            {
                return("Target Account Number does not exist.");
            }
            else if (sourceAcct == null && targetAcct != null)
            {
                return("Source Account Number does not exists.");
            }

            return("Bank Transaction Successfull");
        }
        public void TestUpdateBankAccount()
        {
            BankAccount existAcct = _dataLib.GetBankAccountByAccountNumber("2019101000002");

            existAcct.LoginName = "testme2019";
            existAcct.Balance   = 90;
            double transactionAmount = 10;
            string transactionType   = "withdrawal";

            _dataLib.UpdateBankAccount(existAcct, transactionType, transactionAmount);

            BankAccount dbAcct = _dataLib.GetBankAccountByAccountNumber("2019101000002");

            Assert.IsNotNull(dbAcct);
            Assert.AreEqual(existAcct.LoginName, dbAcct.LoginName);
            Assert.AreEqual(existAcct.AccountNumber, dbAcct.AccountNumber);
            Assert.AreEqual(existAcct.Balance, dbAcct.Balance);
        }