Skip to content

Commit f3186cb

Browse files
committed
Refactored "attribute" values into multiple layers instead of just
defaults and non-defaults. We've now got three layers: defaults, conventions, and user-supplied. This distinction allows us to provide sensible default values which get overwritten by conventions, and user supplied values that override conventions.
1 parent ddd15d4 commit f3186cb

File tree

281 files changed

+3155
-11226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+3155
-11226
lines changed

src/FluentNHibernate.5.1.ReSharper

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@
187187
<Naming2>
188188
<EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>
189189
<EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort>
190+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="TypesAndNamespaces" />
191+
<PredefinedRule Inspect="True" Prefix="I" Suffix="" Style="AaBb" ElementKind="Interfaces" />
192+
<PredefinedRule Inspect="True" Prefix="T" Suffix="" Style="AaBb" ElementKind="TypeParameters" />
193+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="MethodPropertyEvent" />
194+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Locals" />
195+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="LocalConstants" />
196+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Parameters" />
197+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PublicFields" />
198+
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateInstanceFields" />
199+
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateStaticFields" />
200+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Constants" />
201+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateConstants" />
202+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="StaticReadonly" />
203+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateStaticReadonly" />
204+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="EnumMember" />
205+
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Other" />
190206
</Naming2>
191207
</VB>
192208
<Web>
@@ -198,7 +214,9 @@
198214
<XML>
199215
<FormatSettings />
200216
</XML>
201-
<GenerateMemberBody />
217+
<GenerateMemberBody>
218+
<MethodImplementationKind>ReturnDefaultValue</MethodImplementationKind>
219+
</GenerateMemberBody>
202220
<Naming2>
203221
<EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>
204222
<EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort>
@@ -221,6 +239,8 @@
221239
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateStaticReadonly" />
222240
<UserRule Inspect="False" Prefix="" Suffix="" Style="aa_bb" StaticnessKind="Static, Instance" AccessRight="Private, Protected, ProtectedInternal, Internal, Public" Description="MSpec naming">
223241
<ElementKinds>
242+
<Kind Name="TEST_TYPE" />
243+
<Kind Name="TEST_MEMBER" />
224244
<Kind Name="Machine.Specifications_Behavior" />
225245
<Kind Name="Machine.Specifications_Context" />
226246
<Kind Name="Machine.Specifications_Specification" />

src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Linq;
1+
using System.Linq;
32
using FluentNHibernate.Automapping;
43
using FluentNHibernate.Automapping.Steps;
54
using FluentNHibernate.MappingModel;
@@ -161,10 +160,8 @@ public abstract class AutoMapOneToManySpec
161160
{
162161
cfg = new TestConfiguration();
163162
step = new HasManyStep(cfg);
164-
container = new ClassMapping
165-
{
166-
Type = FakeMembers.Type
167-
};
163+
container = new ClassMapping();
164+
container.Set(x => x.Type, Layer.Defaults, FakeMembers.Type);
168165
};
169166

170167
protected static HasManyStep step;

src/FluentNHibernate.Specs/SerializableSpecs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace FluentNHibernate.Specs
1111
public class for_serialization_to_occur
1212
{
1313
Establish context = () =>
14-
mapping_types = typeof(IMappingBase).Assembly
14+
mapping_types = typeof(IMapping).Assembly
1515
.GetTypes()
16-
.Where(x => x.HasInterface(typeof(IMappingBase)) && !x.IsInterface);
16+
.Where(x => x.HasInterface(typeof(IMapping)) && !x.IsInterface);
1717

1818
Because of = () =>
1919
unserializable_types = mapping_types

src/FluentNHibernate.Specs/Visitors/BiDirectionalManyToManyPairingVisitorSpecs.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_two_m
2121
};
2222

2323
Because of = () =>
24-
visit(members_in_queue, supervisors_in_queue, membership_queues_in_user, supervised_queues_in_user);
24+
Visit(members_in_queue, supervisors_in_queue, membership_queues_in_user, supervised_queues_in_user);
2525

2626
It should_call_the_user_defined_func = () =>
2727
udf_was_called.ShouldBeTrue();
@@ -68,7 +68,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_two_m
6868
};
6969

7070
Because of = () =>
71-
ex = Catch.Exception(() => visit(fish_in_queue, chips_in_queue, bacon_in_queue, eggs_in_queue));
71+
ex = Catch.Exception(() => Visit(fish_in_queue, chips_in_queue, bacon_in_queue, eggs_in_queue));
7272

7373
It should_not_fail = () =>
7474
ex.ShouldBeNull();
@@ -115,7 +115,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_two_m
115115
};
116116

117117
Because of = () =>
118-
ex = Catch.Exception(() => visit(dsers_in_queue, fsers_in_queue, wueues_in_user, eueues_in_user));
118+
ex = Catch.Exception(() => Visit(dsers_in_queue, fsers_in_queue, wueues_in_user, eueues_in_user));
119119

120120
It should_not_fail = () =>
121121
ex.ShouldBeNull();
@@ -161,7 +161,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_a_man
161161
};
162162

163163
Because of = () =>
164-
visit(queues_in_user, users2_in_queue, users_in_queue);
164+
Visit(queues_in_user, users2_in_queue, users_in_queue);
165165

166166
It should_call_the_user_defined_func = () =>
167167
udf_was_called.ShouldBeTrue();
@@ -200,7 +200,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_two_c
200200
};
201201

202202
Because of = () =>
203-
visit(users_in_queue, queues_in_user);
203+
Visit(users_in_queue, queues_in_user);
204204

205205
It should_call_the_user_defined_func = () =>
206206
udf_was_called.ShouldBeTrue();
@@ -243,13 +243,13 @@ protected static CollectionMapping collection<T>(Expression<Func<T, object>> exp
243243

244244
bag.ContainingEntityType = typeof(T);
245245
bag.Member = member;
246-
bag.Relationship = new ManyToManyMapping();
247-
bag.ChildType = member.PropertyType.GetGenericArguments()[0];
246+
bag.Set(x => x.Relationship, Layer.Defaults, new ManyToManyMapping());
247+
bag.Set(x => x.ChildType, Layer.Defaults, member.PropertyType.GetGenericArguments()[0]);
248248

249249
return bag;
250250
}
251251

252-
protected static void visit(params CollectionMapping[] mappings)
252+
protected static void Visit(params CollectionMapping[] mappings)
253253
{
254254
mappings.Each(visitor.Visit);
255255
visitor.Visit(new HibernateMapping[0]); // simulate end of visit

src/FluentNHibernate.Testing/AutoMapping/Steps/HasManyStepTests.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq.Expressions;
44
using FluentNHibernate.Automapping;
55
using FluentNHibernate.Automapping.Steps;
6+
using FluentNHibernate.MappingModel;
67
using FluentNHibernate.MappingModel.ClassBased;
78
using FluentNHibernate.MappingModel.Collections;
89
using FluentNHibernate.Utils.Reflection;
@@ -51,10 +52,8 @@ public void ShouldntMapEntities()
5152
[Test]
5253
public void ShouldMapListAsBag()
5354
{
54-
var classMapping = new ClassMapping()
55-
{
56-
Type = typeof(PropertyTarget)
57-
};
55+
var classMapping = new ClassMapping();
56+
classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));
5857

5958
mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("List").ToMember());
6059

@@ -65,10 +64,8 @@ public void ShouldMapListAsBag()
6564
[Test]
6665
public void ShouldMapSetAsSet()
6766
{
68-
var classMapping = new ClassMapping()
69-
{
70-
Type = typeof(PropertyTarget)
71-
};
67+
var classMapping = new ClassMapping();
68+
classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));
7269

7370
mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("Set").ToMember());
7471

@@ -79,10 +76,8 @@ public void ShouldMapSetAsSet()
7976
[Test]
8077
public void ShouldMapHashSetAsSet()
8178
{
82-
var classMapping = new ClassMapping()
83-
{
84-
Type = typeof(PropertyTarget)
85-
};
79+
var classMapping = new ClassMapping();
80+
classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));
8681

8782
mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("HashSet").ToMember());
8883

src/FluentNHibernate.Testing/AutoMapping/Steps/IdentityStepTests.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/FluentNHibernate.Testing/AutoMapping/Steps/VersionStepTests.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public void ShouldMapByteArray()
2828
[Test]
2929
public void ShouldMapByteArrayAsBinaryBlob()
3030
{
31-
var mapping = new ClassMapping { Type = typeof(Target) };
31+
var mapping = new ClassMapping();
32+
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));
3233

3334
mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());
3435

@@ -38,27 +39,30 @@ public void ShouldMapByteArrayAsBinaryBlob()
3839
[Test]
3940
public void ShouldMapByteArrayAsTimestampSqlType()
4041
{
41-
var mapping = new ClassMapping { Type = typeof(Target) };
42+
var mapping = new ClassMapping();
43+
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));
4244

4345
mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());
4446

45-
SpecificationExtensions.ShouldBeTrue(mapping.Version.Columns.All(x => x.SqlType == "timestamp"));
47+
mapping.Version.Columns.All(x => x.SqlType == "timestamp").ShouldBeTrue();
4648
}
4749

4850
[Test]
4951
public void ShouldMapByteArrayAsNotNull()
5052
{
51-
var mapping = new ClassMapping { Type = typeof(Target) };
53+
var mapping = new ClassMapping();
54+
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));
5255

5356
mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());
5457

55-
SpecificationExtensions.ShouldBeTrue(mapping.Version.Columns.All(x => x.NotNull == true));
58+
mapping.Version.Columns.All(x => x.NotNull).ShouldBeTrue();
5659
}
5760

5861
[Test]
5962
public void ShouldMapByteArrayWithUnsavedValueOfNull()
6063
{
61-
var mapping = new ClassMapping { Type = typeof(Target) };
64+
var mapping = new ClassMapping();
65+
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));
6266

6367
mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());
6468

@@ -68,7 +72,8 @@ public void ShouldMapByteArrayWithUnsavedValueOfNull()
6872
[Test]
6973
public void ShouldMapInheritedByteArray()
7074
{
71-
var mapping = new ClassMapping { Type = typeof(SubTarget) };
75+
var mapping = new ClassMapping();
76+
mapping.Set(x => x.Type, Layer.Defaults, typeof(SubTarget));
7277

7378
mapper.Map(mapping, typeof(SubTarget).GetProperty("Version").ToMember());
7479

@@ -78,7 +83,8 @@ public void ShouldMapInheritedByteArray()
7883
[Test]
7984
public void ShouldSetContainingEntityType()
8085
{
81-
var mapping = new ClassMapping { Type = typeof(Target) };
86+
var mapping = new ClassMapping();
87+
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));
8288

8389
mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());
8490

@@ -114,7 +120,8 @@ public void ShouldMapByteArray()
114120
[Test]
115121
public void ShouldMapByteArrayAsBinaryBlob()
116122
{
117-
var mapping = new ClassMapping { Type = typeof(Target) };
123+
var mapping = new ClassMapping();
124+
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));
118125

119126
mapper.Map(mapping, ReflectionHelper.GetMember<BaseEntityClass>(x => x.Version));
120127

@@ -124,7 +131,8 @@ public void ShouldMapByteArrayAsBinaryBlob()
124131
[Test]
125132
public void ShouldMapByteArrayAsTimestampSqlType()
126133
{
127-
var mapping = new ClassMapping { Type = typeof(Target) };
134+
var mapping = new ClassMapping();
135+
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));
128136

129137
mapper.Map(mapping, ReflectionHelper.GetMember<BaseEntityClass>(x => x.Version));
130138

@@ -134,17 +142,19 @@ public void ShouldMapByteArrayAsTimestampSqlType()
134142
[Test]
135143
public void ShouldMapByteArrayAsNotNull()
136144
{
137-
var mapping = new ClassMapping { Type = typeof(Target) };
145+
var mapping = new ClassMapping();
146+
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));
138147

139148
mapper.Map(mapping, ReflectionHelper.GetMember<BaseEntityClass>(x => x.Version));
140149

141-
mapping.Version.Columns.All(x => x.NotNull == true).ShouldBeTrue();
150+
mapping.Version.Columns.All(x => x.NotNull).ShouldBeTrue();
142151
}
143152

144153
[Test]
145154
public void ShouldMapByteArrayWithUnsavedValueOfNull()
146155
{
147-
var mapping = new ClassMapping { Type = typeof(Target) };
156+
var mapping = new ClassMapping();
157+
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));
148158

149159
mapper.Map(mapping, ReflectionHelper.GetMember<BaseEntityClass>(x => x.Version));
150160

0 commit comments

Comments
 (0)