|
From: <fab...@us...> - 2011-04-02 19:14:14
|
Revision: 5578
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5578&view=rev
Author: fabiomaulo
Date: 2011-04-02 19:14:08 +0000 (Sat, 02 Apr 2011)
Log Message:
-----------
union-subclass classes 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/UnionSubclassMappingStrategyTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 19:06:54 UTC (rev 5577)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 19:14:08 UTC (rev 5578)
@@ -155,7 +155,7 @@
{
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))
+ if (IsMappedFor(tablePerClassHierarchyEntities, type) || IsMappedFor(tablePerConcreteClassEntities, type))
{
throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName));
}
@@ -172,7 +172,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) || tablePerClassHierarchyJoinEntities.Contains(type))
+ if (IsMappedFor(tablePerClassEntities, type) || tablePerClassHierarchyJoinEntities.Contains(type) || IsMappedFor(tablePerConcreteClassEntities, type))
{
throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName));
}
@@ -189,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) || IsMappedFor(tablePerClassHierarchyEntities, type))
+ if (IsMappedFor(tablePerClassEntities, type) || IsMappedFor(tablePerClassHierarchyEntities, type) || IsMappedFor(tablePerConcreteClassEntities, type))
{
throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered with more than one class-hierarchy strategy", type.FullName));
}
@@ -345,7 +345,7 @@
public bool IsTablePerConcreteClass(System.Type type)
{
- return tablePerConcreteClassEntities.Contains(type);
+ return IsMappedFor(tablePerConcreteClassEntities, type);
}
public bool IsOneToOne(MemberInfo member)
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/UnionSubclassMappingStrategyTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/UnionSubclassMappingStrategyTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/UnionSubclassMappingStrategyTests.cs 2011-04-02 19:14:08 UTC (rev 5578)
@@ -0,0 +1,78 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.ExplicitlyDeclaredModelTests
+{
+ public class UnionSubclassMappingStrategyTests
+ {
+ private class MyClass
+ {
+
+ }
+ private class Inherited1 : MyClass
+ {
+
+ }
+ private class Inherited2 : Inherited1
+ {
+
+ }
+
+ [Test]
+ public void WhenRegisteredAsUnionSubclassThenIsRegistered()
+ {
+ var inspector = new ExplicitlyDeclaredModel();
+ inspector.AddAsRootEntity(typeof(MyClass));
+ inspector.AddAsTablePerConcreteClassEntity(typeof(Inherited1));
+
+ inspector.IsTablePerClass(typeof(Inherited1)).Should().Be.False();
+ inspector.IsTablePerClassHierarchy(typeof(Inherited1)).Should().Be.False();
+ inspector.IsTablePerClassHierarchyJoin(typeof(Inherited1)).Should().Be.False();
+ inspector.IsTablePerConcreteClass(typeof(Inherited1)).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenRegisteredAsDeepUnionSubclassThenIsRegistered()
+ {
+ var inspector = new ExplicitlyDeclaredModel();
+ inspector.AddAsRootEntity(typeof(MyClass));
+ inspector.AddAsTablePerConcreteClassEntity(typeof(Inherited2));
+
+ inspector.IsTablePerClass(typeof(Inherited2)).Should().Be.False();
+ inspector.IsTablePerClassHierarchy(typeof(Inherited2)).Should().Be.False();
+ inspector.IsTablePerClassHierarchyJoin(typeof(Inherited2)).Should().Be.False();
+ inspector.IsTablePerConcreteClass(typeof(Inherited2)).Should().Be.True();
+ }
+
+ [Test]
+ public void WhenRegisteredAsUnionSubclassThenCantRegisterAsSubclass()
+ {
+ var inspector = new ExplicitlyDeclaredModel();
+ inspector.AddAsRootEntity(typeof(MyClass));
+ inspector.AddAsTablePerConcreteClassEntity(typeof(Inherited1));
+
+ inspector.Executing(x => x.AddAsTablePerClassHierarchyEntity(typeof(Inherited1))).Throws<MappingException>();
+ }
+
+ [Test]
+ public void WhenRegisteredAsUnionSubclassThenCantRegisterAsSubclassJoin()
+ {
+ var inspector = new ExplicitlyDeclaredModel();
+ inspector.AddAsRootEntity(typeof(MyClass));
+ inspector.AddAsTablePerConcreteClassEntity(typeof(Inherited1));
+
+ inspector.Executing(x => x.AddAsTablePerClassHierarchyJoinEntity(typeof(Inherited1))).Throws<MappingException>();
+ }
+
+ [Test]
+ public void WhenRegisteredAsUnionSubclassThenCantRegisterAsJoinedSubclass()
+ {
+ var inspector = new ExplicitlyDeclaredModel();
+ inspector.AddAsRootEntity(typeof(MyClass));
+ inspector.AddAsTablePerConcreteClassEntity(typeof(Inherited1));
+
+ inspector.Executing(x => x.AddAsTablePerClassEntity(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 19:06:54 UTC (rev 5577)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-02 19:14:08 UTC (rev 5578)
@@ -512,6 +512,7 @@
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\RootClassMappingStrategyTests.cs" />
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassJoinMappingStrategyTests.cs" />
<Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassMappingStrategyTests.cs" />
+ <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\UnionSubclassMappingStrategyTests.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.
|