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
collectionIEnumerable<T>The collection
actionFunc<T, int, Task>The action to test each item against
Returns
Type Parameters
TThe 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
collectionIEnumerable<T>The collection
actionFunc<T, Task>The action to test each item against
Returns
Type Parameters
TThe 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
collectionIEnumerable<T>The collection
actionAction<T, int>The action to test each item against
Type Parameters
TThe 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
collectionIEnumerable<T>The collection
actionAction<T>The action to test each item against
Type Parameters
TThe 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
collectionIEnumerable<T>The collection to be inspected
elementInspectorsFunc<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
Type Parameters
TThe 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
collectionIEnumerable<T>The collection to be inspected
elementInspectorsAction<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
TThe 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
collectionIEnumerable<T>The collection to be inspected
filterPredicate<T>The filter used to find the item you're ensuring the collection contains
Type Parameters
TThe 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
expectedTThe object expected to be in the collection
collectionIEnumerable<T>The collection to be inspected
Type Parameters
TThe 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
expectedTThe object expected to be in the collection
collectionIEnumerable<T>The collection to be inspected
comparerIEqualityComparer<T>The comparer used to equate objects in the collection with the expected object
Type Parameters
TThe 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
collectionIEnumerable<T>The collection to be inspected
Type Parameters
TThe 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
collectionIEnumerable<T>The collection to be inspected
comparerIEqualityComparer<T>The comparer used to equate objects in the collection with the expected object
Type Parameters
TThe 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
collectionIEnumerable<T>The collection to be inspected
filterPredicate<T>The filter used to find the item you're ensuring the collection does not contain
Type Parameters
TThe 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
expectedTThe object that is expected not to be in the collection
collectionIEnumerable<T>The collection to be inspected
Type Parameters
TThe 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
expectedTThe object that is expected not to be in the collection
collectionIEnumerable<T>The collection to be inspected
comparerIEqualityComparer<T>The comparer used to equate objects in the collection with the expected object
Type Parameters
TThe 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
collectionIEnumerableThe 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
expectedIEnumerable<T>The expected value
actualIEnumerable<T>The value to be compared against
Type Parameters
TThe 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
expectedIEnumerable<T>The expected value
actualIEnumerable<T>The value to be compared against
comparerIEqualityComparer<T>The comparer used to compare the two objects
Type Parameters
TThe 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
expectedIEnumerable<T>The expected value
actualIEnumerable<T>The value to be compared against
comparerFunc<T, T, bool>The function to compare two items for equality
Type Parameters
TThe 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
collectionIEnumerableThe 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
expectedIEnumerable<T>The expected object
actualIEnumerable<T>The actual object
Type Parameters
TThe 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
expectedIEnumerable<T>The expected object
actualIEnumerable<T>The actual object
comparerIEqualityComparer<T>The comparer used to compare the two objects
Type Parameters
TThe 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
expectedIEnumerable<T>The expected value
actualIEnumerable<T>The value to be compared against
comparerFunc<T, T, bool>The function to compare two items for equality
Type Parameters
TThe 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
collectionIEnumerableThe 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
collectionIEnumerableThe collection.
expectedobjectThe 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
collectionIEnumerable<T>The collection.
Returns
- T
The single item in the collection.
Type Parameters
TThe 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
collectionIEnumerable<T>The collection.
predicatePredicate<T>The item matching predicate.
Returns
- T
The single item in the filtered collection.
Type Parameters
TThe collection type.
Examples
Add an example for this method ?
Contribution guide.
Exceptions
- SingleException
Thrown when the filtered collection does not contain exactly one element.