-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix conventions not applying to members of <natural-id> (#608)
See #607 +semver:fix
- Loading branch information
Showing
6 changed files
with
453 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
...tNHibernate.Testing/ConventionsTests/ApplyingToModel/NaturalIdManyToOneConventionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
using System; | ||
using System.Linq; | ||
using FluentNHibernate.Automapping.TestFixtures; | ||
using FluentNHibernate.Conventions.Helpers.Builders; | ||
using FluentNHibernate.Conventions.Instances; | ||
using FluentNHibernate.Mapping; | ||
using FluentNHibernate.MappingModel; | ||
using NUnit.Framework; | ||
|
||
namespace FluentNHibernate.Testing.ConventionsTests.ApplyingToModel; | ||
|
||
[TestFixture] | ||
public class NaturalIdManyToOneConventionTests | ||
{ | ||
private PersistenceModel model; | ||
|
||
[SetUp] | ||
public void CreatePersistenceModel() | ||
{ | ||
model = new PersistenceModel(); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetAccessProperty() | ||
{ | ||
Convention(x => x.Access.Property()); | ||
|
||
VerifyModel(x => x.Access.ShouldEqual("property")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetCascadeProperty() | ||
{ | ||
Convention(x => x.Cascade.None()); | ||
|
||
VerifyModel(x => x.Cascade.ShouldEqual("none")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetClassProperty() | ||
{ | ||
Convention(x => x.CustomClass(typeof(int))); | ||
|
||
VerifyModel(x => x.Class.GetUnderlyingSystemType().ShouldEqual(typeof(int))); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetColumnProperty() | ||
{ | ||
Convention(x => x.Column("xxx")); | ||
|
||
VerifyModel(x => x.Columns.First().Name.ShouldEqual("xxx")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetFetchProperty() | ||
{ | ||
Convention(x => x.Fetch.Select()); | ||
|
||
VerifyModel(x => x.Fetch.ShouldEqual("select")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetIndexProperty() | ||
{ | ||
Convention(x => x.Index("value")); | ||
|
||
VerifyModel(x => x.Columns.First().Index.ShouldEqual("value")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetInsertProperty() | ||
{ | ||
Convention(x => x.Insert()); | ||
|
||
VerifyModel(x => x.Insert.ShouldBeTrue()); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetLazyProperty() | ||
{ | ||
Convention(x => x.LazyLoad()); | ||
|
||
VerifyModel(x => x.Lazy.ShouldEqual(Laziness.Proxy.ToString())); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetNotFoundProperty() | ||
{ | ||
Convention(x => x.NotFound.Ignore()); | ||
|
||
VerifyModel(x => x.NotFound.ShouldEqual("ignore")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetNullableProperty() | ||
{ | ||
Convention(x => x.Nullable()); | ||
|
||
VerifyModel(x => x.Columns.First().NotNull.ShouldBeFalse()); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetPropertyRefProperty() | ||
{ | ||
Convention(x => x.PropertyRef("xxx")); | ||
|
||
VerifyModel(x => x.PropertyRef.ShouldEqual("xxx")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetReadOnlyProperty() | ||
{ | ||
Convention(x => x.ReadOnly()); | ||
|
||
VerifyModel(x => | ||
{ | ||
x.Insert.ShouldBeFalse(); | ||
x.Update.ShouldBeFalse(); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetUniqueProperty() | ||
{ | ||
Convention(x => x.Unique()); | ||
|
||
VerifyModel(x => x.Columns.First().Unique.ShouldBeTrue()); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetUniqueKeyProperty() | ||
{ | ||
Convention(x => x.UniqueKey("xxx")); | ||
|
||
VerifyModel(x => x.Columns.First().UniqueKey.ShouldEqual("xxx")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetUpdateProperty() | ||
{ | ||
Convention(x => x.Update()); | ||
|
||
VerifyModel(x => x.Update.ShouldBeTrue()); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetForeignKeyProperty() | ||
{ | ||
Convention(x => x.ForeignKey("xxx")); | ||
|
||
VerifyModel(x => x.ForeignKey.ShouldEqual("xxx")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetFormulaProperty() | ||
{ | ||
Convention(x => x.Formula("xxx")); | ||
|
||
VerifyModel(x => x.Formula.ShouldEqual("xxx")); | ||
} | ||
|
||
[Test] | ||
public void ShouldSetOptimisticLockProperty() | ||
{ | ||
Convention(x => x.OptimisticLock()); | ||
|
||
VerifyModel(x => x.OptimisticLock.ShouldBeTrue()); | ||
} | ||
|
||
#region Helpers | ||
|
||
private void Convention(Action<IManyToOneInstance> convention) | ||
{ | ||
model.Conventions.Add(new ReferenceConventionBuilder().Always(convention)); | ||
} | ||
|
||
private void VerifyModel(Action<ManyToOneMapping> modelVerification) | ||
{ | ||
var classMap = new ClassMap<ExampleClass>(); | ||
classMap.Id(x => x.Id); | ||
var map = classMap.NaturalId().Reference(x => x.Parent); | ||
|
||
model.Add(classMap); | ||
|
||
var generatedModels = model.BuildMappings(); | ||
var modelInstance = generatedModels | ||
.SelectMany(x => x.Classes) | ||
.First(x => x.Type == typeof(ExampleClass)) | ||
.NaturalId.ManyToOnes.First(); | ||
|
||
modelVerification(modelInstance); | ||
} | ||
|
||
#endregion | ||
} |
Oops, something went wrong.