From: <fab...@us...> - 2011-04-02 18:58:57
|
Revision: 5576 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5576&view=rev Author: fabiomaulo Date: 2011-04-02 18:58:51 +0000 (Sat, 02 Apr 2011) Log Message: ----------- subclasses registration Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassMappingStrategyTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 18:49:26 UTC (rev 5575) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 18:58:51 UTC (rev 5576) @@ -155,6 +155,10 @@ { throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as root-entity and as subclass for table-per-class strategy", type.FullName)); } + if (IsMappedFor(tablePerClassHierarchyEntities, type)) + { + throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); + } tablePerClassEntities.Add(rootEntity); } } @@ -185,7 +189,7 @@ { throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as root-entity and as subclass for table-per-class-hierarchy strategy", type.FullName)); } - if (IsMappedFor(tablePerClassEntities, type)) + if (IsMappedFor(tablePerClassEntities, type) || IsMappedFor(tablePerClassHierarchyEntities, type)) { throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); } @@ -203,7 +207,7 @@ { throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as root-entity and as subclass for table-per-concrete-class strategy", type.FullName)); } - if (IsMappedFor(tablePerClassEntities, type)) + if (IsMappedFor(tablePerClassEntities, type) || IsMappedFor(tablePerClassHierarchyEntities, type)) { throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName)); } @@ -331,7 +335,7 @@ public bool IsTablePerClassHierarchy(System.Type type) { - return tablePerClassHierarchyEntities.Contains(type); + return IsMappedFor(tablePerClassHierarchyEntities, type); } public bool IsTablePerClassHierarchyJoin(System.Type type) Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassMappingStrategyTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassMappingStrategyTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/SubclassMappingStrategyTests.cs 2011-04-02 18:58:51 UTC (rev 5576) @@ -0,0 +1,79 @@ +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExplicitlyDeclaredModelTests +{ + public class SubclassMappingStrategyTests + { + private class MyClass + { + + } + private class Inherited1 : MyClass + { + + } + private class Inherited2 : Inherited1 + { + + } + + [Test] + public void WhenRegisteredAsSubclassThenIsRegistered() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsRootEntity(typeof(MyClass)); + inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1)); + + inspector.IsTablePerClass(typeof(Inherited1)).Should().Be.False(); + inspector.IsTablePerClassHierarchy(typeof(Inherited1)).Should().Be.True(); + inspector.IsTablePerClassHierarchyJoin(typeof(Inherited1)).Should().Be.False(); + inspector.IsTablePerConcreteClass(typeof(Inherited1)).Should().Be.False(); + } + + [Test] + public void WhenRegisteredAsDeepSubclassThenIsRegistered() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsRootEntity(typeof(MyClass)); + inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited2)); + + inspector.IsTablePerClass(typeof(Inherited2)).Should().Be.False(); + inspector.IsTablePerClassHierarchy(typeof(Inherited2)).Should().Be.True(); + inspector.IsTablePerClassHierarchyJoin(typeof(Inherited2)).Should().Be.False(); + inspector.IsTablePerConcreteClass(typeof(Inherited2)).Should().Be.False(); + } + + [Test] + public void WhenRegisteredAsSubclassThenCantRegisterAsJoinedSubclass() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsRootEntity(typeof(MyClass)); + inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1)); + + inspector.Executing(x => x.AddAsTablePerClassEntity(typeof(Inherited1))).Throws<MappingException>(); + } + + [Test] + public void WhenRegisteredAsSubclassThenCantRegisterAsSubclassJoin() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsRootEntity(typeof(MyClass)); + inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1)); + + inspector.Executing(x => x.AddAsTablePerClassHierarchyJoinEntity(typeof(Inherited1))).Throws<MappingException>(); + } + + [Test] + public void WhenRegisteredAsSubclassThenCantRegisterAsUnionSubclass() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsRootEntity(typeof(MyClass)); + inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1)); + + inspector.Executing(x => x.AddAsTablePerConcreteClassEntity(typeof(Inherited1))).Throws<MappingException>(); + } + + } +} \ 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-02 18:49:26 UTC (rev 5575) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-02 18:58:51 UTC (rev 5576) @@ -510,6 +510,7 @@ <Compile Include="MappingByCode\ColumnsNamingConvetions.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\JoinedSubclassMappingStrategyTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\RootClassMappingStrategyTests.cs" /> + <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassMappingStrategyTests.cs" /> <Compile Include="MappingByCode\MappingOfPrivateMembersOnRootEntity.cs" /> <Compile Include="NHSpecificTest\AccessAndCorrectPropertyName\Fixture.cs" /> <Compile Include="NHSpecificTest\AccessAndCorrectPropertyName\Model.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |