fix tests for fp2
This commit is contained in:
@@ -10,42 +10,51 @@ public class AccountTests
|
||||
public void Opening_an_account_with_a_negative_balance_throws()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() =>
|
||||
new Account(new AccountId(Guid.NewGuid()), new Money(-1m))
|
||||
AccountDomain.Open(Guid.NewGuid(), new Money(-1m))
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Withdrawing_a_zero_amount_throws()
|
||||
public void Withdrawing_a_zero_amount_returns_AmountMustBePositive()
|
||||
{
|
||||
var account = new Account(new AccountId(Guid.NewGuid()), new Money(100m));
|
||||
var account = AccountDomain.Open(Guid.NewGuid(), new Money(100m));
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => account.Withdraw(new Money(0m)));
|
||||
var result = AccountDomain.Withdraw(account, new Money(0m));
|
||||
|
||||
Assert.IsType<WithdrawResult.AmountMustBePositive>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Withdrawing_a_negative_amount_throws()
|
||||
public void Withdrawing_a_negative_amount_returns_AmountMustBePositive()
|
||||
{
|
||||
var account = new Account(new AccountId(Guid.NewGuid()), new Money(100m));
|
||||
var account = AccountDomain.Open(Guid.NewGuid(), new Money(100m));
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => account.Withdraw(new Money(-10m)));
|
||||
var result = AccountDomain.Withdraw(account, new Money(-10m));
|
||||
|
||||
Assert.IsType<WithdrawResult.AmountMustBePositive>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Withdrawing_more_than_the_balance_throws()
|
||||
public void Withdrawing_more_than_the_balance_returns_InsufficientBalance()
|
||||
{
|
||||
var account = new Account(new AccountId(Guid.NewGuid()), new Money(100m));
|
||||
var account = AccountDomain.Open(Guid.NewGuid(), new Money(100m));
|
||||
|
||||
Assert.Throws<InsufficientBalanceException>(() => account.Withdraw(new Money(101m)));
|
||||
var result = AccountDomain.Withdraw(account, new Money(101m));
|
||||
|
||||
Assert.IsType<WithdrawResult.InsufficientBalance>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Successive_withdrawals_are_each_applied_to_the_running_balance()
|
||||
{
|
||||
var account = new Account(new AccountId(Guid.NewGuid()), new Money(300m));
|
||||
var account = AccountDomain.Open(Guid.NewGuid(), new Money(300m));
|
||||
|
||||
account.Withdraw(new Money(100m));
|
||||
account.Withdraw(new Money(100m));
|
||||
var result1 = AccountDomain.Withdraw(account, new Money(100m));
|
||||
var success1 = Assert.IsType<WithdrawResult.Success>(result1);
|
||||
|
||||
Assert.Equal(100m, account.Balance.Amount);
|
||||
var result2 = AccountDomain.Withdraw(success1.Account, new Money(100m));
|
||||
var success2 = Assert.IsType<WithdrawResult.Success>(result2);
|
||||
|
||||
Assert.Equal(100m, success2.Account.Balance.Amount);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user