コード例 #1
0
        public void BankAccount_transfer_changes_balances()
        {
            _bankAccount.Deposit(10);
            var destinationAccount = new BankAccount();

            _bankAccount.TransferTo(destinationAccount,7);

            _bankAccount.Balance.Should().Be(3);
            destinationAccount.Balance.Should().Be(7);
        }
コード例 #2
0
        public void BankAccount_transfer_throws_when_exceeds_balance()
        {
            _bankAccount.Deposit(10);
            var destinationAccount = new BankAccount();

            var exception = Record.Exception(() => _bankAccount.TransferTo(destinationAccount, 11));

            exception.Should().BeOfType<InvalidOperationException>();
            exception.Message.Should().Be("Insufficient funds. Current balace: 10, attempted withdrawal: 11.");
        }
コード例 #3
0
        public void BankAccount_failed_transfer_keeps_balances_of_both_involved_accounts_intact()
        {
            _bankAccount.Deposit(10);
            var destinationAccount = new BankAccount();

            Record.Exception(() => _bankAccount.TransferTo(destinationAccount, 11));

            _bankAccount.Balance.Should().Be(10);
            destinationAccount.Balance.Should().Be(decimal.Zero);
        }
コード例 #4
0
 public void TransferTo(BankAccount destinationAccount, decimal amount)
 {
     Withdraw(amount);
     destinationAccount.Deposit(amount);
 }