Skip to content

Commit 017f5d2

Browse files
authored
Fix conventions not applying to members of <natural-id> (#608)
See #607 +semver:fix
1 parent 65b2909 commit 017f5d2

File tree

6 files changed

+453
-23
lines changed

6 files changed

+453
-23
lines changed

.editorconfig

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
root = true
12
; This file is for unifying the coding style for different editors and IDEs.
23
; More information at http://EditorConfig.org
34

4-
root = true
55

66
[*]
7-
end_of_line = CRLF
7+
end_of_line = crlf
88

99
[*.ps1]
1010
indent_style = space
@@ -17,12 +17,15 @@ insert_final_newline = true
1717

1818
csharp_style_namespace_declarations = file_scoped
1919

20-
dotnet_diagnostic.IDE0161.severity = warning
20+
dotnet_diagnostic.ide0161.severity = warning
21+
22+
# ReSharper properties
23+
resharper_default_private_modifier = implicit
2124

2225
[*.cake]
2326
indent_style = space
2427
indent_size = 4
2528

2629
[*.js]
2730
indent_style = tab
28-
indent_size = 2
31+
indent_size = 2
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
using System;
2+
using System.Linq;
3+
using FluentNHibernate.Automapping.TestFixtures;
4+
using FluentNHibernate.Conventions.Helpers.Builders;
5+
using FluentNHibernate.Conventions.Instances;
6+
using FluentNHibernate.Mapping;
7+
using FluentNHibernate.MappingModel;
8+
using NUnit.Framework;
9+
10+
namespace FluentNHibernate.Testing.ConventionsTests.ApplyingToModel;
11+
12+
[TestFixture]
13+
public class NaturalIdManyToOneConventionTests
14+
{
15+
private PersistenceModel model;
16+
17+
[SetUp]
18+
public void CreatePersistenceModel()
19+
{
20+
model = new PersistenceModel();
21+
}
22+
23+
[Test]
24+
public void ShouldSetAccessProperty()
25+
{
26+
Convention(x => x.Access.Property());
27+
28+
VerifyModel(x => x.Access.ShouldEqual("property"));
29+
}
30+
31+
[Test]
32+
public void ShouldSetCascadeProperty()
33+
{
34+
Convention(x => x.Cascade.None());
35+
36+
VerifyModel(x => x.Cascade.ShouldEqual("none"));
37+
}
38+
39+
[Test]
40+
public void ShouldSetClassProperty()
41+
{
42+
Convention(x => x.CustomClass(typeof(int)));
43+
44+
VerifyModel(x => x.Class.GetUnderlyingSystemType().ShouldEqual(typeof(int)));
45+
}
46+
47+
[Test]
48+
public void ShouldSetColumnProperty()
49+
{
50+
Convention(x => x.Column("xxx"));
51+
52+
VerifyModel(x => x.Columns.First().Name.ShouldEqual("xxx"));
53+
}
54+
55+
[Test]
56+
public void ShouldSetFetchProperty()
57+
{
58+
Convention(x => x.Fetch.Select());
59+
60+
VerifyModel(x => x.Fetch.ShouldEqual("select"));
61+
}
62+
63+
[Test]
64+
public void ShouldSetIndexProperty()
65+
{
66+
Convention(x => x.Index("value"));
67+
68+
VerifyModel(x => x.Columns.First().Index.ShouldEqual("value"));
69+
}
70+
71+
[Test]
72+
public void ShouldSetInsertProperty()
73+
{
74+
Convention(x => x.Insert());
75+
76+
VerifyModel(x => x.Insert.ShouldBeTrue());
77+
}
78+
79+
[Test]
80+
public void ShouldSetLazyProperty()
81+
{
82+
Convention(x => x.LazyLoad());
83+
84+
VerifyModel(x => x.Lazy.ShouldEqual(Laziness.Proxy.ToString()));
85+
}
86+
87+
[Test]
88+
public void ShouldSetNotFoundProperty()
89+
{
90+
Convention(x => x.NotFound.Ignore());
91+
92+
VerifyModel(x => x.NotFound.ShouldEqual("ignore"));
93+
}
94+
95+
[Test]
96+
public void ShouldSetNullableProperty()
97+
{
98+
Convention(x => x.Nullable());
99+
100+
VerifyModel(x => x.Columns.First().NotNull.ShouldBeFalse());
101+
}
102+
103+
[Test]
104+
public void ShouldSetPropertyRefProperty()
105+
{
106+
Convention(x => x.PropertyRef("xxx"));
107+
108+
VerifyModel(x => x.PropertyRef.ShouldEqual("xxx"));
109+
}
110+
111+
[Test]
112+
public void ShouldSetReadOnlyProperty()
113+
{
114+
Convention(x => x.ReadOnly());
115+
116+
VerifyModel(x =>
117+
{
118+
x.Insert.ShouldBeFalse();
119+
x.Update.ShouldBeFalse();
120+
});
121+
}
122+
123+
[Test]
124+
public void ShouldSetUniqueProperty()
125+
{
126+
Convention(x => x.Unique());
127+
128+
VerifyModel(x => x.Columns.First().Unique.ShouldBeTrue());
129+
}
130+
131+
[Test]
132+
public void ShouldSetUniqueKeyProperty()
133+
{
134+
Convention(x => x.UniqueKey("xxx"));
135+
136+
VerifyModel(x => x.Columns.First().UniqueKey.ShouldEqual("xxx"));
137+
}
138+
139+
[Test]
140+
public void ShouldSetUpdateProperty()
141+
{
142+
Convention(x => x.Update());
143+
144+
VerifyModel(x => x.Update.ShouldBeTrue());
145+
}
146+
147+
[Test]
148+
public void ShouldSetForeignKeyProperty()
149+
{
150+
Convention(x => x.ForeignKey("xxx"));
151+
152+
VerifyModel(x => x.ForeignKey.ShouldEqual("xxx"));
153+
}
154+
155+
[Test]
156+
public void ShouldSetFormulaProperty()
157+
{
158+
Convention(x => x.Formula("xxx"));
159+
160+
VerifyModel(x => x.Formula.ShouldEqual("xxx"));
161+
}
162+
163+
[Test]
164+
public void ShouldSetOptimisticLockProperty()
165+
{
166+
Convention(x => x.OptimisticLock());
167+
168+
VerifyModel(x => x.OptimisticLock.ShouldBeTrue());
169+
}
170+
171+
#region Helpers
172+
173+
private void Convention(Action<IManyToOneInstance> convention)
174+
{
175+
model.Conventions.Add(new ReferenceConventionBuilder().Always(convention));
176+
}
177+
178+
private void VerifyModel(Action<ManyToOneMapping> modelVerification)
179+
{
180+
var classMap = new ClassMap<ExampleClass>();
181+
classMap.Id(x => x.Id);
182+
var map = classMap.NaturalId().Reference(x => x.Parent);
183+
184+
model.Add(classMap);
185+
186+
var generatedModels = model.BuildMappings();
187+
var modelInstance = generatedModels
188+
.SelectMany(x => x.Classes)
189+
.First(x => x.Type == typeof(ExampleClass))
190+
.NaturalId.ManyToOnes.First();
191+
192+
modelVerification(modelInstance);
193+
}
194+
195+
#endregion
196+
}

0 commit comments

Comments
 (0)