|
From: <fab...@us...> - 2011-04-12 12:19:40
|
Revision: 5675
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5675&view=rev
Author: fabiomaulo
Date: 2011-04-12 12:19:33 +0000 (Tue, 12 Apr 2011)
Log Message:
-----------
SimpleModelInspector with default pattern to discover RootEntities entities
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/RootEntityTests.cs
Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-12 11:08:59 UTC (rev 5674)
+++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/SimpleModelInspector.cs 2011-04-12 12:19:33 UTC (rev 5675)
@@ -44,6 +44,7 @@
public SimpleModelInspector()
{
isEntity = (t, declared) => declared || MatchEntity(t);
+ isRootEntity = (t, declared) => declared || MatchRootEntity(t);
isTablePerClass = (t, declared) => declared || MatchTablePerClass(t);
isPersistentId = (m, declared) => declared || MatchPoIdPattern(m);
isComponent = (t, declared) => declared || MatchComponentPattern(t);
@@ -56,6 +57,11 @@
isOneToMany = (m, declared) => declared || MatchOneToMany(m);
}
+ private bool MatchRootEntity(System.Type type)
+ {
+ return type.IsClass && typeof(object).Equals(type.BaseType);
+ }
+
private bool MatchTablePerClass(System.Type type)
{
return !declaredModel.IsTablePerClassHierarchy(type) && !declaredModel.IsTablePerConcreteClass(type);
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/RootEntityTests.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/RootEntityTests.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/MixAutomapping/RootEntityTests.cs 2011-04-12 12:19:33 UTC (rev 5675)
@@ -0,0 +1,45 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.MixAutomapping
+{
+ public class RootEntityTests
+ {
+ private class Person
+ {
+ public int Id { get; set; }
+ }
+
+ private class BaseEntity
+ {
+ public int Id { get; set; }
+ }
+
+ private class Product: BaseEntity
+ {
+ }
+
+ [Test]
+ public void ByDefaultInheritedFromObject()
+ {
+ var autoinspector = new SimpleModelInspector();
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsRootEntity(typeof(Person)).Should().Be.True();
+ inspector.IsRootEntity(typeof(Product)).Should().Be.False();
+ }
+
+ [Test]
+ public void WhenCustomizedThenUseCustomizedPredicate()
+ {
+ var autoinspector = new SimpleModelInspector();
+ autoinspector.IsRootEntity((t, declared) => typeof(BaseEntity).Equals(t.BaseType));
+
+ var inspector = (IModelInspector)autoinspector;
+
+ inspector.IsRootEntity(typeof(Person)).Should().Be.False();
+ inspector.IsRootEntity(typeof(Product)).Should().Be.True();
+ }
+ }
+}
\ 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-12 11:08:59 UTC (rev 5674)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-12 12:19:33 UTC (rev 5675)
@@ -552,6 +552,7 @@
<Compile Include="MappingByCode\MixAutomapping\OneToManyTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PoidTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\PropertiesExclusionTests.cs" />
+ <Compile Include="MappingByCode\MixAutomapping\RootEntityTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\SetCollectionTests.cs" />
<Compile Include="MappingByCode\ModelExplicitDeclarationsHolderMergeTest.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Address.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|