【发布时间】:2016-06-07 10:24:21
【问题描述】:
我希望 NUnit 测试一个列表顺序,基于两个属性而不是一个。
片段代码(工作):
var list = new List<Tuple<string, string>>
{
new Tuple<string, string>("aaaa", "bbbb"),
new Tuple<string, string>("bbbb", "aaaa"),
new Tuple<string, string>("aaaa", "cccc"),
new Tuple<string, string>("cccc", "bbbb")
};
var ordered = list.OrderBy(p => p.Item1).ThenBy(p => p.Item2);
Assert.That(ordered, Is.Ordered.By("Item1"));
片段代码(我想要的 - 不工作):
var list = new List<Tuple<string, string>>
{
new Tuple<string, string>("aaaa", "bbbb"),
new Tuple<string, string>("bbbb", "aaaa"),
new Tuple<string, string>("aaaa", "cccc"),
new Tuple<string, string>("cccc", "bbbb")
};
var ordered = list.OrderBy(p => p.Item1).ThenBy(p => p.Item2);
Assert.That(ordered, Is.Ordered.By("Item1").ThenBy("Item2"));
// Below syntax works but does not return expected result
// Assert.That(ordered, Is.Ordered.By("Item1").By("Item2"));
【问题讨论】:
-
什么不起作用?
-
.ThenBy("Item2") in "Assert.That(ordered, Is.Ordered.By("Item1").ThenBy("Item2"));"
-
看来你必须编写自己的扩展来实现这一点。
标签: c# .net unit-testing nunit nunit-3.0