forked from tpolyak/Sharp-Architecture
/
HasUniqueDomainSignatureSpecs.cs
209 lines (163 loc) · 8.07 KB
/
HasUniqueDomainSignatureSpecs.cs
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//-------------------------------------------------------------------------------------------------
// <auto-generated>
// Marked as auto-generated so StyleCop will ignore BDD style tests
// </auto-generated>
//-------------------------------------------------------------------------------------------------
#pragma warning disable 169
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
namespace SharpArch.Specifications.NHibernate
{
using System;
using global::SharpArch.Domain;
using global::SharpArch.Domain.PersistenceSupport;
using global::SharpArch.Features.Specifications;
using global::SharpArch.NHibernate;
using global::SharpArch.NHibernate.NHibernateValidator;
using Machine.Specifications;
using global::SharpArch.Testing.NUnit.NHibernate;
public class has_unique_domain_signature_specs
{
public abstract class specification_for_has_unique_domain_signature_validator
{
protected static IEntityDuplicateChecker entityDuplicateChecker;
Establish context = () =>
{
entityDuplicateChecker = new EntityDuplicateChecker();
entityDuplicateChecker.AddToServiceLocator();
};
Cleanup after = ServiceLocatorHelper.Reset;
}
[Subject(typeof(HasUniqueDomainSignatureAttribute))]
public class when_validating_an_entity_and_a_duplicate_exists : specification_for_has_unique_domain_signature_validator
{
static Contractor duplicateContractor;
static bool result;
Establish context = () =>
{
var contractor = new Contractor() { Name = "codai" };
NHibernateSession.Current.Save(contractor);
RepositoryTestsHelper.FlushSessionAndEvict(contractor);
duplicateContractor = new Contractor() { Name = "codai" };
};
Because of = () =>
{
result = duplicateContractor.IsValid();
};
It should_say_the_entity_is_invalid = () => result.ShouldBeFalse();
}
[Subject(typeof(HasUniqueDomainSignatureWithGuidIdAttribute))]
public class when_validating_an_entity_with_a_guid_id_and_a_duplicate_exists : specification_for_has_unique_domain_signature_validator
{
static ObjectWithGuidId duplicateObjectWithGuidId;
static bool result;
Establish context = () =>
{
var objectWithGuidId = new ObjectWithGuidId { Name = "codai" };
NHibernateSession.Current.Save(objectWithGuidId);
RepositoryTestsHelper.FlushSessionAndEvict(objectWithGuidId);
duplicateObjectWithGuidId = new ObjectWithGuidId { Name = "codai" };
};
Because of = () => result = duplicateObjectWithGuidId.IsValid();
It should_say_the_entity_is_invalid = () => result.ShouldBeFalse();
}
[Subject(typeof(HasUniqueDomainSignatureWithStringIdAttribute))]
public class when_validating_an_entity_with_a_string_id_and_a_duplicate_exists : specification_for_has_unique_domain_signature_validator
{
static User duplicateUser;
static bool result;
Establish context = () =>
{
var user = new User("user1", "123-12-1234");
NHibernateSession.Current.Save(user);
RepositoryTestsHelper.FlushSessionAndEvict(user);
duplicateUser = new User("user2", "123-12-1234");
};
Because of = () => result = duplicateUser.IsValid();
It should_say_the_entity_is_invalid = () => result.ShouldBeFalse();
}
[Subject(typeof(HasUniqueDomainSignatureAttribute))]
public class when_validating_an_entity_and_the_entity_is_unique : specification_for_has_unique_domain_signature_validator
{
static Contractor contractor;
static bool result;
Establish context = () =>
{
contractor = new Contractor { Name = "the name" };
};
Because of = () => result = contractor.IsValid();
It should_say_the_entity_is_valid = () => result.ShouldBeTrue();
}
[Subject(typeof(HasUniqueDomainSignatureAttribute))]
public class when_validating_an_entity_with_the_wrong_validator_type : specification_for_has_unique_domain_signature_validator
{
static ObjectWithStringIdAndValidatorForIntId entity;
static Exception result;
Establish context = () =>
{
Check.UseAssertions = false;
entity = new ObjectWithStringIdAndValidatorForIntId { Name = "whatever" };
};
Because of = () => result = Catch.Exception(() => entity.IsValid());
It should_throw_a_precondition_exception = () => result.ShouldBeOfType(typeof(PreconditionException));
}
[Subject(typeof(HasUniqueDomainSignatureAttribute))]
public class when_validating_a_unique_entity_that_has_another_entity_as_part_of_domain_signature : specification_for_has_unique_domain_signature_validator
{
static Song song;
static bool result;
private Establish context = () =>
{
var tigerlillies = new Band() { BandName = "The Tiger Lillies", DateFormed = DateTime.Now };
NHibernateSession.Current.Save(tigerlillies);
RepositoryTestsHelper.FlushSessionAndEvict(tigerlillies);
song = new Song() { Performer = tigerlillies, SongTitle = "Souvenirs" };
};
Because of = () => result = song.IsValid();
It should_say_the_entity_is_valid = () => result.ShouldBeTrue();
}
[Subject(typeof(HasUniqueDomainSignatureAttribute))]
public class when_validating_a_unique_entity_that_has_a_null_value_domain_signature_property : specification_for_has_unique_domain_signature_validator
{
static Song song;
static bool result;
private Establish context = () =>
{
song = new Song() { SongTitle = "Souvenirs" };
};
Because of = () => result = song.IsValid();
It should_say_the_entity_is_valid = () => result.ShouldBeTrue();
}
[Subject(typeof(HasUniqueDomainSignatureAttribute))]
public class when_validating_a_duplicate_entity_that_has_another_entity_as_part_of_domain_signature : specification_for_has_unique_domain_signature_validator
{
static Song duplicateSong;
static bool result;
private Establish context = () =>
{
var tragicRoundabout = new Band() { BandName = "Tragic Roundabout", DateFormed = DateTime.Now };
NHibernateSession.Current.Save(tragicRoundabout);
var song = new Song() { Performer = tragicRoundabout, SongTitle = "Prince Geek" };
NHibernateSession.Current.Save(song);
duplicateSong = new Song() { Performer = tragicRoundabout, SongTitle = "Prince Geek" };
};
Because of = () => result = duplicateSong.IsValid();
It should_say_the_entity_is_invalid = () => result.ShouldBeFalse();
}
[Subject(typeof(HasUniqueDomainSignatureAttribute))]
public class when_validating_a_duplicate_entity_that_has_a_null_value_domain_signature_property : specification_for_has_unique_domain_signature_validator
{
static Song duplicateSong;
static bool result;
private Establish context = () =>
{
var song = new Song() { SongTitle = "Souvenirs" };
NHibernateSession.Current.Save(song);
duplicateSong = new Song() { SongTitle = "Souvenirs" };
};
Because of = () => result = duplicateSong.IsValid();
It should_say_the_entity_is_valid = () => result.ShouldBeFalse();
}
}
}