|
From: <fab...@us...> - 2011-04-16 18:26:36
|
Revision: 5711
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5711&view=rev
Author: fabiomaulo
Date: 2011-04-16 18:26:30 +0000 (Sat, 16 Apr 2011)
Log Message:
-----------
Conformist component registration fix
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentCustomizer.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ComponentMappingRegistrationTest.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentCustomizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentCustomizer.cs 2011-04-16 18:12:44 UTC (rev 5710)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/ComponentCustomizer.cs 2011-04-16 18:26:30 UTC (rev 5711)
@@ -4,7 +4,7 @@
namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl
{
- public class ComponentCustomizer<TComponent> : PropertyContainerCustomizer<TComponent>, IComponentMapper<TComponent>
+ public class ComponentCustomizer<TComponent> : PropertyContainerCustomizer<TComponent>, IComponentMapper<TComponent>, IConformistHoldersProvider
where TComponent : class
{
public ComponentCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder)
@@ -96,5 +96,19 @@
CustomizersHolder.AddCustomizer(PropertyPath, classCustomizer);
}
}
+
+ #region IConformistHoldersProvider Members
+
+ ICustomizersHolder IConformistHoldersProvider.CustomizersHolder
+ {
+ get { return CustomizersHolder; }
+ }
+
+ IModelExplicitDeclarationsHolder IConformistHoldersProvider.ExplicitDeclarationsHolder
+ {
+ get { return ExplicitDeclarationsHolder; }
+ }
+
+ #endregion
}
}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ComponentMappingRegistrationTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ComponentMappingRegistrationTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/ComponentMappingRegistrationTest.cs 2011-04-16 18:26:30 UTC (rev 5711)
@@ -0,0 +1,80 @@
+using System.Linq;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Mapping.ByCode;
+using NHibernate.Mapping.ByCode.Conformist;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ExpliticMappingTests.ConformistMappingRegistrationTests
+{
+ public class ComponentMappingRegistrationTest
+ {
+ public class MyClass
+ {
+ public int Id { get; set; }
+ public Name Name { get; set; }
+ }
+
+ public class Name
+ {
+ public string First { get; set; }
+ public string Last { get; set; }
+ }
+ private class MyClassMap : ClassMapping<MyClass>
+ {
+ public MyClassMap()
+ {
+ Id(x => x.Id, map =>
+ {
+ map.Column("MyClassId");
+ map.Generator(Generators.HighLow);
+ });
+ Component(x => x.Name, z => { });
+ }
+ }
+ private class NameMap : ComponentMapping<Name>
+ {
+ public NameMap()
+ {
+ Property(x => x.First, map => map.Length(20));
+ Property(x => x.Last, map => map.Length(30));
+ }
+ }
+
+ [Test]
+ public void WhenRegisterClassMappingThenMapTheClass()
+ {
+ var mapper = new ModelMapper();
+ mapper.AddMapping<MyClassMap>();
+ mapper.AddMapping<NameMap>();
+ var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
+
+ ModelIsWellFormed(hbmMapping);
+ }
+
+ [Test]
+ public void WhenRegisterClassMappingThroughTypeThenMapTheClass()
+ {
+ var mapper = new ModelMapper();
+ mapper.AddMapping(typeof(MyClassMap));
+ mapper.AddMapping(typeof(NameMap));
+ var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
+
+ ModelIsWellFormed(hbmMapping);
+ }
+
+ private void ModelIsWellFormed(HbmMapping hbmMapping)
+ {
+ var hbmClass = hbmMapping.RootClasses.Single();
+ hbmClass.Properties.Should().Have.Count.EqualTo(1);
+ var hbmComponent = hbmClass.Properties.OfType<HbmComponent>().Single();
+ hbmComponent.name.Should().Be("Name");
+ hbmComponent.Properties.Should().Have.Count.EqualTo(2);
+ var hbmp1 = hbmComponent.Properties.OfType<HbmProperty>().Single(x => x.name == "First");
+ var hbmp2 = hbmComponent.Properties.OfType<HbmProperty>().Single(x => x.name == "Last");
+
+ hbmp1.length.Should().Be("20");
+ hbmp2.length.Should().Be("30");
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-16 18:12:44 UTC (rev 5710)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-16 18:26:30 UTC (rev 5711)
@@ -529,6 +529,7 @@
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassSequenceRegistrationTests.cs" />
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\UnionSubclassMappingStrategyTests.cs" />
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\UnionSubclassSequenceRegistrationTests.cs" />
+ <Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ComponentMappingRegistrationTest.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\JoinedSubclassMappingRegistration.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ModelMapperAddMappingByTypeTests.cs" />
<Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\SubclassMappingRegistration.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|