Search Results for

    Show / Hide Table of Contents

    Class CollectionAssert

    A set of Assert methods operating on one or more collections

    Inheritance
    object
    AssertBase
    CollectionAssert
    Inherited Members
    AssertBase.ConvertMessageWithArgs(string, object[])
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    Namespace: NUnit.Framework.Legacy
    Assembly: nunit.framework.legacy.dll
    Syntax
    public abstract class CollectionAssert : AssertBase

    Constructors

    View Source

    CollectionAssert()

    Declaration
    protected CollectionAssert()

    Methods

    View Source

    AllItemsAreInstancesOfType(IEnumerable, Type)

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

    Declaration
    public static void AllItemsAreInstancesOfType(IEnumerable collection, Type expectedType)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable containing objects to be considered

    Type expectedType

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

    View Source

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

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

    Declaration
    public static void AllItemsAreInstancesOfType(IEnumerable collection, Type expectedType, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable containing objects to be considered

    Type expectedType

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

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    AllItemsAreNotNull(IEnumerable)

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

    Declaration
    public static void AllItemsAreNotNull(IEnumerable collection)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable containing objects to be considered

    View Source

    AllItemsAreNotNull(IEnumerable, string, params object?[]?)

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

    Declaration
    public static void AllItemsAreNotNull(IEnumerable collection, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable of objects to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    AllItemsAreUnique(IEnumerable)

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

    Declaration
    public static void AllItemsAreUnique(IEnumerable collection)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable of objects to be considered

    View Source

    AllItemsAreUnique(IEnumerable, string, params object?[]?)

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

    Declaration
    public static void AllItemsAreUnique(IEnumerable collection, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable of objects to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    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.

    Declaration
    public static void AreEqual(IEnumerable expected, IEnumerable actual)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    View Source

    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.

    Declaration
    public static void AreEqual(IEnumerable expected, IEnumerable actual, IComparer comparer)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    IComparer comparer

    The IComparer to use in comparing objects from each IEnumerable

    View Source

    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.

    Declaration
    public static void AreEqual(IEnumerable expected, IEnumerable actual, IComparer comparer, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    IComparer comparer

    The IComparer to use in comparing objects from each IEnumerable

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    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.

    Declaration
    public static void AreEqual(IEnumerable expected, IEnumerable actual, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    AreEquivalent(IEnumerable, IEnumerable)

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

    Declaration
    public static void AreEquivalent(IEnumerable expected, IEnumerable actual)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    View Source

    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.

    Declaration
    public static void AreEquivalent(IEnumerable expected, IEnumerable actual, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    AreNotEqual(IEnumerable, IEnumerable)

    Asserts that expected and actual are not exactly equal.

    Declaration
    public static void AreNotEqual(IEnumerable expected, IEnumerable actual)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    View Source

    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.

    Declaration
    public static void AreNotEqual(IEnumerable expected, IEnumerable actual, IComparer comparer)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    IComparer comparer

    The IComparer to use in comparing objects from each IEnumerable

    View Source

    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.

    Declaration
    public static void AreNotEqual(IEnumerable expected, IEnumerable actual, IComparer comparer, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    IComparer comparer

    The IComparer to use in comparing objects from each IEnumerable

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

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

    Asserts that expected and actual are not exactly equal.

    Declaration
    public static void AreNotEqual(IEnumerable expected, IEnumerable actual, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    AreNotEquivalent(IEnumerable, IEnumerable)

    Asserts that expected and actual are not equivalent.

    Declaration
    public static void AreNotEquivalent(IEnumerable expected, IEnumerable actual)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    View Source

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

    Asserts that expected and actual are not equivalent.

    Declaration
    public static void AreNotEquivalent(IEnumerable expected, IEnumerable actual, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable expected

    The first IEnumerable of objects to be considered

    IEnumerable actual

    The second IEnumerable of objects to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    Contains(IEnumerable, object?)

    Asserts that collection contains actual as an item.

    Declaration
    public static void Contains(IEnumerable collection, object? actual)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable of objects to be considered

    object actual

    Object to be found within collection

    View Source

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

    Asserts that collection contains actual as an item.

    Declaration
    public static void Contains(IEnumerable collection, object? actual, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable of objects to be considered

    object actual

    Object to be found within collection

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    DoesNotContain(IEnumerable, object)

    Asserts that collection does not contain actual as an item.

    Declaration
    public static void DoesNotContain(IEnumerable collection, object actual)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable of objects to be considered

    object actual

    Object that cannot exist within collection

    View Source

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

    Asserts that collection does not contain actual as an item.

    Declaration
    public static void DoesNotContain(IEnumerable collection, object actual, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable collection

    IEnumerable of objects to be considered

    object actual

    Object that cannot exist within collection

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    IsEmpty(IEnumerable)

    Assert that an array,list or other collection is empty

    Declaration
    public static void IsEmpty(IEnumerable collection)
    Parameters
    Type Name Description
    IEnumerable collection

    An array, list or other collection implementing IEnumerable

    View Source

    IsEmpty(IEnumerable, string, params object?[]?)

    Assert that an array, list or other collection is empty

    Declaration
    public static void IsEmpty(IEnumerable collection, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable collection

    An array, list or other collection implementing IEnumerable

    string message

    The message to be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    IsNotEmpty(IEnumerable)

    Assert that an array, list or other collection is not empty.

    Declaration
    public static void IsNotEmpty(IEnumerable collection)
    Parameters
    Type Name Description
    IEnumerable collection

    An array, list or other collection implementing IEnumerable

    View Source

    IsNotEmpty(IEnumerable, string, params object?[]?)

    Assert that an array, list or other collection is not empty.

    Declaration
    public static void IsNotEmpty(IEnumerable collection, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable collection

    An array, list or other collection implementing IEnumerable

    string message

    The message to be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    IsNotSubsetOf(IEnumerable, IEnumerable)

    Asserts that the superset does not contain the subset

    Declaration
    public static void IsNotSubsetOf(IEnumerable subset, IEnumerable superset)
    Parameters
    Type Name Description
    IEnumerable subset

    The IEnumerable subset to be considered

    IEnumerable superset

    The IEnumerable superset to be considered

    View Source

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

    Asserts that the superset does not contain the subset

    Declaration
    public static void IsNotSubsetOf(IEnumerable subset, IEnumerable superset, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable subset

    The IEnumerable subset to be considered

    IEnumerable superset

    The IEnumerable superset to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    IsNotSupersetOf(IEnumerable, IEnumerable)

    Asserts that the subset does not contain the superset

    Declaration
    public static void IsNotSupersetOf(IEnumerable superset, IEnumerable subset)
    Parameters
    Type Name Description
    IEnumerable superset

    The IEnumerable superset to be considered

    IEnumerable subset

    The IEnumerable subset to be considered

    View Source

    IsNotSupersetOf(IEnumerable, IEnumerable, string, params object?[]?)

    Asserts that the subset does not contain the superset

    Declaration
    public static void IsNotSupersetOf(IEnumerable superset, IEnumerable subset, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable superset

    The IEnumerable superset to be considered

    IEnumerable subset

    The IEnumerable subset to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    IsOrdered(IEnumerable)

    Assert that an array, list or other collection is ordered

    Declaration
    public static void IsOrdered(IEnumerable collection)
    Parameters
    Type Name Description
    IEnumerable collection

    An array, list or other collection implementing IEnumerable

    View Source

    IsOrdered(IEnumerable, IComparer)

    Assert that an array, list or other collection is ordered

    Declaration
    public static void IsOrdered(IEnumerable collection, IComparer comparer)
    Parameters
    Type Name Description
    IEnumerable collection

    An array, list or other collection implementing IEnumerable

    IComparer comparer

    A custom comparer to perform the comparisons

    View Source

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

    Assert that an array, list or other collection is ordered

    Declaration
    public static void IsOrdered(IEnumerable collection, IComparer comparer, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable collection

    An array, list or other collection implementing IEnumerable

    IComparer comparer

    A custom comparer to perform the comparisons

    string message

    The message to be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

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

    Assert that an array, list or other collection is ordered

    Declaration
    public static void IsOrdered(IEnumerable collection, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable collection

    An array, list or other collection implementing IEnumerable

    string message

    The message to be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    IsSubsetOf(IEnumerable, IEnumerable)

    Asserts that the superset contains the subset.

    Declaration
    public static void IsSubsetOf(IEnumerable subset, IEnumerable superset)
    Parameters
    Type Name Description
    IEnumerable subset

    The IEnumerable subset to be considered

    IEnumerable superset

    The IEnumerable superset to be considered

    View Source

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

    Asserts that the superset contains the subset.

    Declaration
    public static void IsSubsetOf(IEnumerable subset, IEnumerable superset, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable subset

    The IEnumerable subset to be considered

    IEnumerable superset

    The IEnumerable superset to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    IsSupersetOf(IEnumerable, IEnumerable)

    Asserts that the subset contains the superset.

    Declaration
    public static void IsSupersetOf(IEnumerable superset, IEnumerable subset)
    Parameters
    Type Name Description
    IEnumerable superset

    The IEnumerable superset to be considered

    IEnumerable subset

    The IEnumerable subset to be considered

    View Source

    IsSupersetOf(IEnumerable, IEnumerable, string, params object?[]?)

    Asserts that the subset contains the superset.

    Declaration
    public static void IsSupersetOf(IEnumerable superset, IEnumerable subset, string message, params object?[]? args)
    Parameters
    Type Name Description
    IEnumerable superset

    The IEnumerable superset to be considered

    IEnumerable subset

    The IEnumerable subset to be considered

    string message

    The message that will be displayed on failure

    object[] args

    Arguments to be used in formatting the message

    View Source

    ReferenceEquals(object, object)

    DO NOT USE! The ReferenceEquals method throws an InvalidOperationException. This is done to make sure there is no mistake by calling this function.

    Declaration
    public static void ReferenceEquals(object a, object b)
    Parameters
    Type Name Description
    object a
    object b
    • View Source
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0