From: <fab...@us...> - 2011-04-16 18:12:50
|
Revision: 5710 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5710&view=rev Author: fabiomaulo Date: 2011-04-16 18:12:44 +0000 (Sat, 16 Apr 2011) Log Message: ----------- Conformist union-subclass registration fix Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/UnionSubclassCustomizer.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/UnionSubclassMappingRegistrationTest.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/UnionSubclassCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/UnionSubclassCustomizer.cs 2011-04-16 18:09:08 UTC (rev 5709) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/UnionSubclassCustomizer.cs 2011-04-16 18:12:44 UTC (rev 5710) @@ -3,7 +3,7 @@ namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl { - public class UnionSubclassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IUnionSubclassMapper<TEntity> where TEntity : class + public class UnionSubclassCustomizer<TEntity> : PropertyContainerCustomizer<TEntity>, IUnionSubclassMapper<TEntity>, IConformistHoldersProvider where TEntity : class { public UnionSubclassCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, ICustomizersHolder customizersHolder) : base(explicitDeclarationsHolder, customizersHolder, null) @@ -111,5 +111,19 @@ } #endregion + + #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/UnionSubclassMappingRegistrationTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/UnionSubclassMappingRegistrationTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExpliticMappingTests/ConformistMappingRegistrationTests/UnionSubclassMappingRegistrationTest.cs 2011-04-16 18:12:44 UTC (rev 5710) @@ -0,0 +1,74 @@ +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NUnit.Framework; +using NHibernate.Mapping.ByCode; +using NHibernate.Mapping.ByCode.Conformist; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExpliticMappingTests.ConformistMappingRegistrationTests +{ + public class UnionSubclassMappingRegistrationTest + { + public class MyClass + { + public int Id { get; set; } + public string Something { get; set; } + } + public class Inherited : MyClass + { + public string SomethingElse { get; set; } + } + + private class MyClassMap : ClassMapping<MyClass> + { + public MyClassMap() + { + Id(x => x.Id, map => + { + map.Column("MyClassId"); + map.Generator(Generators.HighLow); + }); + Property(x => x.Something, map => map.Length(150)); + } + } + private class InheritedMap : UnionSubclassMapping<Inherited> + { + public InheritedMap() + { + Property(x => x.SomethingElse, map => map.Length(15)); + } + } + + [Test] + public void WhenRegisterClassMappingThenMapTheClass() + { + var mapper = new ModelMapper(); + mapper.AddMapping<MyClassMap>(); + mapper.AddMapping<InheritedMap>(); + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Inherited) }); + + ModelIsWellFormed(hbmMapping); + } + + [Test] + public void WhenRegisterClassMappingThroughTypeThenMapTheClass() + { + var mapper = new ModelMapper(); + mapper.AddMapping(typeof(MyClassMap)); + mapper.AddMapping(typeof(InheritedMap)); + var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Inherited) }); + + ModelIsWellFormed(hbmMapping); + } + + private void ModelIsWellFormed(HbmMapping hbmMapping) + { + var hbmClass = hbmMapping.UnionSubclasses.Single(); + hbmClass.Should().Not.Be.Null(); + hbmClass.extends.Should().Contain("MyClass"); + var hbmProperty = hbmClass.Properties.OfType<HbmProperty>().Single(); + hbmProperty.name.Should().Be("SomethingElse"); + hbmProperty.length.Should().Be("15"); + } + } +} \ 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:09:08 UTC (rev 5709) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-16 18:12:44 UTC (rev 5710) @@ -532,6 +532,7 @@ <Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\JoinedSubclassMappingRegistration.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\ModelMapperAddMappingByTypeTests.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\SubclassMappingRegistration.cs" /> + <Compile Include="MappingByCode\ExpliticMappingTests\ConformistMappingRegistrationTests\UnionSubclassMappingRegistrationTest.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\IdBagMappingTest.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\MappingOfPrivateMembersOnRootEntity.cs" /> <Compile Include="MappingByCode\ExpliticMappingTests\NaturalIdTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |