-
Notifications
You must be signed in to change notification settings - Fork 178
/
DerivedSubjectSpecs.cs
70 lines (56 loc) · 1.76 KB
/
DerivedSubjectSpecs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using FluentAssertions;
using Machine.Specifications;
namespace Example.DerivedSubject
{
public class Account
{
private decimal _balance;
public decimal Balance
{
get { return _balance; }
set { _balance = value; }
}
public void Transfer(decimal amount, Account toAccount)
{
if (amount > _balance)
{
throw new Exception(String.Format("Cannot transfer ${0}. The available balance is ${1}.", amount, _balance));
}
_balance -= amount;
toAccount.Balance += amount;
}
}
[MySubject(typeof(Account), "Funds transfer")]
public class when_transferring_between_two_accounts_with_derived_subject
: AccountSpecs
{
Because of = () =>
fromAccount.Transfer(1m, toAccount);
It should_debit_the_from_account_by_the_amount_transferred = () =>
fromAccount.Balance.Should().Be(0m);
It should_credit_the_to_account_by_the_amount_transferred = () =>
toAccount.Balance.Should().Be(2m);
}
[Subject(typeof(Account), "Funds transfer")]
public class when_transferring_between_two_accounts_with_normal_subject
: AccountSpecs
{
Because of = () =>
fromAccount.Transfer(1m, toAccount);
It should_debit_the_from_account_by_the_amount_transferred = () =>
fromAccount.Balance.Should().Be(0m);
It should_credit_the_to_account_by_the_amount_transferred = () =>
toAccount.Balance.Should().Be(2m);
}
public abstract class AccountSpecs
{
protected static Account fromAccount;
protected static Account toAccount;
Establish context = () =>
{
fromAccount = new Account { Balance = 1m };
toAccount = new Account { Balance = 1m };
};
}
}