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

前端 未结 4 1067
渐次进展
渐次进展 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:04

    We could add an optional lambda expression to the Equal() method. Then, you could do something like

    [TestMethod()] 
    public void foo() 
    { 
       var actual = new List { "ONE", "TWO", "THREE", "FOUR" }; 
       var expected = new List { "One", "Two", "Three", "Four" }; 
    
      actual.Should().Equal(expected, 
        (o1, o2) => string.Compare(o1, o2, StringComparison.InvariantCultureIgnoreCase))
    } 
    

    A IComparer would also be possible, but I think the occasional exception to Equal()'s default behavior wouldn't warrant an additional custom-written class. In fact, a separate IComparer might ever obscure the intention of the test. Let me know what you guys think is the best solution, so I can add it as an issue on Codeplex for release 1.8.0.

提交回复
热议问题