Skip to content

Commit

Permalink
Refactored "attribute" values into multiple layers instead of just
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jagregory committed Aug 12, 2011
1 parent ddd15d4 commit f3186cb
Show file tree
Hide file tree
Showing 281 changed files with 3,155 additions and 11,226 deletions.
22 changes: 21 additions & 1 deletion src/FluentNHibernate.5.1.ReSharper
Expand Up @@ -187,6 +187,22 @@
<Naming2>
<EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>
<EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort>
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="TypesAndNamespaces" />
<PredefinedRule Inspect="True" Prefix="I" Suffix="" Style="AaBb" ElementKind="Interfaces" />
<PredefinedRule Inspect="True" Prefix="T" Suffix="" Style="AaBb" ElementKind="TypeParameters" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="MethodPropertyEvent" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Locals" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="LocalConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Parameters" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PublicFields" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateInstanceFields" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateStaticFields" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Constants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="StaticReadonly" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateStaticReadonly" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="EnumMember" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Other" />
</Naming2>
</VB>
<Web>
Expand All @@ -198,7 +214,9 @@
<XML>
<FormatSettings />
</XML>
<GenerateMemberBody />
<GenerateMemberBody>
<MethodImplementationKind>ReturnDefaultValue</MethodImplementationKind>
</GenerateMemberBody>
<Naming2>
<EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>
<EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort>
Expand All @@ -221,6 +239,8 @@
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateStaticReadonly" />
<UserRule Inspect="False" Prefix="" Suffix="" Style="aa_bb" StaticnessKind="Static, Instance" AccessRight="Private, Protected, ProtectedInternal, Internal, Public" Description="MSpec naming">
<ElementKinds>
<Kind Name="TEST_TYPE" />
<Kind Name="TEST_MEMBER" />
<Kind Name="Machine.Specifications_Behavior" />
<Kind Name="Machine.Specifications_Context" />
<Kind Name="Machine.Specifications_Specification" />
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Steps;
using FluentNHibernate.MappingModel;
Expand Down Expand Up @@ -161,10 +160,8 @@ public abstract class AutoMapOneToManySpec
{
cfg = new TestConfiguration();
step = new HasManyStep(cfg);
container = new ClassMapping
{
Type = FakeMembers.Type
};
container = new ClassMapping();
container.Set(x => x.Type, Layer.Defaults, FakeMembers.Type);
};

protected static HasManyStep step;
Expand Down
4 changes: 2 additions & 2 deletions src/FluentNHibernate.Specs/SerializableSpecs.cs
Expand Up @@ -11,9 +11,9 @@ namespace FluentNHibernate.Specs
public class for_serialization_to_occur
{
Establish context = () =>
mapping_types = typeof(IMappingBase).Assembly
mapping_types = typeof(IMapping).Assembly
.GetTypes()
.Where(x => x.HasInterface(typeof(IMappingBase)) && !x.IsInterface);
.Where(x => x.HasInterface(typeof(IMapping)) && !x.IsInterface);

Because of = () =>
unserializable_types = mapping_types
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_two_m
};

Because of = () =>
visit(members_in_queue, supervisors_in_queue, membership_queues_in_user, supervised_queues_in_user);
Visit(members_in_queue, supervisors_in_queue, membership_queues_in_user, supervised_queues_in_user);

It should_call_the_user_defined_func = () =>
udf_was_called.ShouldBeTrue();
Expand Down Expand Up @@ -68,7 +68,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_two_m
};

Because of = () =>
ex = Catch.Exception(() => visit(fish_in_queue, chips_in_queue, bacon_in_queue, eggs_in_queue));
ex = Catch.Exception(() => Visit(fish_in_queue, chips_in_queue, bacon_in_queue, eggs_in_queue));

It should_not_fail = () =>
ex.ShouldBeNull();
Expand Down Expand Up @@ -115,7 +115,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_two_m
};

Because of = () =>
ex = Catch.Exception(() => visit(dsers_in_queue, fsers_in_queue, wueues_in_user, eueues_in_user));
ex = Catch.Exception(() => Visit(dsers_in_queue, fsers_in_queue, wueues_in_user, eueues_in_user));

It should_not_fail = () =>
ex.ShouldBeNull();
Expand Down Expand Up @@ -161,7 +161,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_a_man
};

Because of = () =>
visit(queues_in_user, users2_in_queue, users_in_queue);
Visit(queues_in_user, users2_in_queue, users_in_queue);

It should_call_the_user_defined_func = () =>
udf_was_called.ShouldBeTrue();
Expand Down Expand Up @@ -200,7 +200,7 @@ public class when_the_bi_directional_many_to_many_visitor_is_asked_to_pair_two_c
};

Because of = () =>
visit(users_in_queue, queues_in_user);
Visit(users_in_queue, queues_in_user);

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

bag.ContainingEntityType = typeof(T);
bag.Member = member;
bag.Relationship = new ManyToManyMapping();
bag.ChildType = member.PropertyType.GetGenericArguments()[0];
bag.Set(x => x.Relationship, Layer.Defaults, new ManyToManyMapping());
bag.Set(x => x.ChildType, Layer.Defaults, member.PropertyType.GetGenericArguments()[0]);

return bag;
}

protected static void visit(params CollectionMapping[] mappings)
protected static void Visit(params CollectionMapping[] mappings)
{
mappings.Each(visitor.Visit);
visitor.Visit(new HibernateMapping[0]); // simulate end of visit
Expand Down
19 changes: 7 additions & 12 deletions src/FluentNHibernate.Testing/AutoMapping/Steps/HasManyStepTests.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq.Expressions;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Steps;
using FluentNHibernate.MappingModel;
using FluentNHibernate.MappingModel.ClassBased;
using FluentNHibernate.MappingModel.Collections;
using FluentNHibernate.Utils.Reflection;
Expand Down Expand Up @@ -51,10 +52,8 @@ public void ShouldntMapEntities()
[Test]
public void ShouldMapListAsBag()
{
var classMapping = new ClassMapping()
{
Type = typeof(PropertyTarget)
};
var classMapping = new ClassMapping();
classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));

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

Expand All @@ -65,10 +64,8 @@ public void ShouldMapListAsBag()
[Test]
public void ShouldMapSetAsSet()
{
var classMapping = new ClassMapping()
{
Type = typeof(PropertyTarget)
};
var classMapping = new ClassMapping();
classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));

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

Expand All @@ -79,10 +76,8 @@ public void ShouldMapSetAsSet()
[Test]
public void ShouldMapHashSetAsSet()
{
var classMapping = new ClassMapping()
{
Type = typeof(PropertyTarget)
};
var classMapping = new ClassMapping();
classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));

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

Expand Down

This file was deleted.

36 changes: 23 additions & 13 deletions src/FluentNHibernate.Testing/AutoMapping/Steps/VersionStepTests.cs
Expand Up @@ -28,7 +28,8 @@ public void ShouldMapByteArray()
[Test]
public void ShouldMapByteArrayAsBinaryBlob()
{
var mapping = new ClassMapping { Type = typeof(Target) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

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

Expand All @@ -38,27 +39,30 @@ public void ShouldMapByteArrayAsBinaryBlob()
[Test]
public void ShouldMapByteArrayAsTimestampSqlType()
{
var mapping = new ClassMapping { Type = typeof(Target) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

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

SpecificationExtensions.ShouldBeTrue(mapping.Version.Columns.All(x => x.SqlType == "timestamp"));
mapping.Version.Columns.All(x => x.SqlType == "timestamp").ShouldBeTrue();
}

[Test]
public void ShouldMapByteArrayAsNotNull()
{
var mapping = new ClassMapping { Type = typeof(Target) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

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

SpecificationExtensions.ShouldBeTrue(mapping.Version.Columns.All(x => x.NotNull == true));
mapping.Version.Columns.All(x => x.NotNull).ShouldBeTrue();
}

[Test]
public void ShouldMapByteArrayWithUnsavedValueOfNull()
{
var mapping = new ClassMapping { Type = typeof(Target) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

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

Expand All @@ -68,7 +72,8 @@ public void ShouldMapByteArrayWithUnsavedValueOfNull()
[Test]
public void ShouldMapInheritedByteArray()
{
var mapping = new ClassMapping { Type = typeof(SubTarget) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(SubTarget));

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

Expand All @@ -78,7 +83,8 @@ public void ShouldMapInheritedByteArray()
[Test]
public void ShouldSetContainingEntityType()
{
var mapping = new ClassMapping { Type = typeof(Target) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

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

Expand Down Expand Up @@ -114,7 +120,8 @@ public void ShouldMapByteArray()
[Test]
public void ShouldMapByteArrayAsBinaryBlob()
{
var mapping = new ClassMapping { Type = typeof(Target) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

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

Expand All @@ -124,7 +131,8 @@ public void ShouldMapByteArrayAsBinaryBlob()
[Test]
public void ShouldMapByteArrayAsTimestampSqlType()
{
var mapping = new ClassMapping { Type = typeof(Target) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

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

Expand All @@ -134,17 +142,19 @@ public void ShouldMapByteArrayAsTimestampSqlType()
[Test]
public void ShouldMapByteArrayAsNotNull()
{
var mapping = new ClassMapping { Type = typeof(Target) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

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

mapping.Version.Columns.All(x => x.NotNull == true).ShouldBeTrue();
mapping.Version.Columns.All(x => x.NotNull).ShouldBeTrue();
}

[Test]
public void ShouldMapByteArrayWithUnsavedValueOfNull()
{
var mapping = new ClassMapping { Type = typeof(Target) };
var mapping = new ClassMapping();
mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

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

Expand Down

0 comments on commit f3186cb

Please sign in to comment.