main
1using developwithpassion.bdd.contexts;
2using Gorilla.Commons.Testing;
3using momoney.database.transactions;
4using momoney.service.infrastructure.transactions;
5
6namespace MoMoney.Service.Infrastructure.Transactions
7{
8 public class UnitOfWorkFactorySpecs
9 {
10 [Concern(typeof (UnitOfWorkFactory))]
11 public abstract class concerns_for_unit_of_work_factory : concerns_for<IUnitOfWorkFactory, UnitOfWorkFactory>
12 {
13 context c = () =>
14 {
15 session_context = the_dependency<IContext>();
16 factory = the_dependency<ISessionFactory>();
17 key = the_dependency<IKey<ISession>>();
18 };
19
20 static protected IContext session_context;
21 static protected ISessionFactory factory;
22 static protected IKey<ISession> key;
23 }
24
25 [Concern(typeof (UnitOfWorkFactory))]
26 public class when_a_unit_of_work_has_not_been_started : concerns_for_unit_of_work_factory
27 {
28 context c = () =>
29 {
30 when_the(session_context).is_told_to(x => x.contains(key)).it_will_return(false);
31 };
32 }
33
34 [Concern(typeof (UnitOfWorkFactory))]
35 public class when_a_unit_of_work_has_been_started : concerns_for_unit_of_work_factory
36 {
37 context c = () =>
38 {
39 when_the(session_context).is_told_to(x => x.contains(key)).it_will_return(true);
40 };
41 }
42
43 [Concern(typeof (UnitOfWorkFactory))]
44 public class when_creating_a_new_unit_of_work : when_a_unit_of_work_has_not_been_started
45 {
46 context c = () =>
47 {
48 session = an<ISession>();
49 when_the(factory).is_told_to(x => x.create()).it_will_return(session);
50 };
51
52 because b = () =>
53 {
54 result = sut.create();
55 };
56
57 it should_create_a_new_unit_of_work = () => factory.was_told_to(x => x.create());
58
59 it should_add_the_session_to_the_current_context = () => session_context.was_told_to(x => x.add(key, session));
60
61 it should_return_a_brand_new_unit_of_work = () =>
62 {
63 result.should_not_be_null();
64 result.should_be_an_instance_of<UnitOfWork>();
65 };
66
67 static IUnitOfWork result;
68 static ISession session;
69 }
70
71 [Concern(typeof (UnitOfWorkFactory))]
72 public class when_attempting_to_create_a_new_unit_of_work : when_a_unit_of_work_has_been_started
73 {
74 because b = () =>
75 {
76 result = sut.create();
77 };
78
79 it should_not_create_a_new_unit_of_work = () => factory.was_not_told_to(x => x.create());
80
81 it should_return_an_empty_unit_of_work = () =>
82 {
83 result.should_not_be_null();
84 result.should_be_an_instance_of<EmptyUnitOfWork>();
85 };
86
87 static IUnitOfWork result;
88 }
89 }
90}