1[Test]
2[ExpectedException(typeof(InsufficientFundsException))]
3public void TransferWithInsufficientFunds()
4{
5 Account source = new Account();
6 source.Deposit(200.00F);
7 Account destination = new Account();
8 destination.Deposit(150.00F);
9 source.TransferFunds(destination, 300.00F);
10}
TransferWithInsufficentFunds : InsufficientFundsException was expected
让我们重新配置Account的代码,让它抛出异常,按下面的实例修改TransferFunds方法.
1public void TransferFunds(Account destination, float amount)
2{
3 destination.Deposit(amount);
4 if(balance-amount < minimumBalance)
5 throw new InsufficientFundsException();
6 Withdraw(amount);
7}