我如何断言使用FluentAssertions将集合按2个属性排序?

Lar*_*Fix 1 c# unit-testing fluent-assertions

我最近发现FluentAssertions有一个名为BeInAscendingOrder的集合断言。太棒了!

public class MyItems
{
    public int SequenceNumber { get; set; }
    public int Name { get; set; }
}

IList<int> resultingList = myClassUnderTest.GetOrderedList();

resultingList.Should().BeInAscendingOrder(m => m.SequenceNumber);
Run Code Online (Sandbox Code Playgroud)

但现在我想测试一个列表是否按2个属性排序。这可能吗?

Den*_*men 5

你真的不能。您在其中传递的lambda会转换为属性表达式,而不是可执行的lambda语句。并且没有提供您自己的IComparer实现的重载。

Your best bet is to generate a collection that contains those items in the right order and comparing it with Should().Equal. This will assert both collections contain the same elements in the same order.