Table of Contents

Class CollectionAsserts

Namespace
Asserts
Assembly
xunit.v3.assert.dll
public class CollectionAsserts
Inheritance
CollectionAsserts
Inherited Members

Methods

AllAsync<T>(IEnumerable<T>, Func<T, int, Task>)

Verifies that all items in the collection pass when executed against action. The item index is provided to the action, in addition to the item.

public static Task AllAsync<T>(IEnumerable<T> collection, Func<T, int, Task> action)

Parameters

collection IEnumerable<T>

The collection

action Func<T, int, Task>

The action to test each item against

Returns

Task

Type Parameters

T

The type of the object to be verified

Examples

Add an example for this method ?

Contribution guide.

Exceptions

AllException

Thrown when the collection contains at least one non-matching element

AllAsync<T>(IEnumerable<T>, Func<T, Task>)

Verifies that all items in the collection pass when executed against action.

public static Task AllAsync<T>(IEnumerable<T> collection, Func<T, Task> action)

Parameters

collection IEnumerable<T>

The collection

action Func<T, Task>

The action to test each item against

Returns

Task

Type Parameters

T

The type of the object to be verified

Examples

Add an example for this method ?

Contribution guide.

Exceptions

AllException

Thrown when the collection contains at least one non-matching element

All<T>(IEnumerable<T>, Action<T, int>)

Verifies that all items in the collection pass when executed against action. The item index is provided to the action, in addition to the item.

public static void All<T>(IEnumerable<T> collection, Action<T, int> action)

Parameters

collection IEnumerable<T>

The collection

action Action<T, int>

The action to test each item against

Type Parameters

T

The type of the object to be verified

Examples

Add an example for this method ?

Contribution guide.

Exceptions

AllException

Thrown when the collection contains at least one non-matching element

All<T>(IEnumerable<T>, Action<T>)

Verifies that all items in the collection pass when executed against action.

public static void All<T>(IEnumerable<T> collection, Action<T> action)

Parameters

collection IEnumerable<T>

The collection

action Action<T>

The action to test each item against

Type Parameters

T

The type of the object to be verified

Examples

Add an example for this method ?

Contribution guide.

Exceptions

AllException

Thrown when the collection contains at least one non-matching element

CollectionAsync<T>(IEnumerable<T>, params Func<T, Task>[])

Verifies that a collection contains exactly a given number of elements, which meet the criteria provided by the element inspectors.

public static Task CollectionAsync<T>(IEnumerable<T> collection, params Func<T, Task>[] elementInspectors)

Parameters

collection IEnumerable<T>

The collection to be inspected

elementInspectors Func<T, Task>[]

The element inspectors, which inspect each element in turn. The total number of element inspectors must exactly match the number of elements in the collection.

Returns

Task

Type Parameters

T

The type of the object to be verified

Examples

Add an example for this method ?

Contribution guide.

Collection<T>(IEnumerable<T>, params Action<T>[])

Verifies that a collection contains exactly a given number of elements, which meet the criteria provided by the element inspectors.

public static void Collection<T>(IEnumerable<T> collection, params Action<T>[] elementInspectors)

Parameters

collection IEnumerable<T>

The collection to be inspected

elementInspectors Action<T>[]

The element inspectors, which inspect each element in turn. The total number of element inspectors must exactly match the number of elements in the collection.

Type Parameters

T

The type of the object to be verified

Examples

Add an example for this method ?

Contribution guide.

Contains<T>(IEnumerable<T>, Predicate<T>)

Verifies that a collection contains a given object.

public static void Contains<T>(IEnumerable<T> collection, Predicate<T> filter)

Parameters

collection IEnumerable<T>

The collection to be inspected

filter Predicate<T>

The filter used to find the item you're ensuring the collection contains

Type Parameters

T

The type of the object to be verified

Examples

Add an example for this method ?

Contribution guide.

Exceptions

ContainsException

Thrown when the object is not present in the collection

Contains<T>(T, IEnumerable<T>)

Verifies that a collection contains a given object.

public static void Contains<T>(T expected, IEnumerable<T> collection)

Parameters

expected T

The object expected to be in the collection

collection IEnumerable<T>

The collection to be inspected

Type Parameters

T

The type of the object to be verified

Examples

Add an example for this method ?

Contribution guide.

Exceptions

ContainsException

Thrown when the object is not present in the collection

Contains<T>(T, IEnumerable<T>, IEqualityComparer<T>)

Verifies that a collection contains a given object, using an equality comparer.

public static void Contains<T>(T expected, IEnumerable<T> collection, IEqualityComparer<T> comparer)

Parameters

expected T

The object expected to be in the collection

collection IEnumerable<T>

The collection to be inspected

comparer IEqualityComparer<T>

The comparer used to equate objects in the collection with the expected object

Type Parameters

T

The type of the object to be verified

Examples

Add an example for this method ?

Contribution guide.

Exceptions

ContainsException

Thrown when the object is not present in the collection

Distinct<T>(IEnumerable<T>)

Verifies that a collection contains each object only once.

public static void Distinct<T>(IEnumerable<T> collection)

Parameters

collection IEnumerable<T>

The collection to be inspected

Type Parameters

T

The type of the object to be compared

Examples

Add an example for this method ?

Contribution guide.

Exceptions

DistinctException

Thrown when an object is present inside the collection more than once

Distinct<T>(IEnumerable<T>, IEqualityComparer<T>)

Verifies that a collection contains each object only once.

public static void Distinct<T>(IEnumerable<T> collection, IEqualityComparer<T> comparer)

Parameters

collection IEnumerable<T>

The collection to be inspected

comparer IEqualityComparer<T>

The comparer used to equate objects in the collection with the expected object

Type Parameters

T

The type of the object to be compared

Examples

Add an example for this method ?

Contribution guide.

Exceptions

DistinctException

Thrown when an object is present inside the collection more than once

DoesNotContain<T>(IEnumerable<T>, Predicate<T>)

Verifies that a collection does not contain a given object.

public static void DoesNotContain<T>(IEnumerable<T> collection, Predicate<T> filter)

Parameters

collection IEnumerable<T>

The collection to be inspected

filter Predicate<T>

The filter used to find the item you're ensuring the collection does not contain

Type Parameters

T

The type of the object to be compared

Examples

Add an example for this method ?

Contribution guide.

Exceptions

DoesNotContainException

Thrown when the object is present inside the collection

DoesNotContain<T>(T, IEnumerable<T>)

Verifies that a collection does not contain a given object.

public static void DoesNotContain<T>(T expected, IEnumerable<T> collection)

Parameters

expected T

The object that is expected not to be in the collection

collection IEnumerable<T>

The collection to be inspected

Type Parameters

T

The type of the object to be compared

Examples

Add an example for this method ?

Contribution guide.

Exceptions

DoesNotContainException

Thrown when the object is present inside the collection

DoesNotContain<T>(T, IEnumerable<T>, IEqualityComparer<T>)

Verifies that a collection does not contain a given object, using an equality comparer.

public static void DoesNotContain<T>(T expected, IEnumerable<T> collection, IEqualityComparer<T> comparer)

Parameters

expected T

The object that is expected not to be in the collection

collection IEnumerable<T>

The collection to be inspected

comparer IEqualityComparer<T>

The comparer used to equate objects in the collection with the expected object

Type Parameters

T

The type of the object to be compared

Examples

Add an example for this method ?

Contribution guide.

Exceptions

DoesNotContainException

Thrown when the object is present inside the collection

Empty(IEnumerable)

Verifies that a collection is empty.

public static void Empty(IEnumerable collection)

Parameters

collection IEnumerable

The collection to be inspected

Examples

Add an example for this method ?

Contribution guide.

Exceptions

ArgumentNullException

Thrown when the collection is null

EmptyException

Thrown when the collection is not empty

Equal<T>(IEnumerable<T>?, IEnumerable<T>?)

Verifies that two sequences are equivalent, using a default comparer.

public static void Equal<T>(IEnumerable<T>? expected, IEnumerable<T>? actual)

Parameters

expected IEnumerable<T>

The expected value

actual IEnumerable<T>

The value to be compared against

Type Parameters

T

The type of the objects to be compared

Examples

Add an example for this method ?

Contribution guide.

Exceptions

EqualException

Thrown when the objects are not equal

Equal<T>(IEnumerable<T>?, IEnumerable<T>?, IEqualityComparer<T>)

Verifies that two sequences are equivalent, using a custom equatable comparer.

public static void Equal<T>(IEnumerable<T>? expected, IEnumerable<T>? actual, IEqualityComparer<T> comparer)

Parameters

expected IEnumerable<T>

The expected value

actual IEnumerable<T>

The value to be compared against

comparer IEqualityComparer<T>

The comparer used to compare the two objects

Type Parameters

T

The type of the objects to be compared

Examples

Add an example for this method ?

Contribution guide.

Exceptions

EqualException

Thrown when the objects are not equal

Equal<T>(IEnumerable<T>?, IEnumerable<T>?, Func<T, T, bool>)

Verifies that two collections are equal, using a comparer function against items in the two collections.

public static void Equal<T>(IEnumerable<T>? expected, IEnumerable<T>? actual, Func<T, T, bool> comparer)

Parameters

expected IEnumerable<T>

The expected value

actual IEnumerable<T>

The value to be compared against

comparer Func<T, T, bool>

The function to compare two items for equality

Type Parameters

T

The type of the objects to be compared

Examples

Add an example for this method ?

Contribution guide.

NotEmpty(IEnumerable)

Verifies that a collection is not empty.

public static void NotEmpty(IEnumerable collection)

Parameters

collection IEnumerable

The collection to be inspected

Examples

Add an example for this method ?

Contribution guide.

Exceptions

ArgumentNullException

Thrown when a null collection is passed

NotEmptyException

Thrown when the collection is empty

NotEqual<T>(IEnumerable<T>?, IEnumerable<T>?)

Verifies that two sequences are not equivalent, using a default comparer.

public static void NotEqual<T>(IEnumerable<T>? expected, IEnumerable<T>? actual)

Parameters

expected IEnumerable<T>

The expected object

actual IEnumerable<T>

The actual object

Type Parameters

T

The type of the objects to be compared

Examples

Add an example for this method ?

Contribution guide.

Exceptions

NotEqualException

Thrown when the objects are equal

NotEqual<T>(IEnumerable<T>?, IEnumerable<T>?, IEqualityComparer<T>)

Verifies that two sequences are not equivalent, using a custom equality comparer.

public static void NotEqual<T>(IEnumerable<T>? expected, IEnumerable<T>? actual, IEqualityComparer<T> comparer)

Parameters

expected IEnumerable<T>

The expected object

actual IEnumerable<T>

The actual object

comparer IEqualityComparer<T>

The comparer used to compare the two objects

Type Parameters

T

The type of the objects to be compared

Examples

Add an example for this method ?

Contribution guide.

Exceptions

NotEqualException

Thrown when the objects are equal

NotEqual<T>(IEnumerable<T>?, IEnumerable<T>?, Func<T, T, bool>)

Verifies that two collections are not equal, using a comparer function against items in the two collections.

public static void NotEqual<T>(IEnumerable<T>? expected, IEnumerable<T>? actual, Func<T, T, bool> comparer)

Parameters

expected IEnumerable<T>

The expected value

actual IEnumerable<T>

The value to be compared against

comparer Func<T, T, bool>

The function to compare two items for equality

Type Parameters

T

The type of the objects to be compared

Examples

Add an example for this method ?

Contribution guide.

Single(IEnumerable)

Verifies that the given collection contains only a single element of the given type.

public static object? Single(IEnumerable collection)

Parameters

collection IEnumerable

The collection.

Returns

object

The single item in the collection.

Examples

Add an example for this method ?

Contribution guide.

Exceptions

SingleException

Thrown when the collection does not contain exactly one element.

Single(IEnumerable, object?)

Verifies that the given collection contains only a single element of the given value. The collection may or may not contain other values.

public static void Single(IEnumerable collection, object? expected)

Parameters

collection IEnumerable

The collection.

expected object

The value to find in the collection.

Examples

Add an example for this method ?

Contribution guide.

Exceptions

SingleException

Thrown when the collection does not contain exactly one element.

Single<T>(IEnumerable<T>)

Verifies that the given collection contains only a single element of the given type.

public static T Single<T>(IEnumerable<T> collection)

Parameters

collection IEnumerable<T>

The collection.

Returns

T

The single item in the collection.

Type Parameters

T

The collection type.

Examples

Add an example for this method ?

Contribution guide.

Exceptions

SingleException

Thrown when the collection does not contain exactly one element.

Single<T>(IEnumerable<T>, Predicate<T>)

Verifies that the given collection contains only a single element of the given type which matches the given predicate. The collection may or may not contain other values which do not match the given predicate.

public static T Single<T>(IEnumerable<T> collection, Predicate<T> predicate)

Parameters

collection IEnumerable<T>

The collection.

predicate Predicate<T>

The item matching predicate.

Returns

T

The single item in the filtered collection.

Type Parameters

T

The collection type.

Examples

Add an example for this method ?

Contribution guide.

Exceptions

SingleException

Thrown when the filtered collection does not contain exactly one element.