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 corresponding elements of the two collections are equal. AreEquivalent tests whether the collection contents are equal, but without regard to order. In both cases, elements are compared using NUnit's default equality comparison.
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 );
The following methods are available beginning with NUnit 2.5
CollectionAssert.IsOrdered( IEnumerable collection ); CollectionAssert.IsOrdered( IEnumerable collection, string message ); CollectionAssert.IsOrdered( IEnumerable collection, string message, params object[] args ); CollectionAssert.IsOrdered( IEnumerable collection, IComparer comparer ); CollectionAssert.IsOrdered( IEnumerable collection, IComparer comparer, string message ); CollectionAssert.IsOrdered( IEnumerable collection, IComparer comparer, string message, params object[] args );