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 UnitOfWorkSpecs
 9    {
10        [Concern(typeof (UnitOfWork))]
11        public abstract class behaves_like_unit_of_work : concerns_for<IUnitOfWork, UnitOfWork>
12        {
13            context c = () =>
14            {
15                session_context = the_dependency<IContext>();
16                session = the_dependency<ISession>();
17                key = the_dependency<IKey<ISession>>();
18            };
19
20            static protected IContext session_context;
21            static protected ISession session;
22            static protected IKey<ISession> key;
23        }
24
25        [Concern(typeof (UnitOfWork))]
26        public abstract class when_a_unit_of_work_has_unsaved_changes : behaves_like_unit_of_work
27        {
28            context c = () => when_the(session).is_told_to(x => x.is_dirty()).it_will_return(true);
29        }
30
31        [Concern(typeof (UnitOfWork))]
32        public abstract class when_a_unit_of_work_has_no_changes : behaves_like_unit_of_work
33        {
34            context c = () => when_the(session).is_told_to(x => x.is_dirty()).it_will_return(false);
35        }
36
37        [Concern(typeof (UnitOfWork))]
38        public class when_checking_if_a_unit_of_work_has_any_unsaved_changes : when_a_unit_of_work_has_unsaved_changes
39        {
40            it should_return_true = () => result.should_be_true();
41
42            because b = () =>
43            {
44                result = sut.is_dirty();
45            };
46
47            static bool result;
48        }
49
50        [Concern(typeof (UnitOfWork))]
51        public class when_commiting_a_unit_of_work : when_a_unit_of_work_has_unsaved_changes
52        {
53            it should_flush_the_current_session = () => session.was_told_to(x => x.flush());
54            because b = () => sut.commit();
55        }
56
57        [Concern(typeof (UnitOfWork))]
58        public class when_attempting_to_commit_a_unit_of_work : when_a_unit_of_work_has_no_changes
59        {
60            it should_not_flush_the_session = () => session.was_not_told_to(x => x.flush());
61            because b = () => sut.commit();
62        }
63
64        [Concern(typeof (UnitOfWork))]
65        public class when_disposing_of_a_unit_of_work : behaves_like_unit_of_work
66        {
67            it should_dispose_the_session = () => session.was_told_to(x => x.Dispose());
68            it should_remove_the_session_from_the_current_context = () => session_context.was_told_to(x => x.remove(key));
69            because b = () => sut.Dispose();
70        }
71    }
72}