main
1using System;
2using developwithpassion.bdd.contexts;
3using Gorilla.Commons.Testing;
4using gorilla.commons.utility;
5
6namespace momoney.database.transactions
7{
8 public class ChangeTrackerSpecs
9 {
10
11 [Concern(typeof (ChangeTracker<Identifiable<Guid>>))]
12 public abstract class behaves_like_change_tracker :
13 concerns_for<IChangeTracker<Identifiable<Guid>>, ChangeTracker<Identifiable<Guid>>>
14 {
15 context c = () =>
16 {
17 mapper = the_dependency<ITrackerEntryMapper<Identifiable<Guid>>>();
18 registry = the_dependency<DatabaseCommandRegistry>();
19 };
20
21 static protected ITrackerEntryMapper<Identifiable<Guid>> mapper;
22 static protected DatabaseCommandRegistry registry;
23 }
24
25 [Concern(typeof (ChangeTracker<Identifiable<Guid>>))]
26 public class when_commit_that_changes_made_to_an_item : behaves_like_change_tracker
27 {
28 it should_save_the_changes_to_the_database = () => database.was_told_to(x => x.apply(statement));
29
30 context c = () =>
31 {
32 item = an<Identifiable<Guid>>();
33 statement = an<DatabaseCommand>();
34 database = an<IDatabase>();
35 var entry = an<ITrackerEntry<Identifiable<Guid>>>();
36
37 when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(entry);
38 when_the(entry).is_told_to(x => x.has_changes()).it_will_return(true);
39 when_the(entry).is_told_to(x => x.current).it_will_return(item);
40 when_the(registry).is_told_to(x => x.prepare_for_flushing(item)).it_will_return(statement);
41 };
42
43 because b = () =>
44 {
45 sut.register(item);
46 sut.commit_to(database);
47 };
48
49 static Identifiable<Guid> item;
50 static IDatabase database;
51 static DatabaseCommand statement;
52 }
53
54 [Concern(typeof (ChangeTracker<Identifiable<Guid>>))]
55 public class when_checking_if_there_are_changes_and_there_are : behaves_like_change_tracker
56 {
57 it should_tell_the_truth = () => result.should_be_true();
58
59 context c = () =>
60 {
61 item = an<Identifiable<Guid>>();
62 var registration = an<ITrackerEntry<Identifiable<Guid>>>();
63
64 when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(registration);
65 when_the(registration).is_told_to(x => x.has_changes()).it_will_return(true);
66 when_the(registration).is_told_to(x => x.current).it_will_return(item);
67 };
68
69 because b = () =>
70 {
71 sut.register(item);
72 result = sut.is_dirty();
73 };
74
75 static bool result;
76 static Identifiable<Guid> item;
77 }
78
79 [Concern(typeof (ChangeTracker<Identifiable<Guid>>))]
80 public class when_checking_if_there_are_changes_and_there_are_not : behaves_like_change_tracker
81 {
82 it should_tell_the_truth = () => result.should_be_false();
83
84 context c = () =>
85 {
86 item = an<Identifiable<Guid>>();
87 var entry = an<ITrackerEntry<Identifiable<Guid>>>();
88
89 when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(entry);
90 when_the(entry).is_told_to(x => x.has_changes()).it_will_return(false);
91 };
92
93 because b = () =>
94 {
95 sut.register(item);
96 result = sut.is_dirty();
97 };
98
99 static bool result;
100 static Identifiable<Guid> item;
101 }
102 }
103}