Legacy Documentation. View NUnit 3 Documentation

CollectionAssert (NUnit 2.4)

The CollectionAssert class provides a number of methods that are useful when examining collections and their contents or for comparing two collections.

The AreEqual overloads succeed if the two collections contain the same objects, in the same order. AreEquivalent tests whether the collections contain the same objects, without regard to order.

Beginning with NUnit 2.4.6, these methods may be used on any object that implements IEnumerable. Prior to 2.4.6, only true collections were supported.

CollectionAssert.AllItemsAreInstancesOfType( IEnumerable collection,
          Type expectedType );
CollectionAssert.AllItemsAreInstancesOfType( IEnumerable collection,
          Type expectedType, string message );
CollectionAssert.AllItemsAreInstancesOfType( IEnumerable collection,
          Type expectedType, string message, params object[] args );

CollectionAssert.AllItemsAreNotNull( IEnumerable collection );
CollectionAssert.AllItemsAreNotNull( IEnumerable collection,
          string message );
CollectionAssert.AllItemsAreNotNull( IEnumerable collection,
          string message, params object[] args );

CollectionAssert.AllItemsAreUnique( IEnumerable collection );
CollectionAssert.AllItemsAreUnique( IEnumerable collection,
          string message );
CollectionAssert.AllItemsAreUnique( IEnumerable collection,
          string message, params object[] args );

CollectionAssert.AreEqual( IEnumerable expected, IEnumerable actual );
CollectionAssert.AreEqual( IEnumerable expected, IEnumerable actual,
          string message );
CollectionAssert.AreEqual( IEnumerable expected, IEnumerable actual
          string message, params object[] args );

CollectionAssert.AreEquivalent( IEnumerable expected, IEnumerable actual);
CollectionAssert.AreEquivalent( IEnumerable expected, IEnumerable actual,
          string message );
CollectionAssert.AreEquivalent( IEnumerable expected, IEnumerable actual
          string message, params object[] args );

CollectionAssert.AreNotEqual( IEnumerable expected, IEnumerable actual );
CollectionAssert.AreNotEqual( IEnumerable expected, IEnumerable actual,
          string message );
CollectionAssert.AreNotEqual( IEnumerableon expected, IEnumerable actual
          string message, params object[] args );

CollectionAssert.AreNotEquivalent( IEnumerable expected,
          IEnumerable actual );
CollectionAssert.AreNotEquivalent( IEnumerable expected,
          IEnumerable actual, string message );
CollectionAssert.AreNotEquivalent( IEnumerable expected,
          IEnumerable actual, string message, params object[] args );

CollectionAssert.Contains( IEnumerable expected, object actual );
CollectionAssert.Contains( IEnumerable expected, object actual,
          string message );
CollectionAssert.Contains( IEnumerable expected, object actual
          string message, params object[] args );

CollectionAssert.DoesNotContain( IEnumerable expected, object actual );
CollectionAssert.DoesNotContain( IEnumerable expected, object actual,
          string message );
CollectionAssert.DoesNotContain( IEnumerable expected, object actual
          string message, params object[] args );

CollectionAssert.IsSubsetOf( IEnumerable subset, IEnumerable superset );
CollectionAssert.IsSubsetOf( IEnumerable subset, IEnumerable superset,
          string message );
CollectionAssert.IsSubsetOf( IEnumerable subset, IEnumerable superset,
          string message, params object[] args );

CollectionAssert.IsNotSubsetOf( IEnumerable subset, IEnumerable superset);
CollectionAssert.IsNotSubsetOf( IEnumerable subset, IEnumerable superset,
          string message );
CollectionAssert.IsNotSubsetOf( IEnumerable subset, IEnumerable superset,
          string message, params object[] args );

CollectionAssert.IsEmpty( IEnumerable collection );
CollectionAssert.IsEmpty( IEnumerable collection, string message );
CollectionAssert.IsEmpty( IEnumerable collection, string message,
          params object[] args );

CollectionAssert.IsNotEmpty( IEnumerable collection );
CollectionAssert.IsNotEmpty( IEnumerable collection, string message );
CollectionAssert.IsNotEmpty( IEnumerable collection, string message,
          params object[] args );