Skip to content
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

EnsureMappingsBuild is called in PersistenceModel.ImportProviders to pre... #258

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
80 changes: 80 additions & 0 deletions src/FluentNHibernate.Testing/Cfg/DuplicateMappingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using FluentNHibernate.Automapping;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Mapping;
using NHibernate.Cfg;
using NHibernate.Mapping;
using NUnit.Framework;

namespace FluentNHibernate.Testing.Cfg
{
[TestFixture]
public class DuplicateMappingTests
{
private Configuration cfg;
private MappingConfiguration mapping;

[SetUp]
public void CreateMappingConfiguration()
{
cfg = new Configuration();

SQLiteConfiguration.Standard
.InMemory()
.ConfigureProperties(cfg);

mapping = new MappingConfiguration();
}

[Test]
public void FluentMappingOfInheritedAutomappedTypeShouldBeIgnoredForSubclasses()
{
mapping.FluentMappings.Add(typeof(TypeInfoMap));
mapping.FluentMappings.Add(typeof(MessageTypeMap));
mapping.AutoMappings.Add(AutoMap.Source(new StubTypeSource(typeof(ActiveRecord))));
mapping.Apply(cfg);

var arMapping = cfg.GetClassMapping(typeof(ActiveRecord));
arMapping.SubclassIterator.GetEnumerator().MoveNext().ShouldBeFalse();
var messageTypeMapping = cfg.GetClassMapping(typeof(MessageType)) as SingleTableSubclass;
messageTypeMapping.IsJoinedSubclass.ShouldBeFalse();
}

#region TestModel

public class ActiveRecord
{
public virtual int Id { get; set; }
}

public class TypeInfo : ActiveRecord
{
public virtual int ClassId { get; set; }
}

public class MessageType : TypeInfo
{
}

public class TypeInfoMap : ClassMap<TypeInfo>
{
public TypeInfoMap()
{
Table("TypeInfoNH");
Id(t => t.Id).GeneratedBy.HiLo("10");
Map(t => t.ClassId).ReadOnly();
DiscriminateSubClassesOnColumn("ClassId", 102);
}
}

public class MessageTypeMap : SubclassMap<MessageType>
{
public MessageTypeMap()
{
DiscriminatorValue(305);
}
}

#endregion
}
}
3 changes: 1 addition & 2 deletions src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<Compile Include="AutoMapping\Overrides\CompositeIdOverrides.cs" />
<Compile Include="AutoMapping\Overrides\HibernateMappingOverrides.cs" />
<Compile Include="Cfg\Db\SqlAnywhereConfigurationTester.cs" />
<Compile Include="Cfg\DuplicateMappingTests.cs" />
<Compile Include="DomainModel\Mapping\ManyToManySelfReferencedInverseIntegrationTester.cs" />
<Compile Include="DomainModel\Mapping\MultipleKeyColumnsTester.cs" />
<Compile Include="DomainModel\MemberAccessResolverTests.cs" />
Expand Down Expand Up @@ -416,10 +417,8 @@
<Compile Include="Testing\Values\ReferencePropertySpecs.cs" />
<Compile Include="Testing\Values\PropertySpecs.cs" />
<Compile Include="Testing\Values\Entities.cs" />

<Compile Include="Utils\ReflectionHelperTests.cs" />
<Compile Include="Testing\XmlWriterTestHelper.cs" />

<Compile Include="Utils\TypeReferenceEqualityTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Visitors\ComponentColumnPrefixVisitorSpecs.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/FluentNHibernate/PersistenceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ public bool ValidationEnabled

internal void ImportProviders(PersistenceModel model)
{
EnsureMappingsBuilt();

model.classProviders.Each(x =>
{
if (!classProviders.Contains(x))
Expand Down