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
collection
IEnumerableThe 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
collection
IEnumerableThe collection.
expected
objectThe 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
collection
IEnumerable<T>The collection.
Returns
- T
The single item in the collection.
Type Parameters
T
The 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
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.
Exceptions
Thrown when the filtered collection does not contain exactly one element.