Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conventions not applying to members of <natural-id> #608

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
root = true
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://EditorConfig.org

root = true

[*]
end_of_line = CRLF
end_of_line = crlf

[*.ps1]
indent_style = space
Expand All @@ -17,12 +17,15 @@ insert_final_newline = true

csharp_style_namespace_declarations = file_scoped

dotnet_diagnostic.IDE0161.severity = warning
dotnet_diagnostic.ide0161.severity = warning

# ReSharper properties
resharper_default_private_modifier = implicit

[*.cake]
indent_style = space
indent_size = 4

[*.js]
indent_style = tab
indent_size = 2
indent_size = 2
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
}
Loading