main
1using System;
2using System.Collections.Generic;
3using developwithpassion.bdd.contexts;
4using Gorilla.Commons.Testing;
5using Gorilla.Commons.Utility;
6using MoMoney.Domain.Accounting;
7using MoMoney.Domain.Core;
8
9namespace MoMoney.Domain.accounting
10{
11 [Concern(typeof (AccountHolder))]
12 public abstract class behaves_like_an_account_holder : concerns_for<IAccountHolder, AccountHolder>
13 {
14 }
15
16 public class when_a_customer_is_checking_for_any_bills_that_have_not_been_paid : behaves_like_an_account_holder
17 {
18 it should_return_all_the_unpaid_bills = () =>
19 {
20 result.should_contain(first_unpaid_bill);
21 result.should_contain(second_unpaid_bill);
22 };
23
24 context c = () =>
25 {
26 first_unpaid_bill = an<IBill>();
27 second_unpaid_bill = an<IBill>();
28 paid_bill = an<IBill>();
29
30 first_unpaid_bill.is_told_to(x => x.is_paid_for()).it_will_return(false);
31 second_unpaid_bill.is_told_to(x => x.is_paid_for()).it_will_return(false);
32 paid_bill.is_told_to(x => x.is_paid_for()).it_will_return(true);
33 };
34
35 because b = () =>
36 {
37 sut.receive(first_unpaid_bill);
38 sut.receive(paid_bill);
39 sut.receive(second_unpaid_bill);
40 result = sut.collect_all_the_unpaid_bills();
41 };
42
43 static IEnumerable<IBill> result;
44 static IBill first_unpaid_bill;
45 static IBill second_unpaid_bill;
46 static IBill paid_bill;
47 }
48
49 [Concern(typeof (AccountHolder))]
50 public class when_an_account_holder_is_calculating_their_income_for_a_year : behaves_like_an_account_holder
51 {
52 context c = () =>
53 {
54 income_for_january_2007 = an<IIncome>();
55 income_for_february_2007 = an<IIncome>();
56 income_for_february_2008 = an<IIncome>();
57
58 income_for_january_2007.is_told_to(x => x.date_of_issue).it_will_return<Date>( new DateTime(2007, 01, 01));
59 income_for_january_2007.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000, 00));
60
61 income_for_february_2007.is_told_to(x => x.date_of_issue).it_will_return<Date>( new DateTime(2007, 02, 01));
62 income_for_february_2007.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000,
63 00));
64
65 income_for_february_2008.is_told_to(x => x.date_of_issue).it_will_return<Date>( new DateTime(2008, 02, 01));
66 income_for_february_2008.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000, 00));
67 };
68
69 because b = () =>
70 {
71 sut.receive(income_for_january_2007);
72 sut.receive(income_for_february_2007);
73 sut.receive(income_for_february_2008);
74 result = sut.calculate_income_for(2007);
75 };
76
77 it should_return_the_correct_amount = () => result.should_be_equal_to(2000.as_money());
78
79 static Money result;
80 static IIncome income_for_january_2007;
81 static IIncome income_for_february_2007;
82 static IIncome income_for_february_2008;
83 }
84}