Skip to content

Commit 5f554fe

Browse files
committed
Merge remote branch 'ashmind/collection-element-conventions' into v1.x
2 parents 6d97fa9 + 6d702bb commit 5f554fe

14 files changed

+374
-2
lines changed

src/FluentNHibernate.Testing/ConventionsTests/ApplyingToModel/HasManyCollectionConventionTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,37 @@ public void ShouldSetKeyColumnNameProperty()
105105
VerifyModel(x => x.Key.Columns.First().Name.ShouldEqual("xxx"));
106106
}
107107

108+
[Test]
109+
public void ShouldSetElementColumnNameProperty()
110+
{
111+
Convention(x => x.Element.Column("xxx"));
112+
113+
VerifyModel(x => x.Element.Columns.First().Name.ShouldEqual("xxx"));
114+
}
115+
116+
[Test]
117+
public void ShouldSetElementTypePropertyUsingGeneric()
118+
{
119+
Convention(x => x.Element.Type<string>());
120+
121+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
122+
}
123+
124+
[Test]
125+
public void ShouldSetElementTypePropertyUsingTypeOf()
126+
{
127+
Convention(x => x.Element.Type(typeof(string)));
128+
129+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
130+
}
131+
132+
[Test]
133+
public void ShouldSetElementTypePropertyUsingString() {
134+
Convention(x => x.Element.Type(typeof(string).AssemblyQualifiedName));
135+
136+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
137+
}
138+
108139
[Test]
109140
public void ShouldSetLazyProperty()
110141
{

src/FluentNHibernate.Testing/ConventionsTests/ApplyingToModel/HasManyConventionTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,38 @@ public void ShouldSetKeyColumnNameProperty()
112112
VerifyModel(x => x.Key.Columns.First().Name.ShouldEqual("xxx"));
113113
}
114114

115+
[Test]
116+
public void ShouldSetElementColumnNameProperty()
117+
{
118+
Convention(x => x.Element.Column("xxx"));
119+
120+
VerifyModel(x => x.Element.Columns.First().Name.ShouldEqual("xxx"));
121+
}
122+
123+
[Test]
124+
public void ShouldSetElementTypePropertyUsingGeneric()
125+
{
126+
Convention(x => x.Element.Type<string>());
127+
128+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
129+
}
130+
131+
[Test]
132+
public void ShouldSetElementTypePropertyUsingTypeOf()
133+
{
134+
Convention(x => x.Element.Type(typeof(string)));
135+
136+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
137+
}
138+
139+
[Test]
140+
public void ShouldSetElementTypePropertyUsingString()
141+
{
142+
Convention(x => x.Element.Type(typeof(string).AssemblyQualifiedName));
143+
144+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
145+
}
146+
115147
[Test]
116148
public void ShouldSetLazyProperty()
117149
{

src/FluentNHibernate.Testing/ConventionsTests/ApplyingToModel/HasManyToManyCollectionConventionTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,38 @@ public void ShouldSetParentKeyColumnNameProperty()
105105
VerifyModel(x => x.Key.Columns.First().Name.ShouldEqual("xxx"));
106106
}
107107

108+
[Test]
109+
public void ShouldSetElementColumnNameProperty()
110+
{
111+
Convention(x => x.Element.Column("xxx"));
112+
113+
VerifyModel(x => x.Element.Columns.First().Name.ShouldEqual("xxx"));
114+
}
115+
116+
[Test]
117+
public void ShouldSetElementTypePropertyUsingGeneric()
118+
{
119+
Convention(x => x.Element.Type<string>());
120+
121+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
122+
}
123+
124+
[Test]
125+
public void ShouldSetElementTypePropertyUsingTypeOf()
126+
{
127+
Convention(x => x.Element.Type(typeof(string)));
128+
129+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
130+
}
131+
132+
[Test]
133+
public void ShouldSetElementTypePropertyUsingString()
134+
{
135+
Convention(x => x.Element.Type(typeof(string).AssemblyQualifiedName));
136+
137+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
138+
}
139+
108140
[Test]
109141
public void ShouldSetLazyProperty()
110142
{

src/FluentNHibernate.Testing/ConventionsTests/ApplyingToModel/HasManyToManyConventionTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,37 @@ public void ShouldSetParentKeyColumnNameProperty()
104104
VerifyModel(x => x.Key.Columns.First().Name.ShouldEqual("xxx"));
105105
}
106106

107+
[Test]
108+
public void ShouldSetElementColumnNameProperty()
109+
{
110+
Convention(x => x.Element.Column("xxx"));
111+
112+
VerifyModel(x => x.Element.Columns.First().Name.ShouldEqual("xxx"));
113+
}
114+
115+
[Test]
116+
public void ShouldSetElementTypePropertyUsingGeneric()
117+
{
118+
Convention(x => x.Element.Type<string>());
119+
120+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
121+
}
122+
123+
[Test]
124+
public void ShouldSetElementTypePropertyUsingTypeOf()
125+
{
126+
Convention(x => x.Element.Type(typeof(string)));
127+
128+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
129+
}
130+
131+
[Test]
132+
public void ShouldSetElementTypePropertyUsingString() {
133+
Convention(x => x.Element.Type(typeof(string).AssemblyQualifiedName));
134+
135+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
136+
}
137+
107138
[Test]
108139
public void ShouldSetChildKeyColumnNameProperty()
109140
{

src/FluentNHibernate.Testing/ConventionsTests/OverridingFluentInterface/HasManyCollectionConventionTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,46 @@ public void KeyColumnNameShouldntBeOverwritten()
125125
VerifyModel(x => x.Key.Columns.First().Name.ShouldEqual("name"));
126126
}
127127

128+
[Test]
129+
public void ElementColumnNameShouldntBeOverwritten()
130+
{
131+
Mapping(x => x.Children, x => x.Element("name"));
132+
133+
Convention(x => x.Element.Column("xxx"));
134+
135+
VerifyModel(x => x.Element.Columns.First().Name.ShouldEqual("name"));
136+
}
137+
138+
[Test]
139+
public void ElementTypeShouldntBeOverwrittenUsingGeneric()
140+
{
141+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
142+
143+
Convention(x => x.Element.Type<int>());
144+
145+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
146+
}
147+
148+
[Test]
149+
public void ElementTypeShouldntBeOverwrittenUsingTypeOf()
150+
{
151+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
152+
153+
Convention(x => x.Element.Type(typeof(int)));
154+
155+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
156+
}
157+
158+
[Test]
159+
public void ElementTypeShouldntBeOverwrittenUsingString()
160+
{
161+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
162+
163+
Convention(x => x.Element.Type(typeof(int).AssemblyQualifiedName));
164+
165+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
166+
}
167+
128168
[Test]
129169
public void LazyShouldntBeOverwritten()
130170
{

src/FluentNHibernate.Testing/ConventionsTests/OverridingFluentInterface/HasManyConventionTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,46 @@ public void KeyColumnNameShouldntBeOverwritten()
126126
VerifyModel(x => x.Key.Columns.First().Name.ShouldEqual("name"));
127127
}
128128

129+
[Test]
130+
public void ElementColumnNameShouldntBeOverwritten()
131+
{
132+
Mapping(x => x.Children, x => x.Element("name"));
133+
134+
Convention(x => x.Element.Column("xxx"));
135+
136+
VerifyModel(x => x.Element.Columns.First().Name.ShouldEqual("name"));
137+
}
138+
139+
[Test]
140+
public void ElementTypeShouldntBeOverwrittenUsingGeneric()
141+
{
142+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
143+
144+
Convention(x => x.Element.Type<int>());
145+
146+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
147+
}
148+
149+
[Test]
150+
public void ElementTypeShouldntBeOverwrittenUsingTypeOf()
151+
{
152+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
153+
154+
Convention(x => x.Element.Type(typeof(int)));
155+
156+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
157+
}
158+
159+
[Test]
160+
public void ElementTypeShouldntBeOverwrittenUsingString()
161+
{
162+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
163+
164+
Convention(x => x.Element.Type(typeof(int).AssemblyQualifiedName));
165+
166+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
167+
}
168+
129169
[Test]
130170
public void LazyShouldntBeOverwritten()
131171
{

src/FluentNHibernate.Testing/ConventionsTests/OverridingFluentInterface/HasManyToManyCollectionConventionTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,46 @@ public void ParentKeyColumnNameShouldntBeOverwritten()
127127
VerifyModel(x => x.Key.Columns.First().Name.ShouldEqual("name"));
128128
}
129129

130+
[Test]
131+
public void ElementColumnNameShouldntBeOverwritten()
132+
{
133+
Mapping(x => x.Children, x => x.Element("name"));
134+
135+
Convention(x => x.Element.Column("xxx"));
136+
137+
VerifyModel(x => x.Element.Columns.First().Name.ShouldEqual("name"));
138+
}
139+
140+
[Test]
141+
public void ElementTypeShouldntBeOverwrittenUsingGeneric()
142+
{
143+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
144+
145+
Convention(x => x.Element.Type<int>());
146+
147+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
148+
}
149+
150+
[Test]
151+
public void ElementTypeShouldntBeOverwrittenUsingTypeOf()
152+
{
153+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
154+
155+
Convention(x => x.Element.Type(typeof(int)));
156+
157+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
158+
}
159+
160+
[Test]
161+
public void ElementTypeShouldntBeOverwrittenUsingString()
162+
{
163+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
164+
165+
Convention(x => x.Element.Type(typeof(int).AssemblyQualifiedName));
166+
167+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
168+
}
169+
130170
[Test]
131171
public void LazyShouldntBeOverwritten()
132172
{

src/FluentNHibernate.Testing/ConventionsTests/OverridingFluentInterface/HasManyToManyConventionTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,46 @@ public void ParentKeyColumnNameShouldntBeOverwritten()
126126
VerifyModel(x => x.Key.Columns.First().Name.ShouldEqual("name"));
127127
}
128128

129+
[Test]
130+
public void ElementColumnNameShouldntBeOverwritten()
131+
{
132+
Mapping(x => x.Children, x => x.Element("name"));
133+
134+
Convention(x => x.Element.Column("xxx"));
135+
136+
VerifyModel(x => x.Element.Columns.First().Name.ShouldEqual("name"));
137+
}
138+
139+
[Test]
140+
public void ElementTypeShouldntBeOverwrittenUsingGeneric()
141+
{
142+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
143+
144+
Convention(x => x.Element.Type<int>());
145+
146+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
147+
}
148+
149+
[Test]
150+
public void ElementTypeShouldntBeOverwrittenUsingTypeOf()
151+
{
152+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
153+
154+
Convention(x => x.Element.Type(typeof(int)));
155+
156+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
157+
}
158+
159+
[Test]
160+
public void ElementTypeShouldntBeOverwrittenUsingString()
161+
{
162+
Mapping(x => x.Children, x => x.Element("xxx", e => e.Type<string>()));
163+
164+
Convention(x => x.Element.Type(typeof(int).AssemblyQualifiedName));
165+
166+
VerifyModel(x => x.Element.Type.GetUnderlyingSystemType().ShouldEqual(typeof(string)));
167+
}
168+
129169
[Test]
130170
public void ChildKeyColumnNameShouldntBeOverwritten()
131171
{

src/FluentNHibernate/Conventions/Instances/CollectionInstance.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,17 @@ public void SetOrderBy(string orderBy)
272272
get { return new KeyInstance(mapping.Key); }
273273
}
274274

275+
public new IElementInstance Element
276+
{
277+
get
278+
{
279+
if (!mapping.IsSpecified("Element"))
280+
mapping.Element = new ElementMapping();
281+
282+
return new ElementInstance(mapping.Element);
283+
}
284+
}
285+
275286
public void ApplyFilter(string name, string condition)
276287
{
277288
mapping.AddFilter(new FilterMapping

0 commit comments

Comments
 (0)