Skip to content

Commit 7665282

Browse files
committed
Added an overload of CheckList to match the added overload of CheckReference
1 parent a1e3d07 commit 7665282

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/FluentNHibernate.Testing/Testing/PersistenceSpecificationTester.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ public void should_not_be_equal_without_the_equality_comparer()
145145
_spec.CheckList(x => x.AllKittens, _cat.AllKittens).VerifyTheMappings());
146146
}
147147

148+
[Test]
149+
public void Comparing_objects_in_two_lists_should_use_the_specified_comparisons()
150+
{
151+
_spec.CheckList(x => x.AllKittens, _cat.AllKittens, kitten => kitten.Id).VerifyTheMappings();
152+
153+
// Should fail because the names don't match.
154+
Assert.Throws<ApplicationException>(() => _spec.CheckList(x => x.AllKittens, _cat.AllKittens, kitten => kitten.Id, kitten => kitten.Name)
155+
.VerifyTheMappings());
156+
}
157+
148158
[Test]
149159
public void Can_test_enumerable()
150160
{
@@ -174,6 +184,7 @@ public void Comparing_reference_should_use_the_specified_property_comparisons()
174184
{
175185
_spec.CheckReference(cat => cat.FirstKitten, _cat.FirstKitten, x => x.Id).VerifyTheMappings();
176186

187+
// Should fail because the names don't match.
177188
Assert.Throws<ApplicationException>(() => _spec.CheckReference(cat => cat.FirstKitten, _cat.FirstKitten, x => x.Id, x => x.Name)
178189
.VerifyTheMappings());
179190
}

src/FluentNHibernate/Testing/PersistenceSpecificationExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ public static PersistenceSpecification<T> CheckList<T, TListElement>(this Persis
135135
return spec.RegisterCheckedProperty(new ReferenceList<T, TListElement>(property, propertyValue), elementComparer);
136136
}
137137

138+
public static PersistenceSpecification<T> CheckList<T, TListElement>(this PersistenceSpecification<T> spec,
139+
Expression<Func<T, IEnumerable<TListElement>>> expression,
140+
IEnumerable<TListElement> propertyValue,
141+
params Func<TListElement, object>[] propertiesToCompare)
142+
{
143+
// Because of the params keyword, the compiler can select this overload
144+
// instead of the one above, even when no funcs are supplied in the method call.
145+
if (propertiesToCompare == null || propertiesToCompare.Length == 0)
146+
return spec.CheckList(expression, propertyValue, (IEqualityComparer)null);
147+
148+
return spec.CheckList(expression, propertyValue, new FuncEqualityComparer<TListElement>(propertiesToCompare));
149+
}
150+
138151
public static PersistenceSpecification<T> CheckList<T, TListElement>(this PersistenceSpecification<T> spec,
139152
Expression<Func<T, IEnumerable<TListElement>>> expression,
140153
IEnumerable<TListElement> propertyValue,

0 commit comments

Comments
 (0)