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

前端 未结 4 1068
渐次进展
渐次进展 2021-01-17 10:46

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 rea

4条回答
  •  执念已碎
    2021-01-17 11:09

    How about adding a new Fluent assertion via an extention method (or two)? I've written code to add a .EqualInsensitively(...) to the available fluent assertions for a collection of strings.

    I've put the code to implement this on an external pastebin because its a little long and the MS-PL might not be compatible with CC-Wiki.

    Use something like this:

    private static void Main()
    {
        var mylist = new List {"abc", "DEF", "GHI"};
        mylist.Should().EqualInsensitively(new[] {"AbC", "def", "GHI"})
          .And.NotContain(string.Empty); //Emaple of chaining
    }
    

提交回复
热议问题