forked from nhibernate/fluent-nhibernate
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for non-layer supertype abstract classes to the automap…
…per. You can either explicitly force an abstract type to be used with IncludeBase<T> or you can configure it in the setup with AbstractClassIsLayerSupertype.
- Loading branch information
Showing
4 changed files
with
129 additions
and
9 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/FluentNHibernate.Testing/AutoMapping/Apm/AbstractBaseClassTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Linq; | ||
using FluentNHibernate.Automapping; | ||
using FluentNHibernate.MappingModel.Identity; | ||
using NUnit.Framework; | ||
|
||
namespace FluentNHibernate.Testing.Automapping.Apm | ||
{ | ||
[TestFixture] | ||
public class AbstractBaseClassTests | ||
{ | ||
[Test] | ||
public void ShouldBeConsideredLayerSuperTypesByDefault() | ||
{ | ||
var automapper = | ||
AutoMap.Source(new StubTypeSource(new[] { typeof(AbstractBase), typeof(Child) })); | ||
|
||
automapper.CompileMappings(); | ||
var mappings = automapper.BuildMappings(); | ||
|
||
mappings | ||
.SelectMany(x => x.Classes) | ||
.ShouldNotContain(x => x.Type == typeof(AbstractBase)); | ||
} | ||
|
||
[Test] | ||
public void ShouldAllowSpecifyingToNotTreatAbstractsAsLayerSuperTypes() | ||
{ | ||
var automapper = | ||
AutoMap.Source(new StubTypeSource(new[] { typeof(AbstractBase), typeof(Child) })) | ||
.Setup(x => x.AbstractClassIsLayerSupertype = t => false); | ||
|
||
automapper.CompileMappings(); | ||
var mappings = automapper.BuildMappings(); | ||
|
||
mappings | ||
.SelectMany(x => x.Classes) | ||
.ShouldContain(x => x.Type == typeof(AbstractBase)); | ||
} | ||
|
||
[Test] | ||
public void ShouldAllowExplicitInclusionOfAnAbstractClass() | ||
{ | ||
var automapper = | ||
AutoMap.Source(new StubTypeSource(new[] { typeof(AbstractBase), typeof(Child) })) | ||
.IncludeBase<AbstractBase>(); | ||
|
||
automapper.CompileMappings(); | ||
var mappings = automapper.BuildMappings(); | ||
|
||
mappings | ||
.SelectMany(x => x.Classes) | ||
.ShouldContain(x => x.Type == typeof(AbstractBase)); | ||
} | ||
} | ||
|
||
public abstract class AbstractBase | ||
{ | ||
|
||
} | ||
|
||
public class Child : AbstractBase | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters