Table of Contents

Method Contains

Namespace
Xunit
Assembly
xunit.v3.assert.dll

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

Exceptions

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

Exceptions

Thrown when the object is not present in the collection

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

Exceptions

Thrown when the object is not present in the collection

Contains<TKey, TValue>(TKey, IDictionary<TKey, TValue>)

Verifies that a dictionary contains a given key.

public static TValue Contains<TKey, TValue>(TKey expected, IDictionary<TKey, TValue> collection) where TKey : notnull

Parameters

expected TKey

The object expected to be in the collection.

collection IDictionary<TKey, TValue>

The collection to be inspected.

Returns

TValue

The value associated with expected.

Type Parameters

TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions

Thrown when the object is not present in the collection

Contains<TKey, TValue>(TKey, IReadOnlyDictionary<TKey, TValue>)

Verifies that a read-only dictionary contains a given key.

public static TValue Contains<TKey, TValue>(TKey expected, IReadOnlyDictionary<TKey, TValue> collection) where TKey : notnull

Parameters

expected TKey

The object expected to be in the collection.

collection IReadOnlyDictionary<TKey, TValue>

The collection to be inspected.

Returns

TValue

The value associated with expected.

Type Parameters

TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions

Thrown when the object is not present in the collection

Contains<TKey, TValue>(TKey, ConcurrentDictionary<TKey, TValue>)

Verifies that a dictionary contains a given key.

public static TValue Contains<TKey, TValue>(TKey expected, ConcurrentDictionary<TKey, TValue> collection) where TKey : notnull

Parameters

expected TKey

The object expected to be in the collection.

collection ConcurrentDictionary<TKey, TValue>

The collection to be inspected.

Returns

TValue

The value associated with expected.

Type Parameters

TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions

Thrown when the object is not present in the collection

Contains<TKey, TValue>(TKey, Dictionary<TKey, TValue>)

Verifies that a dictionary contains a given key.

public static TValue Contains<TKey, TValue>(TKey expected, Dictionary<TKey, TValue> collection) where TKey : notnull

Parameters

expected TKey

The object expected to be in the collection.

collection Dictionary<TKey, TValue>

The collection to be inspected.

Returns

TValue

The value associated with expected.

Type Parameters

TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions

Thrown when the object is not present in the collection

Contains<TKey, TValue>(TKey, ReadOnlyDictionary<TKey, TValue>)

Verifies that a dictionary contains a given key.

public static TValue Contains<TKey, TValue>(TKey expected, ReadOnlyDictionary<TKey, TValue> collection) where TKey : notnull

Parameters

expected TKey

The object expected to be in the collection.

collection ReadOnlyDictionary<TKey, TValue>

The collection to be inspected.

Returns

TValue

The value associated with expected.

Type Parameters

TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions

Thrown when the object is not present in the collection

Contains<TKey, TValue>(TKey, ImmutableDictionary<TKey, TValue>)

Verifies that a dictionary contains a given key.

public static TValue Contains<TKey, TValue>(TKey expected, ImmutableDictionary<TKey, TValue> collection) where TKey : notnull

Parameters

expected TKey

The object expected to be in the collection.

collection ImmutableDictionary<TKey, TValue>

The collection to be inspected.

Returns

TValue

The value associated with expected.

Type Parameters

TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions

Thrown when the object is not present in the collection

Contains<T>(Memory<T>, Memory<T>)

Verifies that a Memory contains a given sub-Memory

public static void Contains<T>(Memory<T> expectedSubMemory, Memory<T> actualMemory) where T : IEquatable<T>

Parameters

expectedSubMemory Memory<T>

The sub-Memory expected to be in the Memory

actualMemory Memory<T>

The Memory to be inspected

Type Parameters

T

Exceptions

Thrown when the sub-Memory is not present inside the Memory

Contains<T>(Memory<T>, ReadOnlyMemory<T>)

Verifies that a Memory contains a given sub-Memory

public static void Contains<T>(Memory<T> expectedSubMemory, ReadOnlyMemory<T> actualMemory) where T : IEquatable<T>

Parameters

expectedSubMemory Memory<T>

The sub-Memory expected to be in the Memory

actualMemory ReadOnlyMemory<T>

The Memory to be inspected

Type Parameters

T

Exceptions

Thrown when the sub-Memory is not present inside the Memory

Contains<T>(ReadOnlyMemory<T>, Memory<T>)

Verifies that a Memory contains a given sub-Memory

public static void Contains<T>(ReadOnlyMemory<T> expectedSubMemory, Memory<T> actualMemory) where T : IEquatable<T>

Parameters

expectedSubMemory ReadOnlyMemory<T>

The sub-Memory expected to be in the Memory

actualMemory Memory<T>

The Memory to be inspected

Type Parameters

T

Exceptions

Thrown when the sub-Memory is not present inside the Memory

Contains<T>(ReadOnlyMemory<T>, ReadOnlyMemory<T>)

Verifies that a Memory contains a given sub-Memory

public static void Contains<T>(ReadOnlyMemory<T> expectedSubMemory, ReadOnlyMemory<T> actualMemory) where T : IEquatable<T>

Parameters

expectedSubMemory ReadOnlyMemory<T>

The sub-Memory expected to be in the Memory

actualMemory ReadOnlyMemory<T>

The Memory to be inspected

Type Parameters

T

Exceptions

Thrown when the sub-Memory is not present inside the Memory

Contains<T>(T, ISet<T>)

Verifies that the set contains the given object.

public static void Contains<T>(T expected, ISet<T> set)

Parameters

expected T

The object expected to be in the set

set ISet<T>

The set to be inspected

Type Parameters

T

The type of the object to be verified

Exceptions

Thrown when the object is not present in the set

Contains<T>(T, HashSet<T>)

Verifies that the hashset contains the given object.

public static void Contains<T>(T expected, HashSet<T> set)

Parameters

expected T

The object expected to be in the set

set HashSet<T>

The set to be inspected

Type Parameters

T

The type of the object to be verified

Exceptions

Thrown when the object is not present in the set

Contains<T>(T, SortedSet<T>)

Verifies that the sorted hashset contains the given object.

public static void Contains<T>(T expected, SortedSet<T> set)

Parameters

expected T

The object expected to be in the set

set SortedSet<T>

The set to be inspected

Type Parameters

T

The type of the object to be verified

Exceptions

Thrown when the object is not present in the set

Contains<T>(T, ImmutableHashSet<T>)

Verifies that the immutable hashset contains the given object.

public static void Contains<T>(T expected, ImmutableHashSet<T> set)

Parameters

expected T

The object expected to be in the set

set ImmutableHashSet<T>

The set to be inspected

Type Parameters

T

The type of the object to be verified

Exceptions

Thrown when the object is not present in the set

Contains<T>(T, ImmutableSortedSet<T>)

Verifies that the immutable sorted hashset contains the given object.

public static void Contains<T>(T expected, ImmutableSortedSet<T> set)

Parameters

expected T

The object expected to be in the set

set ImmutableSortedSet<T>

The set to be inspected

Type Parameters

T

The type of the object to be verified

Exceptions

Thrown when the object is not present in the set

Contains<T>(Span<T>, Span<T>)

Verifies that a span contains a given sub-span

public static void Contains<T>(Span<T> expectedSubSpan, Span<T> actualSpan) where T : IEquatable<T>

Parameters

expectedSubSpan Span<T>

The sub-span expected to be in the span

actualSpan Span<T>

The span to be inspected

Type Parameters

T

Exceptions

Thrown when the sub-span is not present inside the span

Contains<T>(Span<T>, ReadOnlySpan<T>)

Verifies that a span contains a given sub-span

public static void Contains<T>(Span<T> expectedSubSpan, ReadOnlySpan<T> actualSpan) where T : IEquatable<T>

Parameters

expectedSubSpan Span<T>

The sub-span expected to be in the span

actualSpan ReadOnlySpan<T>

The span to be inspected

Type Parameters

T

Exceptions

Thrown when the sub-span is not present inside the span

Contains<T>(ReadOnlySpan<T>, Span<T>)

Verifies that a span contains a given sub-span

public static void Contains<T>(ReadOnlySpan<T> expectedSubSpan, Span<T> actualSpan) where T : IEquatable<T>

Parameters

expectedSubSpan ReadOnlySpan<T>

The sub-span expected to be in the span

actualSpan Span<T>

The span to be inspected

Type Parameters

T

Exceptions

Thrown when the sub-span is not present inside the span

Contains<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

Verifies that a span contains a given sub-span

public static void Contains<T>(ReadOnlySpan<T> expectedSubSpan, ReadOnlySpan<T> actualSpan) where T : IEquatable<T>

Parameters

expectedSubSpan ReadOnlySpan<T>

The sub-span expected to be in the span

actualSpan ReadOnlySpan<T>

The span to be inspected

Type Parameters

T

Exceptions

Thrown when the sub-span is not present inside the span

Contains(string, string?)

Verifies that a string contains a given sub-string, using the current culture.

public static void Contains(string expectedSubstring, string? actualString)

Parameters

expectedSubstring string

The sub-string expected to be in the string

actualString string

The string to be inspected

Exceptions

Thrown when the sub-string is not present inside the string

Contains(string, string?, StringComparison)

Verifies that a string contains a given sub-string, using the given comparison type.

public static void Contains(string expectedSubstring, string? actualString, StringComparison comparisonType)

Parameters

expectedSubstring string

The sub-string expected to be in the string

actualString string

The string to be inspected

comparisonType StringComparison

The type of string comparison to perform

Exceptions

Thrown when the sub-string is not present inside the string

Contains(Memory<char>, Memory<char>)

Verifies that a string contains a given sub-string, using the current culture.

public static void Contains(Memory<char> expectedSubstring, Memory<char> actualString)

Parameters

expectedSubstring Memory<char>

The sub-string expected to be in the string

actualString Memory<char>

The string to be inspected

Exceptions

Thrown when the sub-string is not present inside the string

Contains(Memory<char>, ReadOnlyMemory<char>)

Verifies that a string contains a given sub-string, using the current culture.

public static void Contains(Memory<char> expectedSubstring, ReadOnlyMemory<char> actualString)

Parameters

expectedSubstring Memory<char>

The sub-string expected to be in the string

actualString ReadOnlyMemory<char>

The string to be inspected

Exceptions

Thrown when the sub-string is not present inside the string

Contains(ReadOnlyMemory<char>, Memory<char>)

Verifies that a string contains a given sub-string, using the current culture.

public static void Contains(ReadOnlyMemory<char> expectedSubstring, Memory<char> actualString)

Parameters

expectedSubstring ReadOnlyMemory<char>

The sub-string expected to be in the string

actualString Memory<char>

The string to be inspected

Exceptions

Thrown when the sub-string is not present inside the string

Contains(ReadOnlyMemory<char>, ReadOnlyMemory<char>)

Verifies that a string contains a given sub-string, using the current culture.

public static void Contains(ReadOnlyMemory<char> expectedSubstring, ReadOnlyMemory<char> actualString)

Parameters

expectedSubstring ReadOnlyMemory<char>

The sub-string expected to be in the string

actualString ReadOnlyMemory<char>

The string to be inspected

Exceptions

Thrown when the sub-string is not present inside the string

Contains(Memory<char>, Memory<char>, StringComparison)

Verifies that a string contains a given sub-string, using the given comparison type.

public static void Contains(Memory<char> expectedSubstring, Memory<char> actualString, StringComparison comparisonType = StringComparison.CurrentCulture)

Parameters

expectedSubstring Memory<char>

The sub-string expected to be in the string

actualString Memory<char>

The string to be inspected

comparisonType StringComparison

The type of string comparison to perform

Exceptions

Thrown when the sub-string is not present inside the string

Contains(Memory<char>, ReadOnlyMemory<char>, StringComparison)

Verifies that a string contains a given sub-string, using the given comparison type.

public static void Contains(Memory<char> expectedSubstring, ReadOnlyMemory<char> actualString, StringComparison comparisonType = StringComparison.CurrentCulture)

Parameters

expectedSubstring Memory<char>

The sub-string expected to be in the string

actualString ReadOnlyMemory<char>

The string to be inspected

comparisonType StringComparison

The type of string comparison to perform

Exceptions

Thrown when the sub-string is not present inside the string

Contains(ReadOnlyMemory<char>, Memory<char>, StringComparison)

Verifies that a string contains a given sub-string, using the given comparison type.

public static void Contains(ReadOnlyMemory<char> expectedSubstring, Memory<char> actualString, StringComparison comparisonType = StringComparison.CurrentCulture)

Parameters

expectedSubstring ReadOnlyMemory<char>

The sub-string expected to be in the string

actualString Memory<char>

The string to be inspected

comparisonType StringComparison

The type of string comparison to perform

Exceptions

Thrown when the sub-string is not present inside the string

Contains(ReadOnlyMemory<char>, ReadOnlyMemory<char>, StringComparison)

Verifies that a string contains a given sub-string, using the given comparison type.

public static void Contains(ReadOnlyMemory<char> expectedSubstring, ReadOnlyMemory<char> actualString, StringComparison comparisonType = StringComparison.CurrentCulture)

Parameters

expectedSubstring ReadOnlyMemory<char>

The sub-string expected to be in the string

actualString ReadOnlyMemory<char>

The string to be inspected

comparisonType StringComparison

The type of string comparison to perform

Exceptions

Thrown when the sub-string is not present inside the string

Contains(Span<char>, Span<char>, StringComparison)

Verifies that a string contains a given string, using the given comparison type.

public static void Contains(Span<char> expectedSubstring, Span<char> actualString, StringComparison comparisonType = StringComparison.CurrentCulture)

Parameters

expectedSubstring Span<char>

The string expected to be in the string

actualString Span<char>

The string to be inspected

comparisonType StringComparison

The type of string comparison to perform

Exceptions

Thrown when the string is not present inside the string

Contains(Span<char>, ReadOnlySpan<char>, StringComparison)

Verifies that a string contains a given string, using the given comparison type.

public static void Contains(Span<char> expectedSubstring, ReadOnlySpan<char> actualString, StringComparison comparisonType = StringComparison.CurrentCulture)

Parameters

expectedSubstring Span<char>

The string expected to be in the string

actualString ReadOnlySpan<char>

The string to be inspected

comparisonType StringComparison

The type of string comparison to perform

Exceptions

Thrown when the string is not present inside the string

Contains(ReadOnlySpan<char>, Span<char>, StringComparison)

Verifies that a string contains a given string, using the given comparison type.

public static void Contains(ReadOnlySpan<char> expectedSubstring, Span<char> actualString, StringComparison comparisonType = StringComparison.CurrentCulture)

Parameters

expectedSubstring ReadOnlySpan<char>

The string expected to be in the string

actualString Span<char>

The string to be inspected

comparisonType StringComparison

The type of string comparison to perform

Exceptions

Thrown when the string is not present inside the string

Contains(ReadOnlySpan<char>, ReadOnlySpan<char>, StringComparison)

Verifies that a string contains a given string, using the given comparison type.

public static void Contains(ReadOnlySpan<char> expectedSubstring, ReadOnlySpan<char> actualString, StringComparison comparisonType = StringComparison.CurrentCulture)

Parameters

expectedSubstring ReadOnlySpan<char>

The string expected to be in the string

actualString ReadOnlySpan<char>

The string to be inspected

comparisonType StringComparison

The type of string comparison to perform

Exceptions

Thrown when the string is not present inside the string

Contains(Span<char>, Span<char>)

Verifies that a string contains a given string, using the current culture.

public static void Contains(Span<char> expectedSubstring, Span<char> actualString)

Parameters

expectedSubstring Span<char>

The string expected to be in the string

actualString Span<char>

The string to be inspected

Exceptions

Thrown when the string is not present inside the string

Contains(Span<char>, ReadOnlySpan<char>)

Verifies that a string contains a given string, using the current culture.

public static void Contains(Span<char> expectedSubstring, ReadOnlySpan<char> actualString)

Parameters

expectedSubstring Span<char>

The string expected to be in the string

actualString ReadOnlySpan<char>

The string to be inspected

Exceptions

Thrown when the string is not present inside the string

Contains(ReadOnlySpan<char>, Span<char>)

Verifies that a string contains a given string, using the current culture.

public static void Contains(ReadOnlySpan<char> expectedSubstring, Span<char> actualString)

Parameters

expectedSubstring ReadOnlySpan<char>

The string expected to be in the string

actualString Span<char>

The string to be inspected

Exceptions

Thrown when the string is not present inside the string

Contains(ReadOnlySpan<char>, ReadOnlySpan<char>)

Verifies that a string contains a given string, using the current culture.

public static void Contains(ReadOnlySpan<char> expectedSubstring, ReadOnlySpan<char> actualString)

Parameters

expectedSubstring ReadOnlySpan<char>

The string expected to be in the string

actualString ReadOnlySpan<char>

The string to be inspected

Exceptions

Thrown when the string is not present inside the string