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