title: What makes a class a collection according to NUnit collection constraints?
body: <p>I have a class that implements <code>ICollection&lt;SomeConcreteClass&gt;</code>. The NUnit collections constraints do not recognize it as a collection.</p>
  
  <p>e.g. <code>Assert.That( sut, Has.No.Member( someObjectOfTypeSomeConcreteClass ) );</code> throws <code>System.ArgumentException : The actual value must be a collection</code></p>
  
  <p>and <code>Assert.That( sut, Is.Empty );</code> fails with empty <code>sut</code>.</p>
  
  <p>So when is a collection a collection (according to NUnit)?</p>
  
  <p>Stack Trace:  </p>
  
  <pre><code>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()
  </code></pre>
  
  <p>Above problems occurred with NUnit 2.4.3.0. I just tried it with 2.6. <code>Is.Empty</code> works now, but <code>Has.No.Member</code> still fails. It does not even call <code>Equals()</code> or <code>operator ==()</code>. How does it compare the collection elements? RhinoMocks <code>Arg&lt;MyCollection&gt;.List.Count( Is.Equal( 1 ) )</code> does now fail too.</p>
  
  <p><strong>Conclusion:</strong><br>
  With NUnit 2.4 the collection constraints require implementation of non-generic ICollection for the collection to be recognized as a collection (that answers the original question). IEnumerable equality works as expected.</p>
  
  <p>With NUnit 2.6 (and possibly 3.0) equality of <code>IEnumerable</code>s is checked by matching elements even if <code>Equals</code> is overridden. That's why the membership constraint does not work if the elements are <code>IEnumerable</code>s themselves. This is a known issue (<a href="https://bugs.launchpad.net/nunit-3.0/+bug/646786" rel="nofollow">https://bugs.launchpad.net/nunit-3.0/+bug/646786</a>).</p>
  
  <p>For details see my own answer.</p>