0

I have two collections that contain objects of my custom type. I compare these collections using FluentAssertions library:

Collection1.Should().BeEquivalentTo(Collection2);

Let's say, objects in the collections have string property called Title, but sometimes their case is different (title case vs. upper case). The comparison fails due to this.

Is there a way to ignore case for some (or all) object's string properties when comparing collections?

YMM
  • 632
  • 1
  • 10
  • 21

2 Answers2

1

No, sorry. But you could create your own implementation of IMemberSelectionRule

Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44
  • Thanks for the suggestion, but I found a way to make these string properties `ToUpper()` on collection initialization, so the case does not matter. – YMM May 06 '17 at 23:07
  • Wait, you meant that the casing of the actual property _values_ had different casing. I thought you meant the names of the properties. – Dennis Doomen May 08 '17 at 05:16
  • No, case of property values. The names are always 'Title'. – YMM May 09 '17 at 10:21
1

Yes. Just make your custom type implement IComparable interface. In CompareTo method implement a comparison whatever way you want. In your case, a ignore-case string comparison.

ozgur
  • 2,549
  • 4
  • 25
  • 40