Commit 5df53a2
Changed files (5)
trunk
src
MyMoney
Domain
accounting
Core
trunk/src/MyMoney/Domain/accounting/billing/company_specs.cs
@@ -1,4 +1,5 @@
using System;
+using jpboodhoo.bdd.contexts;
using MyMoney.Domain.accounting.financial_growth;
using MyMoney.Domain.Core;
using MyMoney.Testing.Extensions;
@@ -7,65 +8,53 @@ using MyMoney.Testing.spechelpers.contexts;
namespace MyMoney.Domain.accounting.billing
{
- public class company_specs
- {}
-
[Concern(typeof (company))]
- public class when_a_company_issues_a_bill_to_a_customer : old_context_specification<ICompany>
+ public class behaves_like_a_company : concerns_for<ICompany>
{
- [Observation]
- public void it_should_issue_the_bill_to_the_customer_for_the_previous_billing_month()
+ protected string company_name;
+
+ public override ICompany create_sut()
{
- customer.was_told_to(x => x.recieve(bill));
+ company_name = "enmax";
+ return new company(company_name);
}
+ }
- protected override ICompany context()
- {
- customer = an<IAccountHolder>();
- for_amount = new money(53, 24);
- that_is_due_on = new DateTime(2008, 02, 12);
- var the_company_to_pay = new company("enmax");
+ public class when_a_company_issues_a_bill_to_a_customer : behaves_like_a_company
+ {
+ it should_issue_the_bill_to_the_customer_for_the_previous_billing_month =
+ () => customer.was_told_to(x => x.recieve(new bill(sut, for_amount, that_is_due_on)));
- bill = new bill(the_company_to_pay, for_amount, that_is_due_on);
- return the_company_to_pay;
- }
+ context c = () =>
+ {
+ customer = an<IAccountHolder>();
+ for_amount = new money(53, 24);
+ that_is_due_on = new DateTime(2008, 02, 12);
+ };
- protected override void because()
- {
- sut.issue_bill_to(customer, that_is_due_on, for_amount);
- }
+ because b = () => sut.issue_bill_to(customer, that_is_due_on, for_amount);
- private IAccountHolder customer;
- private IMoney for_amount;
- private DateTime that_is_due_on;
- private IBill bill;
+ static IAccountHolder customer;
+ static IMoney for_amount;
+ static DateTime that_is_due_on;
}
- [Concern(typeof (company))]
- public class when_a_company_pays_an_employee_or_consultant_for_services : old_context_specification<ICompany>
+ public class when_a_company_pays_an_employee_or_consultant_for_services : behaves_like_a_company
{
- [Observation]
- public void it_should_pay_the_total_amount_that_is_due()
- {
- person.was_told_to(x => x.recieve(new income(date_of_payment, two_thousand_dollars, sut)));
- }
-
- protected override ICompany context()
- {
- two_thousand_dollars = new money(2000);
- person = an<IAccountHolder>();
- date_of_payment = an<IDate>();
+ it should_pay_the_total_amount_that_is_due =
+ () => person.was_told_to(x => x.recieve(new income(date_of_payment, two_thousand_dollars, sut)));
- return new company("eCompliance");
- }
+ context c = () =>
+ {
+ two_thousand_dollars = new money(2000);
+ person = an<IAccountHolder>();
+ date_of_payment = an<IDate>();
+ };
- protected override void because()
- {
- sut.pay(person, two_thousand_dollars, date_of_payment);
- }
+ because b = () => sut.pay(person, two_thousand_dollars, date_of_payment);
- private money two_thousand_dollars;
- private IAccountHolder person;
- private IDate date_of_payment;
+ static money two_thousand_dollars;
+ static IAccountHolder person;
+ static IDate date_of_payment;
}
}
\ No newline at end of file
trunk/src/MyMoney/Domain/accounting/account_holder_specs.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using jpboodhoo.bdd.contexts;
using MyMoney.Domain.accounting.billing;
using MyMoney.Domain.accounting.financial_growth;
using MyMoney.Domain.Core;
@@ -9,96 +10,92 @@ using MyMoney.Testing.spechelpers.contexts;
namespace MyMoney.Domain.accounting
{
- public class account_holder_specs
- {}
-
[Concern(typeof (account_holder))]
- public class when_a_customer_is_checking_for_any_bills_that_have_not_been_paid : old_context_specification<IAccountHolder>
+ public class behaves_like_an_account_holder : concerns_for<IAccountHolder>
{
- [Observation]
- public void it_should_return_all_the_unpaid_bills()
- {
- result.should_contain(first_unpaid_bill);
- result.should_contain(second_unpaid_bill);
- }
-
- protected override IAccountHolder context()
+ public override IAccountHolder create_sut()
{
- first_unpaid_bill = an<IBill>();
- second_unpaid_bill = an<IBill>();
- paid_bill = an<IBill>();
-
-
- first_unpaid_bill.is_told_to(x => x.is_paid_for()).Return(false);
- second_unpaid_bill.is_told_to(x => x.is_paid_for()).Return(false);
- paid_bill.is_told_to(x => x.is_paid_for()).Return(true);
-
- var customer = new account_holder();
- customer.recieve(first_unpaid_bill);
- customer.recieve(paid_bill);
- customer.recieve(second_unpaid_bill);
- return customer;
- }
-
- protected override void because()
- {
- result = sut.collect_all_the_unpaid_bills();
+ return new account_holder();
}
+ }
- private IEnumerable<IBill> result;
- private IBill first_unpaid_bill;
- private IBill second_unpaid_bill;
- private IBill paid_bill;
+ public class when_a_customer_is_checking_for_any_bills_that_have_not_been_paid : behaves_like_an_account_holder
+ {
+ it should_return_all_the_unpaid_bills = () =>
+ {
+ result.should_contain(first_unpaid_bill);
+ result.should_contain(second_unpaid_bill);
+ };
+
+ context c = () =>
+ {
+ first_unpaid_bill = an<IBill>();
+ second_unpaid_bill = an<IBill>();
+ paid_bill = an<IBill>();
+
+ first_unpaid_bill.is_told_to(x => x.is_paid_for()).it_will_return(false);
+ second_unpaid_bill.is_told_to(x => x.is_paid_for()).it_will_return(false);
+ paid_bill.is_told_to(x => x.is_paid_for()).it_will_return(true);
+ };
+
+ because b = () =>
+ {
+ sut.recieve(first_unpaid_bill);
+ sut.recieve(paid_bill);
+ sut.recieve(second_unpaid_bill);
+ result = sut.collect_all_the_unpaid_bills();
+ };
+
+ static IEnumerable<IBill> result;
+ static IBill first_unpaid_bill;
+ static IBill second_unpaid_bill;
+ static IBill paid_bill;
}
[Concern(typeof (account_holder))]
- public class when_an_account_holder_is_calculating_their_income_for_a_year : old_context_specification<IAccountHolder>
+ public class when_an_account_holder_is_calculating_their_income_for_a_year : behaves_like_an_account_holder
{
- protected override IAccountHolder context()
- {
- var income_for_january_2007 = an<IIncome>();
- var income_for_february_2007 = an<IIncome>();
- var income_for_february_2008 = an<IIncome>();
-
- income_for_january_2007
- .is_told_to(x => x.date_of_issue)
- .Return(new DateTime(2007, 01, 01).as_a_date());
- income_for_january_2007
- .is_told_to(x => x.amount_tendered)
- .Return(new money(1000, 00));
-
- income_for_february_2007
- .is_told_to(x => x.date_of_issue)
- .Return(new DateTime(2007, 02, 01).as_a_date());
- income_for_february_2007
- .is_told_to(x => x.amount_tendered)
- .Return(new money(1000, 00));
-
- income_for_february_2008
- .is_told_to(x => x.date_of_issue)
- .Return(new DateTime(2008, 02, 01).as_a_date());
- income_for_february_2008
- .is_told_to(x => x.amount_tendered)
- .Return(new money(1000, 00));
-
- var system_under_test = new account_holder();
- system_under_test.recieve(income_for_january_2007);
- system_under_test.recieve(income_for_february_2007);
- system_under_test.recieve(income_for_february_2008);
- return system_under_test;
- }
-
- protected override void because()
- {
- result = sut.calculate_income_for(2007.as_a_year());
- }
-
- [Observation]
- public void it_should_return_the_correct_amount()
- {
- result.should_be_equal_to(2000.as_money());
- }
-
- private IMoney result;
+ context c = () =>
+ {
+ income_for_january_2007 = an<IIncome>();
+ income_for_february_2007 = an<IIncome>();
+ income_for_february_2008 = an<IIncome>();
+
+ income_for_january_2007
+ .is_told_to(x => x.date_of_issue)
+ .it_will_return(new DateTime(2007, 01, 01).as_a_date());
+ income_for_january_2007
+ .is_told_to(x => x.amount_tendered)
+ .it_will_return(new money(1000, 00));
+
+ income_for_february_2007
+ .is_told_to(x => x.date_of_issue)
+ .it_will_return(new DateTime(2007, 02, 01).as_a_date());
+ income_for_february_2007
+ .is_told_to(x => x.amount_tendered)
+ .it_will_return(new money(1000, 00));
+
+ income_for_february_2008
+ .is_told_to(x => x.date_of_issue)
+ .it_will_return(new DateTime(2008, 02, 01).as_a_date());
+ income_for_february_2008
+ .is_told_to(x => x.amount_tendered)
+ .it_will_return(new money(1000, 00));
+ };
+
+ because b = () =>
+ {
+ sut.recieve(income_for_january_2007);
+ sut.recieve(income_for_february_2007);
+ sut.recieve(income_for_february_2008);
+ result = sut.calculate_income_for(2007.as_a_year());
+ };
+
+ it should_return_the_correct_amount = () => result.should_be_equal_to(2000.as_money());
+
+ static IMoney result;
+ static IIncome income_for_january_2007;
+ static IIncome income_for_february_2007;
+ static IIncome income_for_february_2008;
}
}
\ No newline at end of file
trunk/src/MyMoney/Domain/accounting/general_ledger.cs
@@ -10,7 +10,7 @@ namespace MyMoney.Domain.accounting
IEnumerable<ILedgerEntry> get_all_the_entries_for(IMonth month);
}
- internal class general_ledger : IGeneralLedger
+ public class general_ledger : IGeneralLedger
{
private readonly List<ILedgerEntry> entries;
trunk/src/MyMoney/Domain/accounting/GeneralLedgerSpecs.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using jpboodhoo.bdd.contexts;
using MyMoney.Domain.accounting.billing;
using MyMoney.Domain.Core;
using MyMoney.Testing.Extensions;
@@ -13,42 +14,49 @@ namespace MyMoney.Domain.accounting
}
[Concern(typeof (general_ledger))]
- public class when_retrieving_all_the_entries_for_a_month_in_the_past : old_context_specification<IGeneralLedger>
+ public class behaves_like_a_general_ledger : concerns_for<IGeneralLedger, general_ledger>
{
- [Observation]
- public void it_should_return_all_the_entries_posted_for_that_month()
+ public override IGeneralLedger create_sut()
{
- result.should_contain(february_first);
- result.should_contain(february_twenty_first);
+ return new general_ledger(new List<ILedgerEntry> {february_first, february_twenty_first, april_first});
}
- [Observation]
- public void it_should_not_return_any_entries_that_were_not_posted_for_that_month()
- {
- result.should_not_contain(april_first);
- }
+ context c = () =>
+ {
+ february_first = an<ILedgerEntry>();
+ february_twenty_first = an<ILedgerEntry>();
+ april_first = an<ILedgerEntry>();
+ };
- protected override IGeneralLedger context()
- {
- february_first = an<ILedgerEntry>();
- february_twenty_first = an<ILedgerEntry>();
- april_first = an<ILedgerEntry>();
+ protected static ILedgerEntry february_first;
+ protected static ILedgerEntry february_twenty_first;
+ protected static ILedgerEntry april_first;
+ }
+
+ public class when_retrieving_all_the_entries_for_a_month_in_the_past : behaves_like_a_general_ledger
+ {
+ it should_return_all_the_entries_posted_for_that_month = () =>
+ {
+ result.should_contain(february_first);
+ result.should_contain(february_twenty_first);
+ };
- february_first.is_told_to(x => x.entry_date()).Return(new DateTime(2008, 02, 01));
- february_twenty_first.is_told_to(x => x.entry_date()).Return(new DateTime(2008, 02, 21));
- april_first.is_told_to(x => x.entry_date()).Return(new DateTime(2008, 04, 01));
+ it should_not_return_any_entries_that_were_not_posted_for_that_month =
+ () => result.should_not_contain(april_first);
- return new general_ledger(new List<ILedgerEntry> {february_first, february_twenty_first, april_first});
- }
+ context c = () =>
+ {
+ february_first = an<ILedgerEntry>();
+ february_twenty_first = an<ILedgerEntry>();
+ april_first = an<ILedgerEntry>();
- protected override void because()
- {
- result = sut.get_all_the_entries_for(Months.February);
- }
+ february_first.is_told_to(x => x.entry_date()).Return(new DateTime(2008, 02, 01));
+ february_twenty_first.is_told_to(x => x.entry_date()).Return(new DateTime(2008, 02, 21));
+ april_first.is_told_to(x => x.entry_date()).Return(new DateTime(2008, 04, 01));
+ };
+
+ because b = () => { result = sut.get_all_the_entries_for(Months.February); };
- private IEnumerable<ILedgerEntry> result;
- private ILedgerEntry february_first;
- private ILedgerEntry february_twenty_first;
- private ILedgerEntry april_first;
+ static IEnumerable<ILedgerEntry> result;
}
}
\ No newline at end of file
trunk/src/MyMoney/Domain/Core/range_specs.cs
@@ -1,121 +1,71 @@
+using jpboodhoo.bdd.contexts;
using MyMoney.Testing.Extensions;
using MyMoney.Testing.MetaData;
using MyMoney.Testing.spechelpers.contexts;
namespace MyMoney.Domain.Core
{
- public class range_specs
- {}
-
[Concern(typeof (range<int>))]
- public class when_a_range_from_1_to_10_is_asked_if_it_contains_the_number_1 :
- old_context_specification<IRange<int>>
+ public class behaves_like_a_range_from_1_to_10 : concerns_for<IRange<int>>
{
- [Observation]
- public void it_should_return_true()
- {
- result.should_be_equal_to(true);
- }
-
- protected override IRange<int> context()
+ public override IRange<int> create_sut()
{
return new range<int>(1, 10);
}
-
- protected override void because()
- {
- result = sut.contains(1);
- }
-
- private bool result;
}
[Concern(typeof (range<int>))]
- public class when_a_range_from_1_to_10_is_asked_if_it_contains_the_number_10 :
- old_context_specification<IRange<int>>
+ public class behaves_like_a_range_from_10_to_1 : concerns_for<IRange<int>>
{
- [Observation]
- public void it_should_return_true()
+ public override IRange<int> create_sut()
{
- result.should_be_equal_to(true);
+ return new range<int>(10, 1);
}
+ }
- protected override IRange<int> context()
- {
- return new range<int>(1, 10);
- }
+ public class when_a_range_from_1_to_10_is_asked_if_it_contains_the_number_1 : behaves_like_a_range_from_1_to_10
+ {
+ it should_return_true = () => result.should_be_equal_to(true);
- protected override void because()
- {
- result = sut.contains(10);
- }
+ because b = () => { result = sut.contains(1); };
- private bool result;
+ static bool result;
}
- [Concern(typeof (range<int>))]
- public class when_a_range_from_1_to_10_is_asked_if_it_contains_the_number_0 :
- old_context_specification<IRange<int>>
+ public class when_a_range_from_1_to_10_is_asked_if_it_contains_the_number_10 : behaves_like_a_range_from_1_to_10
{
- [Observation]
- public void it_should_return_false()
- {
- result.should_be_equal_to(false);
- }
+ it should_return_true = () => result.should_be_equal_to(true);
- protected override IRange<int> context()
- {
- return new range<int>(1, 10);
- }
+ because b = () => { result = sut.contains(10); };
- protected override void because()
- {
- result = sut.contains(0);
- }
-
- private bool result;
+ static bool result;
}
- [Concern(typeof (range<int>))]
- public class when_a_range_from_1_to_10_is_asked_if_it_contains_the_number_11 :
- old_context_specification<IRange<int>>
+ public class when_a_range_from_1_to_10_is_asked_if_it_contains_the_number_0 : behaves_like_a_range_from_1_to_10
{
- [Observation]
- public void it_should_return_false()
- {
- result.should_be_equal_to(false);
- }
+ it should_return_false = () => result.should_be_equal_to(false);
- protected override IRange<int> context()
- {
- return new range<int>(1, 10);
- }
-
- protected override void because()
- {
- result = sut.contains(0);
- }
+ because b = () => { result = sut.contains(0); };
- private bool result;
+ static bool result;
}
- [Concern(typeof (range<int>))]
- public class when_a_range_is_created_where_the_start_of_the_range_is_greater_than_the_end :
- old_context_specification<IRange<int>>
+ public class when_a_range_from_1_to_10_is_asked_if_it_contains_the_number_11 : behaves_like_a_range_from_1_to_10
{
- [Observation]
- public void it_should_flip_the_start_and_end_of_the_range()
- {
- sut.start_of_range.should_be_equal_to(1);
- sut.end_of_range.should_be_equal_to(10);
- }
+ it should_return_false = () => result.should_be_equal_to(false);
- protected override IRange<int> context()
- {
- return new range<int>(10, 1);
- }
+ because b = () => { result = sut.contains(0); };
+
+ static bool result;
+ }
- protected override void because()
- {}
+ public class when_a_range_is_created_where_the_start_of_the_range_is_greater_than_the_end :
+ behaves_like_a_range_from_10_to_1
+ {
+ it should_flip_the_start_and_end_of_the_range = () =>
+ {
+ sut.start_of_range.should_be_equal_to(1);
+ sut.end_of_range.should_be_equal_to(10);
+ };
}
}
\ No newline at end of file