Table of Contents

Class CollectionAssert

Namespace
NUnit.Framework
Assembly
nunit.framework.dll

A set of Assert methods operationg on one or more collections

public class CollectionAssert
Inheritance
CollectionAssert
Inherited Members

Constructors

CollectionAssert()

public CollectionAssert()

Methods

AllItemsAreInstancesOfType(IEnumerable, Type)

Asserts that all items contained in collection are of the type specified by expectedType.

public static void AllItemsAreInstancesOfType(IEnumerable collection, Type expectedType)

Parameters

collection IEnumerable

IEnumerable containing objects to be considered

expectedType Type

System.Type that all objects in collection must be instances of

AllItemsAreInstancesOfType(IEnumerable, Type, string)

Asserts that all items contained in collection are of the type specified by expectedType.

public static void AllItemsAreInstancesOfType(IEnumerable collection, Type expectedType, string message)

Parameters

collection IEnumerable

IEnumerable containing objects to be considered

expectedType Type

System.Type that all objects in collection must be instances of

message string

The message that will be displayed on failure

AllItemsAreInstancesOfType(IEnumerable, Type, string, params object[])

Asserts that all items contained in collection are of the type specified by expectedType.

public static void AllItemsAreInstancesOfType(IEnumerable collection, Type expectedType, string message, params object[] args)

Parameters

collection IEnumerable

IEnumerable containing objects to be considered

expectedType Type

System.Type that all objects in collection must be instances of

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

AllItemsAreNotNull(IEnumerable)

Asserts that all items contained in collection are not equal to null.

public static void AllItemsAreNotNull(IEnumerable collection)

Parameters

collection IEnumerable

IEnumerable containing objects to be considered

AllItemsAreNotNull(IEnumerable, string)

Asserts that all items contained in collection are not equal to null.

public static void AllItemsAreNotNull(IEnumerable collection, string message)

Parameters

collection IEnumerable

IEnumerable containing objects to be considered

message string

The message that will be displayed on failure

AllItemsAreNotNull(IEnumerable, string, params object[])

Asserts that all items contained in collection are not equal to null.

public static void AllItemsAreNotNull(IEnumerable collection, string message, params object[] args)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

AllItemsAreUnique(IEnumerable)

Ensures that every object contained in collection exists within the collection once and only once.

public static void AllItemsAreUnique(IEnumerable collection)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

AllItemsAreUnique(IEnumerable, string)

Ensures that every object contained in collection exists within the collection once and only once.

public static void AllItemsAreUnique(IEnumerable collection, string message)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

message string

The message that will be displayed on failure

AllItemsAreUnique(IEnumerable, string, params object[])

Ensures that every object contained in collection exists within the collection once and only once.

public static void AllItemsAreUnique(IEnumerable collection, string message, params object[] args)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

AreEqual(IEnumerable, IEnumerable)

Asserts that expected and actual are exactly equal. The collections must have the same count, and contain the exact same objects in the same order.

public static void AreEqual(IEnumerable expected, IEnumerable actual)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

AreEqual(IEnumerable, IEnumerable, IComparer)

Asserts that expected and actual are exactly equal. The collections must have the same count, and contain the exact same objects in the same order. If comparer is not null then it will be used to compare the objects.

public static void AreEqual(IEnumerable expected, IEnumerable actual, IComparer comparer)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

comparer IComparer

The IComparer to use in comparing objects from each IEnumerable

AreEqual(IEnumerable, IEnumerable, IComparer, string)

Asserts that expected and actual are exactly equal. The collections must have the same count, and contain the exact same objects in the same order. If comparer is not null then it will be used to compare the objects.

public static void AreEqual(IEnumerable expected, IEnumerable actual, IComparer comparer, string message)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

comparer IComparer

The IComparer to use in comparing objects from each IEnumerable

message string

The message that will be displayed on failure

AreEqual(IEnumerable, IEnumerable, IComparer, string, params object[])

Asserts that expected and actual are exactly equal. The collections must have the same count, and contain the exact same objects in the same order. If comparer is not null then it will be used to compare the objects.

public static void AreEqual(IEnumerable expected, IEnumerable actual, IComparer comparer, string message, params object[] args)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

comparer IComparer

The IComparer to use in comparing objects from each IEnumerable

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

AreEqual(IEnumerable, IEnumerable, string)

Asserts that expected and actual are exactly equal. The collections must have the same count, and contain the exact same objects in the same order.

public static void AreEqual(IEnumerable expected, IEnumerable actual, string message)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

message string

The message that will be displayed on failure

AreEqual(IEnumerable, IEnumerable, string, params object[])

Asserts that expected and actual are exactly equal. The collections must have the same count, and contain the exact same objects in the same order.

public static void AreEqual(IEnumerable expected, IEnumerable actual, string message, params object[] args)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

AreEquivalent(IEnumerable, IEnumerable)

Asserts that expected and actual are equivalent, containing the same objects but the match may be in any order.

public static void AreEquivalent(IEnumerable expected, IEnumerable actual)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

AreEquivalent(IEnumerable, IEnumerable, string)

Asserts that expected and actual are equivalent, containing the same objects but the match may be in any order.

public static void AreEquivalent(IEnumerable expected, IEnumerable actual, string message)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

message string

The message that will be displayed on failure

AreEquivalent(IEnumerable, IEnumerable, string, params object[])

Asserts that expected and actual are equivalent, containing the same objects but the match may be in any order.

public static void AreEquivalent(IEnumerable expected, IEnumerable actual, string message, params object[] args)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

AreNotEqual(IEnumerable, IEnumerable)

Asserts that expected and actual are not exactly equal.

public static void AreNotEqual(IEnumerable expected, IEnumerable actual)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

AreNotEqual(IEnumerable, IEnumerable, IComparer)

Asserts that expected and actual are not exactly equal. If comparer is not null then it will be used to compare the objects.

public static void AreNotEqual(IEnumerable expected, IEnumerable actual, IComparer comparer)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

comparer IComparer

The IComparer to use in comparing objects from each IEnumerable

AreNotEqual(IEnumerable, IEnumerable, IComparer, string)

Asserts that expected and actual are not exactly equal. If comparer is not null then it will be used to compare the objects.

public static void AreNotEqual(IEnumerable expected, IEnumerable actual, IComparer comparer, string message)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

comparer IComparer

The IComparer to use in comparing objects from each IEnumerable

message string

The message that will be displayed on failure

AreNotEqual(IEnumerable, IEnumerable, IComparer, string, params object[])

Asserts that expected and actual are not exactly equal. If comparer is not null then it will be used to compare the objects.

public static void AreNotEqual(IEnumerable expected, IEnumerable actual, IComparer comparer, string message, params object[] args)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

comparer IComparer

The IComparer to use in comparing objects from each IEnumerable

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

AreNotEqual(IEnumerable, IEnumerable, string)

Asserts that expected and actual are not exactly equal.

public static void AreNotEqual(IEnumerable expected, IEnumerable actual, string message)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

message string

The message that will be displayed on failure

AreNotEqual(IEnumerable, IEnumerable, string, params object[])

Asserts that expected and actual are not exactly equal.

public static void AreNotEqual(IEnumerable expected, IEnumerable actual, string message, params object[] args)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

AreNotEquivalent(IEnumerable, IEnumerable)

Asserts that expected and actual are not equivalent.

public static void AreNotEquivalent(IEnumerable expected, IEnumerable actual)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

AreNotEquivalent(IEnumerable, IEnumerable, string)

Asserts that expected and actual are not equivalent.

public static void AreNotEquivalent(IEnumerable expected, IEnumerable actual, string message)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

message string

The message that will be displayed on failure

AreNotEquivalent(IEnumerable, IEnumerable, string, params object[])

Asserts that expected and actual are not equivalent.

public static void AreNotEquivalent(IEnumerable expected, IEnumerable actual, string message, params object[] args)

Parameters

expected IEnumerable

The first IEnumerable of objects to be considered

actual IEnumerable

The second IEnumerable of objects to be considered

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

Contains(IEnumerable, object)

Asserts that collection contains actual as an item.

public static void Contains(IEnumerable collection, object actual)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

actual object

Object to be found within collection

Contains(IEnumerable, object, string)

Asserts that collection contains actual as an item.

public static void Contains(IEnumerable collection, object actual, string message)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

actual object

Object to be found within collection

message string

The message that will be displayed on failure

Contains(IEnumerable, object, string, params object[])

Asserts that collection contains actual as an item.

public static void Contains(IEnumerable collection, object actual, string message, params object[] args)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

actual object

Object to be found within collection

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

DoesNotContain(IEnumerable, object)

Asserts that collection does not contain actual as an item.

public static void DoesNotContain(IEnumerable collection, object actual)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

actual object

Object that cannot exist within collection

DoesNotContain(IEnumerable, object, string)

Asserts that collection does not contain actual as an item.

public static void DoesNotContain(IEnumerable collection, object actual, string message)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

actual object

Object that cannot exist within collection

message string

The message that will be displayed on failure

DoesNotContain(IEnumerable, object, string, params object[])

Asserts that collection does not contain actual as an item.

public static void DoesNotContain(IEnumerable collection, object actual, string message, params object[] args)

Parameters

collection IEnumerable

IEnumerable of objects to be considered

actual object

Object that cannot exist within collection

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

IsEmpty(IEnumerable)

Assert that an array,list or other collection is empty

public static void IsEmpty(IEnumerable collection)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

IsEmpty(IEnumerable, string)

Assert that an array, list or other collection is empty

public static void IsEmpty(IEnumerable collection, string message)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

message string

The message to be displayed on failure

IsEmpty(IEnumerable, string, params object[])

Assert that an array, list or other collection is empty

public static void IsEmpty(IEnumerable collection, string message, params object[] args)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

message string

The message to be displayed on failure

args object[]

Arguments to be used in formatting the message

IsNotEmpty(IEnumerable)

Assert that an array,list or other collection is empty

public static void IsNotEmpty(IEnumerable collection)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

IsNotEmpty(IEnumerable, string)

Assert that an array, list or other collection is empty

public static void IsNotEmpty(IEnumerable collection, string message)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

message string

The message to be displayed on failure

IsNotEmpty(IEnumerable, string, params object[])

Assert that an array, list or other collection is empty

public static void IsNotEmpty(IEnumerable collection, string message, params object[] args)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

message string

The message to be displayed on failure

args object[]

Arguments to be used in formatting the message

IsNotSubsetOf(IEnumerable, IEnumerable)

Asserts that the superset does not contain the subset

public static void IsNotSubsetOf(IEnumerable subset, IEnumerable superset)

Parameters

subset IEnumerable

The IEnumerable subset to be considered

superset IEnumerable

The IEnumerable superset to be considered

IsNotSubsetOf(IEnumerable, IEnumerable, string)

Asserts that the superset does not contain the subset

public static void IsNotSubsetOf(IEnumerable subset, IEnumerable superset, string message)

Parameters

subset IEnumerable

The IEnumerable subset to be considered

superset IEnumerable

The IEnumerable superset to be considered

message string

The message that will be displayed on failure

IsNotSubsetOf(IEnumerable, IEnumerable, string, params object[])

Asserts that the superset does not contain the subset

public static void IsNotSubsetOf(IEnumerable subset, IEnumerable superset, string message, params object[] args)

Parameters

subset IEnumerable

The IEnumerable subset to be considered

superset IEnumerable

The IEnumerable superset to be considered

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

IsOrdered(IEnumerable)

Assert that an array, list or other collection is ordered

public static void IsOrdered(IEnumerable collection)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

IsOrdered(IEnumerable, IComparer)

Assert that an array, list or other collection is ordered

public static void IsOrdered(IEnumerable collection, IComparer comparer)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

comparer IComparer

A custom comparer to perform the comparisons

IsOrdered(IEnumerable, IComparer, string)

Assert that an array, list or other collection is ordered

public static void IsOrdered(IEnumerable collection, IComparer comparer, string message)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

comparer IComparer

A custom comparer to perform the comparisons

message string

The message to be displayed on failure

IsOrdered(IEnumerable, IComparer, string, params object[])

Assert that an array, list or other collection is ordered

public static void IsOrdered(IEnumerable collection, IComparer comparer, string message, params object[] args)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

comparer IComparer

A custom comparer to perform the comparisons

message string

The message to be displayed on failure

args object[]

Arguments to be used in formatting the message

IsOrdered(IEnumerable, string)

Assert that an array, list or other collection is ordered

public static void IsOrdered(IEnumerable collection, string message)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

message string

The message to be displayed on failure

IsOrdered(IEnumerable, string, params object[])

Assert that an array, list or other collection is ordered

public static void IsOrdered(IEnumerable collection, string message, params object[] args)

Parameters

collection IEnumerable

An array, list or other collection implementing IEnumerable

message string

The message to be displayed on failure

args object[]

Arguments to be used in formatting the message

IsSubsetOf(IEnumerable, IEnumerable)

Asserts that the superset contains the subset.

public static void IsSubsetOf(IEnumerable subset, IEnumerable superset)

Parameters

subset IEnumerable

The IEnumerable subset to be considered

superset IEnumerable

The IEnumerable superset to be considered

IsSubsetOf(IEnumerable, IEnumerable, string)

Asserts that the superset contains the subset.

public static void IsSubsetOf(IEnumerable subset, IEnumerable superset, string message)

Parameters

subset IEnumerable

The IEnumerable subset to be considered

superset IEnumerable

The IEnumerable superset to be considered

message string

The message that will be displayed on failure

IsSubsetOf(IEnumerable, IEnumerable, string, params object[])

Asserts that the superset contains the subset.

public static void IsSubsetOf(IEnumerable subset, IEnumerable superset, string message, params object[] args)

Parameters

subset IEnumerable

The IEnumerable subset to be considered

superset IEnumerable

The IEnumerable superset to be considered

message string

The message that will be displayed on failure

args object[]

Arguments to be used in formatting the message

ReferenceEquals(object, object)

override the default ReferenceEquals to throw an AssertionException. This implementation makes sure there is no mistake in calling this function as part of Assert.

public static void ReferenceEquals(object a, object b)

Parameters

a object
b object