Skip to content

NH-3527 - UnionSubclassMapper should mark an abstract type as abstract in the generated HbmMapping #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using NHibernate.Cfg.MappingSchema;
using NHibernate.Mapping.ByCode.Impl;
using NUnit.Framework;

namespace NHibernate.Test.MappingByCode.MappersTests.UnionSubclassMapperTests
{
[TestFixture]
public class AbstractAttributeTests
{
private abstract class EntityBase
{
}

private abstract class Item : EntityBase
{
}

private class InventoryItem : Item
{
}

[Test]
public void CanSetAbstractAttributeOnAbstractClass()
{
var mapping = new HbmMapping();
var mapper = new UnionSubclassMapper(typeof(Item), mapping);

Assert.That(mapping.UnionSubclasses[0].abstractSpecified, Is.True);
Assert.That(mapping.UnionSubclasses[0].@abstract, Is.True);
}

[Test]
public void CanSetAbstractAttributeOnConcreteClass()
{
var mapping = new HbmMapping();
var mapper = new UnionSubclassMapper(typeof(InventoryItem), mapping);

Assert.That(mapping.UnionSubclasses[0].abstractSpecified, Is.False);
Assert.That(mapping.UnionSubclasses[0].@abstract, Is.False);
}
}
}
1 change: 1 addition & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@
<Compile Include="MappingByCode\MappersTests\SubclassMapperTests\SetPersisterTests.cs" />
<Compile Include="MappingByCode\MappersTests\SubclassMapperTests\TablesSincronizationTests.cs" />
<Compile Include="MappingByCode\MappersTests\SubclassMapperWithJoinPropertiesTest.cs" />
<Compile Include="MappingByCode\MappersTests\UnionSubclassMapperTests\AbstractAttributeTests.cs" />
<Compile Include="MappingByCode\MappersTests\UnionSubclassMapperTests\SetPersisterTests.cs" />
<Compile Include="MappingByCode\MappersTests\UnionSubclassMapperTests\TablesSincronizationTests.cs" />
<Compile Include="MappingByCode\MixAutomapping\ArrayCollectionTests.cs" />
Expand Down
7 changes: 6 additions & 1 deletion src/NHibernate/Mapping/ByCode/Impl/UnionSubclassMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public UnionSubclassMapper(System.Type subClass, HbmMapping mapDoc)
var toAdd = new[] {classMapping};
classMapping.name = subClass.GetShortClassName(mapDoc);
classMapping.extends = subClass.BaseType.GetShortClassName(mapDoc);
if (subClass.IsAbstract)
{
classMapping.@abstract = true;
classMapping.abstractSpecified = true;
}
mapDoc.Items = mapDoc.Items == null ? toAdd : mapDoc.Items.Concat(toAdd).ToArray();
}

Expand Down Expand Up @@ -170,7 +175,7 @@ public void Extends(System.Type baseType)
if (!Container.GetBaseTypes().Contains(baseType))
{
throw new ArgumentOutOfRangeException("baseType",
string.Format("{0} is a valid super-class of {1}", baseType, Container));
string.Format("{0} is a valid super-class of {1}", baseType, Container));
}
classMapping.extends = baseType.GetShortClassName(MapDoc);
}
Expand Down