From: <fab...@us...> - 2011-04-02 19:38:50
|
Revision: 5579 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5579&view=rev Author: fabiomaulo Date: 2011-04-02 19:38:43 +0000 (Sat, 02 Apr 2011) Log Message: ----------- components 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/ComponentMappingRegistrationTests.cs Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 19:14:08 UTC (rev 5578) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ExplicitlyDeclaredModel.cs 2011-04-02 19:38:43 UTC (rev 5579) @@ -138,16 +138,29 @@ public void AddAsRootEntity(System.Type type) { + if (IsComponent(type)) + { + throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + } rootEntities.Add(type); } public void AddAsComponent(System.Type type) { + var rootEntity = GetRootEntityOrNull(type); + if (rootEntity != null) + { + throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + } components.Add(type); } public void AddAsTablePerClassEntity(System.Type type) { + if (IsComponent(type)) + { + throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + } var rootEntity = GetRootEntityOrNull(type); if(rootEntity != null) { @@ -165,6 +178,10 @@ public void AddAsTablePerClassHierarchyEntity(System.Type type) { + if (IsComponent(type)) + { + throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + } var rootEntity = GetRootEntityOrNull(type); if (rootEntity != null) { @@ -182,6 +199,10 @@ public void AddAsTablePerClassHierarchyJoinEntity(System.Type type) { + if (IsComponent(type)) + { + throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + } var rootEntity = GetRootEntityOrNull(type); if (rootEntity != null) { @@ -200,6 +221,10 @@ public void AddAsTablePerConcreteClassEntity(System.Type type) { + if (IsComponent(type)) + { + throw new MappingException(string.Format("Abiguous mapping of {0}. It was registered as entity and as component", type.FullName)); + } var rootEntity = GetRootEntityOrNull(type); if (rootEntity != null) { Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/ComponentMappingRegistrationTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/ComponentMappingRegistrationTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/ComponentMappingRegistrationTests.cs 2011-04-02 19:38:43 UTC (rev 5579) @@ -0,0 +1,77 @@ +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.MappingByCode.ExplicitlyDeclaredModelTests +{ + public class ComponentMappingRegistrationTests + { + private class MyComponent + { + + } + + [Test] + public void WhenRegisteredAsComponentThenIsRegistered() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsComponent(typeof(MyComponent)); + + inspector.IsComponent(typeof(MyComponent)).Should().Be.True(); + } + + [Test] + public void WhenRegisteredAsEntityThenCantRegisterAsComponent() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsRootEntity(typeof(MyComponent)); + + inspector.Executing(x => x.AddAsComponent(typeof(MyComponent))).Throws<MappingException>(); + } + + [Test] + public void WhenRegisteredAsComponetThenCantRegisterAsRootEntity() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsComponent(typeof(MyComponent)); + + inspector.Executing(x => x.AddAsRootEntity(typeof(MyComponent))).Throws<MappingException>(); + } + + [Test] + public void WhenRegisteredAsComponetThenCantRegisterAsJoinedSubclass() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsComponent(typeof(MyComponent)); + + inspector.Executing(x => x.AddAsTablePerClassEntity(typeof(MyComponent))).Throws<MappingException>(); + } + + [Test] + public void WhenRegisteredAsComponetThenCantRegisterAsSubclass() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsComponent(typeof(MyComponent)); + + inspector.Executing(x => x.AddAsTablePerClassHierarchyEntity(typeof(MyComponent))).Throws<MappingException>(); + } + + [Test] + public void WhenRegisteredAsComponetThenCantRegisterAsSubclassJoin() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsComponent(typeof(MyComponent)); + + inspector.Executing(x => x.AddAsTablePerClassHierarchyJoinEntity(typeof(MyComponent))).Throws<MappingException>(); + } + + [Test] + public void WhenRegisteredAsComponetThenCantRegisterAsUnionSubclass() + { + var inspector = new ExplicitlyDeclaredModel(); + inspector.AddAsComponent(typeof(MyComponent)); + + inspector.Executing(x => x.AddAsTablePerConcreteClassEntity(typeof(MyComponent))).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:14:08 UTC (rev 5578) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-02 19:38:43 UTC (rev 5579) @@ -508,6 +508,7 @@ <Compile Include="Logging\LoggerProviderTest.cs" /> <Compile Include="MappingByCode\BasicMappingOfSimpleClass.cs" /> <Compile Include="MappingByCode\ColumnsNamingConvetions.cs" /> + <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\ComponentMappingRegistrationTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\JoinedSubclassMappingStrategyTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\RootClassMappingStrategyTests.cs" /> <Compile Include="MappingByCode\ExplicitlyDeclaredModelTests\SubclassJoinMappingStrategyTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |