Skip to content

Commit 1e82f30

Browse files
committed
added unit-tests for edge-case of compiler-generated class being mapped
1 parent 8b3d62b commit 1e82f30

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using FluentNHibernate.Automapping;
6+
using NUnit.Framework;
7+
8+
namespace FluentNHibernate.Testing.Automapping
9+
{
10+
[TestFixture]
11+
public class DefaultAutoMappingConfigurationTests
12+
{
13+
IAutomappingConfiguration configuration;
14+
15+
[TestFixtureSetUp]
16+
public void FixtureSetUp()
17+
{
18+
configuration = new DefaultAutomappingConfiguration();
19+
}
20+
21+
[Test]
22+
public void ShouldNotMapCompilerGeneratedClasses()
23+
{
24+
var anonymous = new { id = 5, title = "Whatever happening"};
25+
configuration.ShouldMap(anonymous.GetType()).ShouldBeFalse();
26+
}
27+
}
28+
}

src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
<PlatformTarget>x86</PlatformTarget>
5555
<ErrorReport>prompt</ErrorReport>
5656
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
57-
<DocumentationFile>bin\Release\FluentNHibernate.Testing.xml</DocumentationFile>
57+
<DocumentationFile>
58+
</DocumentationFile>
5859
</PropertyGroup>
5960
<ItemGroup>
6061
<Reference Include="Iesi.Collections, Version=1.0.0.3, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
@@ -101,6 +102,7 @@
101102
<Compile Include="AutoMapping\Apm\AlterationTests.cs" />
102103
<Compile Include="AutoMapping\Apm\ConcreteBaseClassTests.cs" />
103104
<Compile Include="AutoMapping\Apm\Conventions\VersionConventionTests.cs" />
105+
<Compile Include="AutoMapping\DefaultAutoMappingConfigurationTests.cs" />
104106
<Compile Include="AutoMapping\Overrides\ReferenceComponentOverrides.cs" />
105107
<Compile Include="AutoMapping\Overrides\AutoMappingOverrideAlterationTests.cs" />
106108
<Compile Include="AutoMapping\Apm\CacheOverrideTests.cs" />

src/FluentNHibernate/Automapping/DefaultAutomappingConfiguration.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Runtime.CompilerServices;
34
using FluentNHibernate.Automapping.Alterations;
45
using FluentNHibernate.Automapping.Steps;
56
using FluentNHibernate.Conventions;
@@ -20,8 +21,8 @@ public virtual bool ShouldMap(Type type)
2021
return !type.ClosesInterface(typeof(IAutoMappingOverride<>)) &&
2122
!type.HasInterface(typeof(IMappingProvider)) &&
2223
!type.IsNestedPrivate &&
23-
!type.IsDefined(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false)
24-
type.IsClass;
24+
!type.IsDefined(typeof(CompilerGeneratedAttribute), false)
25+
&& type.IsClass;
2526
}
2627

2728
public virtual bool IsId(Member member)

0 commit comments

Comments
 (0)