使用约束断言元素数量

Assert number of elements using constraint

使用 constraint syntax 断言集合中元素数量的正确方法是什么?

类似于:

Assert.That(collection, Has.Exactly(3).Elements);

您可以这样做:

Assert.AreEqual(YourCollection.Count,Number);

这是使用约束语法的等价物

Assert.That(集合,Has.Count.EqualTo(3));