Method Single
- Namespace
- Xunit
- Assembly
- xunit.v3.assert.dll
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.
Exceptions
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.
Exceptions
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.
Exceptions
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.
Exceptions
Thrown when the filtered collection does not contain exactly one element.