Skip to content

Commit

Permalink
Modified the IdentityStep class to specify the access method of an Id…
Browse files Browse the repository at this point in the history
…Mapping as a default only, so that a convention can override the value.
  • Loading branch information
paulbatum committed Jun 5, 2010
1 parent f3a8467 commit 8294f2a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.MappingModel.Identity;
using NUnit.Framework;
using FluentNHibernate.Automapping.Steps;
using FluentNHibernate.Automapping;
using FluentNHibernate.MappingModel.ClassBased;
using FluentNHibernate.Utils.Reflection;

namespace FluentNHibernate.Testing.AutoMapping.Steps
{
[TestFixture]
public class IdentityStepTests
{
[Test]
public void IdentityStepShouldProvideAnAccessValueThatIsADefaultOnly()
{
IdentityStep step = new IdentityStep(new DefaultAutomappingConfiguration());

var classMapping = new ClassMapping() {Type = typeof(ClassWithIdFieldAndGetter)};
step.Map(classMapping, ReflectionHelper.GetMember<ClassWithIdFieldAndGetter>(x => x.Id));

var idMapping = (IdMapping) classMapping.Id;
idMapping.HasValue("Access").ShouldBeTrue();
idMapping.IsSpecified(x => x.Access).ShouldBeFalse();
}

private class ClassWithIdFieldAndGetter
{
#pragma warning disable 649
int _id;
#pragma warning restore 649
public int Id { get { return _id; } }
}
}
}
Expand Up @@ -450,6 +450,7 @@
<Compile Include="AutoMapping\Apm\AutoPersistenceModelTests.Inheritance.cs" />
<Compile Include="AutoMapping\Apm\AutoPersistenceModelTests.Overrides.cs" />
<Compile Include="AutoMapping\Steps\HasManyToManyStepTests.cs" />
<Compile Include="AutoMapping\Steps\IdentityStepTests.cs" />
<Compile Include="AutoMapping\Steps\ReferenceStepTests.cs" />
<Compile Include="AutoMapping\Steps\HasManyStepTests.cs" />
<Compile Include="AutoMapping\Steps\VersionStepTests.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Automapping/Steps/IdentityStep.cs
Expand Up @@ -32,7 +32,7 @@ public void Map(ClassMappingBase classMap, Member member)
idMapping.SetDefaultValue("Generator", GetDefaultGenerator(member));

if (member.IsProperty && !member.CanWrite)
idMapping.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString();
idMapping.SetDefaultValue("Access", cfg.GetAccessStrategyForReadOnlyProperty(member).ToString());

((ClassMapping)classMap).Id = idMapping;
}
Expand Down

0 comments on commit 8294f2a

Please sign in to comment.