示例#1
0
        public void DebitTest()
        {
            string customerName = "UnitTest01";
            double balance = 0.99;
            var target = new BankAccount(customerName, balance);

            double amount = -1.0;
            try
            {
                target.Debit(amount);
            }
            catch (ArgumentOutOfRangeException) { }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected exception type " + ex.GetType().Name);
            }

            amount = 1.0;
            try
            {
                target.Debit(amount);
            }
            catch (ArgumentOutOfRangeException) { }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected exception type " + ex.GetType().Name);
            }

            amount = balance;
            target.Debit(amount);
            Assert.AreEqual(target.Balance, balance - amount);
        }
示例#2
0
        public void BankAccountConstructorTest()
        {
            string customerName = "UnitTest01";
            double balance = 0.99;
            var target = new BankAccount(customerName, balance);

            Assert.IsNotNull(target);
            Assert.AreEqual(target.CustomerName, customerName, true);
            Assert.AreEqual(target.Balance, balance);
        }
示例#3
0
        public void GetBankAccountTest()
        {
            string customerName = "UnitTest01";
            double balance = 0.0;
            var expected = new BankAccount(customerName, balance);

            var actual = Program.GetBankAccount(customerName);

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.CustomerName, actual.CustomerName, true);
            Assert.AreEqual(expected.Balance, actual.Balance);
        }
示例#4
0
 public static void TransferMoney(BankAccount debitAccount, BankAccount creditAccount, double amount)
 {
     try
     {
         debitAccount.Debit(amount);
     }
     catch (ArgumentOutOfRangeException ex)
     {
         throw new ArgumentException("Insufficient balance.", ex);
     }
     creditAccount.Credit(amount);
 }
示例#5
0
 public static BankAccount GetBankAccount(string customerName)
 {
     var balance = GetBalance(customerName);
     var result = new BankAccount(customerName, balance);
     return result;
 }