blob: 39a71c897aeafc777efca01ebc502d11f41a0560 (
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.Core;
namespace MoMoney.DataAccess.Transactions
{
public class ChangeTrackerSpecs
{
}
[Concern(typeof (ChangeTracker<IIdentifiable<Guid>>))]
public abstract class behaves_like_change_tracker :
concerns_for<IChangeTracker<IIdentifiable<Guid>>, ChangeTracker<IIdentifiable<Guid>>>
{
context c = () =>
{
mapper = the_dependency<ITrackerEntryMapper<IIdentifiable<Guid>>>();
registry = the_dependency<IStatementRegistry>();
};
static protected ITrackerEntryMapper<IIdentifiable<Guid>> mapper;
static protected IStatementRegistry registry;
}
[Concern(typeof (ChangeTracker<IIdentifiable<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<IIdentifiable<Guid>>();
statement = an<IStatement>();
database = an<IDatabase>();
var entry = an<ITrackerEntry<IIdentifiable<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_command_for(item)).it_will_return(statement);
};
because b = () =>
{
sut.register(item);
sut.commit_to(database);
};
static IIdentifiable<Guid> item;
static IDatabase database;
static IStatement statement;
}
[Concern(typeof (ChangeTracker<IIdentifiable<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<IIdentifiable<Guid>>();
var registration = an<ITrackerEntry<IIdentifiable<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 IIdentifiable<Guid> item;
}
[Concern(typeof (ChangeTracker<IIdentifiable<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<IIdentifiable<Guid>>();
var entry = an<ITrackerEntry<IIdentifiable<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 IIdentifiable<Guid> item;
}
}
|