Can Fluent Assertions use a string-insensitive comparison for IEnumerable<string>?

Zugbo picture Zugbo · Mar 26, 2012 · Viewed 8.9k times · Source

I've got a pair of Lists I'm trying to compare using Fluent Assertions. I can code up a comparison easily, but I'd like to use Fluent Assertions so that I can get the reason to show up in the test failed message.

Everything I've seen so far seems to using the default Object.Equals comparison, which is case-sensitive. I can't seem to pass an IComparer to the Equal or Contains methods, so is there any other way?

[TestMethod()]
public void foo()
{
  var actual = new List<string> { "ONE", "TWO", "THREE", "FOUR" };
  var expected = new List<string> { "One", "Two", "Three", "Four" };

  actual.Should().Equal(expected);
}

Answer

TarasB picture TarasB · Apr 7, 2014

In later versions of FluentAssetrions one can use following:

stringValue.Should().BeEquivalentTo(stringToCompare);

Summary from [metadata]:

    // Summary:
    //     Asserts that a string is exactly the same as another string, including any
    //     leading or trailing whitespace, with the exception of the casing.

Works in version that I use (FluentAssertions.2.2.0.0).