Skip to content

Commit c5583eb

Browse files
committed
Merge pull request #216 from chester89/testsFor113
Tests for #113
2 parents 1daf18a + d5d9f91 commit c5583eb

File tree

5 files changed

+137
-7
lines changed

5 files changed

+137
-7
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ build
2424

2525
*.swp
2626
TestResult.xml
27+
*.ncrunchsolution
28+
*.ncrunchproject
29+
packages/
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using FluentNHibernate.Automapping.TestFixtures.SuperTypes;
6+
using FluentNHibernate.Testing.Automapping;
7+
using NUnit.Framework;
8+
9+
namespace FluentNHibernate.Testing.AutoMapping
10+
{
11+
[TestFixture]
12+
public class InheritanceTests: BaseAutoMapFixture
13+
{
14+
[Test]
15+
public void AutoMapSimpleProperties()
16+
{
17+
Model<ThirdLevel>();
18+
19+
Test<ThirdLevel>(mapping =>
20+
{
21+
mapping.Element("//property[@name='Rate']/column").HasAttribute("name", "Rate");
22+
mapping.Element("//property[@name='SecondRate']/column").HasAttribute("name", "SecondRate");
23+
});
24+
}
25+
26+
[Test]
27+
public void AutoMapInheritedIdProperty()
28+
{
29+
Model<SecondLevel>();
30+
31+
Test<SecondLevel>(mapping => mapping.Element("//id").HasAttribute("name", "Id"));
32+
}
33+
34+
[Test]
35+
public void AutoMapManyToOne()
36+
{
37+
Model<FourthLevel>();
38+
39+
Test<FourthLevel>(mapping => mapping.Element("//many-to-one").HasAttribute("name", "One").
40+
Element("//many-to-one/column").HasAttribute("name", "One_id"));
41+
}
42+
43+
[Test]
44+
public void AutoMapManyToMany()
45+
{
46+
Model<FourthLevel>();
47+
48+
Test<FourthLevel>(mapping =>
49+
{
50+
mapping.Element("//many-to-many/column").HasAttribute("name", "ManyToMany_id");
51+
});
52+
}
53+
54+
[Test]
55+
public void AutoMapEnum()
56+
{
57+
Model<FourthLevel>(model => model.Override<FourthLevel>(map => map.Map(x => x.publisherType)));
58+
59+
Test<FourthLevel > (mapping => mapping.Element("//property[@name='publisherType']").Exists());
60+
}
61+
62+
[Test]
63+
public void AutoMapVersion()
64+
{
65+
Model<ThirdLevel>();
66+
67+
Test<ThirdLevel>(mapping =>
68+
{
69+
mapping.Element("//version").HasAttribute("name", "Version");
70+
mapping.Element("//version/column").HasAttribute("name", "Version");
71+
});
72+
}
73+
}
74+
}

src/FluentNHibernate.Testing/AutoMapping/TestFixtures.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,5 +470,60 @@ public class ExampleParentClass : SuperType
470470
public virtual IList<ExampleClass> Examples {get; set;}
471471
}
472472

473+
public abstract class Base1
474+
{
475+
public virtual int Id { get; protected set; }
476+
public abstract void Foo(int x);
477+
}
478+
479+
public class Derived1 : Base1
480+
{
481+
public virtual Decimal Rate { get; set; }
482+
public override void Foo(int x)
483+
{
484+
}
485+
486+
public string GetSomething()
487+
{
488+
return Environment.NewLine;
489+
}
490+
}
491+
492+
public class SecondLevel : Derived1
493+
{
494+
public virtual Double SecondRate { get; set; }
495+
}
496+
497+
public class ThirdLevel : SecondLevel
498+
{
499+
public virtual Boolean Flag { get; set; }
500+
public virtual TimeSpan Version { get; set; }
501+
}
502+
503+
public class FourthLevel: ThirdLevel
504+
{
505+
public PublisherType publisherType { get; set; }
506+
public ToOne One { get; set; }
507+
public IList<ManyToMany> Many { get; set; }
508+
}
509+
510+
public class ToOne
511+
{
512+
public virtual int Id { get; protected set; }
513+
public virtual string Name { get; set; }
514+
}
473515

516+
public class ManyToMany
517+
{
518+
public virtual int Id { get; protected set; }
519+
public virtual Decimal Value { get; set; }
520+
public IList<FourthLevel> Levels { get; set; }
521+
}
522+
523+
public enum PublisherType
524+
{
525+
Online,
526+
Offline,
527+
Mixed
528+
}
474529
}

src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@
101101
<Compile Include="AutoMapping\Apm\AlterationCollectionTests.cs" />
102102
<Compile Include="AutoMapping\Apm\AlterationTests.cs" />
103103
<Compile Include="AutoMapping\Apm\ConcreteBaseClassTests.cs" />
104-
<Compile Include="AutoMapping\Apm\Conventions\VersionConventionTests.cs" />
105-
<Compile Include="AutoMapping\DefaultAutoMappingConfigurationTests.cs" />
106-
<Compile Include="AutoMapping\Apm\IdentityTests.cs" />
104+
<Compile Include="AutoMapping\Apm\Conventions\VersionConventionTests.cs" />
105+
<Compile Include="AutoMapping\DefaultAutoMappingConfigurationTests.cs" />
106+
<Compile Include="AutoMapping\Apm\IdentityTests.cs" />
107+
<Compile Include="AutoMapping\InheritanceTests.cs" />
107108
<Compile Include="AutoMapping\Overrides\ReferenceComponentOverrides.cs" />
108109
<Compile Include="AutoMapping\Overrides\AutoMappingOverrideAlterationTests.cs" />
109110
<Compile Include="AutoMapping\Apm\CacheOverrideTests.cs" />

src/FluentNHibernate/Automapping/AutoPersistenceModel.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ private void AddMapping(Type type)
207207
{
208208
Type typeToMap = GetTypeToMap(type);
209209

210-
// Fixes https://github.com/jagregory/fluent-nhibernate/issues/113,
211-
// where 'type' would not be mapped if 'GetTypeToMap' returned the
212-
// base type
213210
if (typeToMap != type)
214211
{
215212
log.BeginAutomappingType(type);
@@ -264,7 +261,7 @@ private bool ShouldMap(Type type)
264261
return false; // skipped because we don't want to map components as entities
265262
}
266263
if (type == typeof(object))
267-
return false; // object!
264+
return false;
268265

269266
return true;
270267
}

0 commit comments

Comments
 (0)