我有一个类实现ICollection<SomeConcreteClass>
。 NUnit集合约束不会将其识别为集合。根据NUnit集合约束,什么使类成为集合?
例如Assert.That(sut, Has.No.Member(someObjectOfTypeSomeConcreteClass));
抛出System.ArgumentException : The actual value must be a collection
和Assert.That(sut, Is.Empty);
失败,空sut
。
那么什么时候是一个集合(根据NUnit)?
堆栈跟踪:
System.ArgumentException : The actual value must be a collection Parametername: actual
at NUnit.Framework.Constraints.CollectionConstraint.Matches(Object actual)
at NUnit.Framework.Constraints.NotConstraint.Matches(Object actual)
MyTestFile.cs(36,0): at MyAssembly.MyTestFixture.MyTestMethod()
上述问题时与NUnit的2.4.3.0。我只是用2.6试了一下。 Is.Empty
现在有效,但Has.No.Member
仍然失败。它甚至不呼叫Equals()
或operator ==()
。它如何比较收集元素? RhinoMocks Arg<MyCollection>.List.Count(Is.Equal(1))
现在也失败了。
结论:
随着NUnit的2.4集合约束要求实现非泛型ICollection的用于收集被识别为一个集合(即回答了原来的问题)。 IEnumerable相等按预期工作。
使用NUnit 2.6(可能3.0)等于IEnumerable
时,即使重写Equals
,也会通过匹配元素来检查。这就是为什么如果元素本身是IEnumerable
,成员资格约束不起作用。这是一个已知问题(https://bugs.launchpad.net/nunit-3.0/+bug/646786)。
有关详细信息,请参阅我自己的答案。
您可以发布抛出的异常的全栈? – 2012-03-12 08:16:15