Skip to content

Commit 8294f2a

Browse files
committed
Modified the IdentityStep class to specify the access method of an IdMapping as a default only, so that a convention can override the value.
1 parent f3a8467 commit 8294f2a

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using FluentNHibernate.MappingModel.Identity;
6+
using NUnit.Framework;
7+
using FluentNHibernate.Automapping.Steps;
8+
using FluentNHibernate.Automapping;
9+
using FluentNHibernate.MappingModel.ClassBased;
10+
using FluentNHibernate.Utils.Reflection;
11+
12+
namespace FluentNHibernate.Testing.AutoMapping.Steps
13+
{
14+
[TestFixture]
15+
public class IdentityStepTests
16+
{
17+
[Test]
18+
public void IdentityStepShouldProvideAnAccessValueThatIsADefaultOnly()
19+
{
20+
IdentityStep step = new IdentityStep(new DefaultAutomappingConfiguration());
21+
22+
var classMapping = new ClassMapping() {Type = typeof(ClassWithIdFieldAndGetter)};
23+
step.Map(classMapping, ReflectionHelper.GetMember<ClassWithIdFieldAndGetter>(x => x.Id));
24+
25+
var idMapping = (IdMapping) classMapping.Id;
26+
idMapping.HasValue("Access").ShouldBeTrue();
27+
idMapping.IsSpecified(x => x.Access).ShouldBeFalse();
28+
}
29+
30+
private class ClassWithIdFieldAndGetter
31+
{
32+
#pragma warning disable 649
33+
int _id;
34+
#pragma warning restore 649
35+
public int Id { get { return _id; } }
36+
}
37+
}
38+
}

src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@
450450
<Compile Include="AutoMapping\Apm\AutoPersistenceModelTests.Inheritance.cs" />
451451
<Compile Include="AutoMapping\Apm\AutoPersistenceModelTests.Overrides.cs" />
452452
<Compile Include="AutoMapping\Steps\HasManyToManyStepTests.cs" />
453+
<Compile Include="AutoMapping\Steps\IdentityStepTests.cs" />
453454
<Compile Include="AutoMapping\Steps\ReferenceStepTests.cs" />
454455
<Compile Include="AutoMapping\Steps\HasManyStepTests.cs" />
455456
<Compile Include="AutoMapping\Steps\VersionStepTests.cs" />

src/FluentNHibernate/Automapping/Steps/IdentityStep.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void Map(ClassMappingBase classMap, Member member)
3232
idMapping.SetDefaultValue("Generator", GetDefaultGenerator(member));
3333

3434
if (member.IsProperty && !member.CanWrite)
35-
idMapping.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString();
35+
idMapping.SetDefaultValue("Access", cfg.GetAccessStrategyForReadOnlyProperty(member).ToString());
3636

3737
((ClassMapping)classMap).Id = idMapping;
3838
}

0 commit comments

Comments
 (0)