【发布时间】:2015-05-06 15:14:01
【问题描述】:
我知道
Assert.IsFalse(postsPageOne.Intersect(postsPageTwo).Any());
您可以比较对象以查找任何重复项。
但我想在我的方法中使用它之后检查我的列表是否包含重复项。下面是测试代码:
///ARRANGE
///
var toShuffle = new List<int>(){
1001,
1002,
1003,
1004,
1005,
1006,
1007,
1008,
1009,
1010
};
///ACT
///
toShuffle = Shared_Components.SharedComponents.Shuffle(toShuffle, 10);
///ASSERT
///
Assert.IsTrue(toShuffle.Count == 10, "Number of Elements not correct!");
Assert.IsTrue(toShuffle.All(a => a >= 1001 && a <= 1010), "Elements out of range!");
【问题讨论】:
-
你真的应该使用 Assert.AreEqual(10, toShuffle.Count, "Number of Elements not correct!"),而不是 Assert.IsTrue()。这将使您的失败测试报告更加有用。
-
@Grant Winney:Shuffle() 方法改变了每个数字的 [index] 位置。
标签: c# linq list unit-testing stub