Language

Assert.ContainsSingle Method

Definition

Overloads

Name Description
ContainsSingle(IEnumerable, String, String)

Tests whether the specified collection contains exactly one element.

ContainsSingle(Func<Object,Boolean>, IEnumerable, String, String, String)

Tests whether the specified collection contains exactly one element that matches the given predicate.

ContainsSingle<T>(ReadOnlySpan<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Tests whether the specified span contains exactly one element.

ContainsSingle<T>(Func<T,Boolean>, Span<T>, String, String, String)

Tests whether the specified span contains exactly one element that matches the given predicate.

ContainsSingle<T>(Func<T,Boolean>, ReadOnlySpan<T>, String, String, String)

Tests whether the specified span contains exactly one element that matches the given predicate.

ContainsSingle<T>(Func<T,Boolean>, ReadOnlyMemory<T>, String, String, String)

Tests whether the specified memory contains exactly one element that matches the given predicate.

ContainsSingle<T>(Func<T,Boolean>, Memory<T>, String, String, String)

Tests whether the specified memory contains exactly one element that matches the given predicate.

ContainsSingle<T>(Func<T,Boolean>, IEnumerable<T>, String, String, String)

Tests whether the specified collection contains exactly one element that matches the given predicate.

ContainsSingle<T>(Span<T>, String, String)

Tests whether the specified span contains exactly one element.

ContainsSingle<T>(Span<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Tests whether the specified span contains exactly one element.

ContainsSingle<T>(ReadOnlySpan<T>, String, String)

Tests whether the specified span contains exactly one element.

ContainsSingle<T>(ReadOnlyMemory<T>, String, String)

Tests whether the specified memory contains exactly one element.

ContainsSingle<T>(IEnumerable<T>, String)

Tests whether the specified collection contains exactly one element.

ContainsSingle<T>(Memory<T>, String, String)

Tests whether the specified memory contains exactly one element.

ContainsSingle<T>(IEnumerable<T>, Assert.AssertSingleInterpolatedStringHandler<T>)

Tests whether the specified collection contains exactly one element.

ContainsSingle<T>(ReadOnlyMemory<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Tests whether the specified memory contains exactly one element.

ContainsSingle<T>(IEnumerable<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Tests whether the specified collection contains exactly one element.

ContainsSingle<T>(IEnumerable<T>)

Tests whether the specified collection contains exactly one element.

ContainsSingle<T>(IEnumerable<T>, String, String)

Tests whether the specified collection contains exactly one element.

ContainsSingle<T>(Func<T,Boolean>, IEnumerable<T>, String)

Tests whether the specified collection contains exactly one element that matches the given predicate.

ContainsSingle<T>(Memory<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Tests whether the specified memory contains exactly one element.

ContainsSingle<T>(IEnumerable<T>, String, Object[])

Tests whether the specified collection contains exactly one element.

ContainsSingle(IEnumerable, String, String)

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.ContainsSingle.cs

Tests whether the specified collection contains exactly one element.

public static object? ContainsSingle(System.Collections.IEnumerable collection, string? message = "", string collectionExpression = "");
static member ContainsSingle : System.Collections.IEnumerable * string * string -> obj
Public Shared Function ContainsSingle (collection As IEnumerable, Optional message As String = "", Optional collectionExpression As String = "") As Object

Parameters

collection
IEnumerable

The collection.

message
String

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

The item.

Applies to

ContainsSingle(Func<Object,Boolean>, IEnumerable, String, String, String)

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.ContainsSingle.cs

Tests whether the specified collection contains exactly one element that matches the given predicate.

public static object? ContainsSingle(Func<object?,bool> predicate, System.Collections.IEnumerable collection, string? message = "", string predicateExpression = "", string collectionExpression = "");
static member ContainsSingle : Func<obj, bool> * System.Collections.IEnumerable * string * string * string -> obj
Public Shared Function ContainsSingle (predicate As Func(Of Object, Boolean), collection As IEnumerable, Optional message As String = "", Optional predicateExpression As String = "", Optional collectionExpression As String = "") As Object

Parameters

predicate
Func<Object,Boolean>

A function to test each element for a condition.

collection
IEnumerable

The collection.

message
String

The message to display when the assertion fails.

predicateExpression
String

The syntactic expression of predicate as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

The item that matches the predicate.

Applies to

ContainsSingle<T>(ReadOnlySpan<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Tests whether the specified span contains exactly one element.

public static T ContainsSingle<T>(ReadOnlySpan<T> collection, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertSingleInterpolatedStringHandler<T> message, string collectionExpression = "");
static member ContainsSingle : ReadOnlySpan<'T> * AssertSingleInterpolatedStringHandler * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As ReadOnlySpan(Of T), ByRef message As Assert.AssertSingleInterpolatedStringHandler(Of T), Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the span items.

Parameters

collection
ReadOnlySpan<T>

The span.

message
Assert.AssertSingleInterpolatedStringHandler<T>

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(Func<T,Boolean>, Span<T>, String, String, String)

Tests whether the specified span contains exactly one element that matches the given predicate.

public static T ContainsSingle<T>(Func<T,bool> predicate, Span<T> collection, string? message = "", string predicateExpression = "", string collectionExpression = "");
static member ContainsSingle : Func<'T, bool> * Span<'T> * string * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (predicate As Func(Of T, Boolean), collection As Span(Of T), Optional message As String = "", Optional predicateExpression As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the span items.

Parameters

predicate
Func<T,Boolean>

A function to test each element for a condition.

collection
Span<T>

The span.

message
String

The message to display when the assertion fails.

predicateExpression
String

The syntactic expression of predicate as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item that matches the predicate.

Applies to

ContainsSingle<T>(Func<T,Boolean>, ReadOnlySpan<T>, String, String, String)

Tests whether the specified span contains exactly one element that matches the given predicate.

public static T ContainsSingle<T>(Func<T,bool> predicate, ReadOnlySpan<T> collection, string? message = "", string predicateExpression = "", string collectionExpression = "");
static member ContainsSingle : Func<'T, bool> * ReadOnlySpan<'T> * string * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (predicate As Func(Of T, Boolean), collection As ReadOnlySpan(Of T), Optional message As String = "", Optional predicateExpression As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the span items.

Parameters

predicate
Func<T,Boolean>

A function to test each element for a condition.

collection
ReadOnlySpan<T>

The span.

message
String

The message to display when the assertion fails.

predicateExpression
String

The syntactic expression of predicate as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item that matches the predicate.

Applies to

ContainsSingle<T>(Func<T,Boolean>, ReadOnlyMemory<T>, String, String, String)

Tests whether the specified memory contains exactly one element that matches the given predicate.

public static T ContainsSingle<T>(Func<T,bool> predicate, ReadOnlyMemory<T> collection, string? message = "", string predicateExpression = "", string collectionExpression = "");
static member ContainsSingle : Func<'T, bool> * ReadOnlyMemory<'T> * string * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (predicate As Func(Of T, Boolean), collection As ReadOnlyMemory(Of T), Optional message As String = "", Optional predicateExpression As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the memory items.

Parameters

predicate
Func<T,Boolean>

A function to test each element for a condition.

collection
ReadOnlyMemory<T>

The memory.

message
String

The message to display when the assertion fails.

predicateExpression
String

The syntactic expression of predicate as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item that matches the predicate.

Applies to

ContainsSingle<T>(Func<T,Boolean>, Memory<T>, String, String, String)

Tests whether the specified memory contains exactly one element that matches the given predicate.

public static T ContainsSingle<T>(Func<T,bool> predicate, Memory<T> collection, string? message = "", string predicateExpression = "", string collectionExpression = "");
static member ContainsSingle : Func<'T, bool> * Memory<'T> * string * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (predicate As Func(Of T, Boolean), collection As Memory(Of T), Optional message As String = "", Optional predicateExpression As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the memory items.

Parameters

predicate
Func<T,Boolean>

A function to test each element for a condition.

collection
Memory<T>

The memory.

message
String

The message to display when the assertion fails.

predicateExpression
String

The syntactic expression of predicate as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item that matches the predicate.

Applies to

ContainsSingle<T>(Func<T,Boolean>, IEnumerable<T>, String, String, String)

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.ContainsSingle.cs

Tests whether the specified collection contains exactly one element that matches the given predicate.

public static T ContainsSingle<T>(Func<T,bool> predicate, System.Collections.Generic.IEnumerable<T> collection, string? message = "", string predicateExpression = "", string collectionExpression = "");
static member ContainsSingle : Func<'T, bool> * seq<'T> * string * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (predicate As Func(Of T, Boolean), collection As IEnumerable(Of T), Optional message As String = "", Optional predicateExpression As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the collection items.

Parameters

predicate
Func<T,Boolean>

A function to test each element for a condition.

collection
IEnumerable<T>

The collection.

message
String

The message to display when the assertion fails.

predicateExpression
String

The syntactic expression of predicate as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item that matches the predicate.

Applies to

ContainsSingle<T>(Span<T>, String, String)

Tests whether the specified span contains exactly one element.

public static T ContainsSingle<T>(Span<T> collection, string? message = "", string collectionExpression = "");
static member ContainsSingle : Span<'T> * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As Span(Of T), Optional message As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the span items.

Parameters

collection
Span<T>

The span.

message
String

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(Span<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Tests whether the specified span contains exactly one element.

public static T ContainsSingle<T>(Span<T> collection, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertSingleInterpolatedStringHandler<T> message, string collectionExpression = "");
static member ContainsSingle : Span<'T> * AssertSingleInterpolatedStringHandler * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As Span(Of T), ByRef message As Assert.AssertSingleInterpolatedStringHandler(Of T), Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the span items.

Parameters

collection
Span<T>

The span.

message
Assert.AssertSingleInterpolatedStringHandler<T>

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(ReadOnlySpan<T>, String, String)

Tests whether the specified span contains exactly one element.

public static T ContainsSingle<T>(ReadOnlySpan<T> collection, string? message = "", string collectionExpression = "");
static member ContainsSingle : ReadOnlySpan<'T> * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As ReadOnlySpan(Of T), Optional message As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the span items.

Parameters

collection
ReadOnlySpan<T>

The span.

message
String

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(ReadOnlyMemory<T>, String, String)

Tests whether the specified memory contains exactly one element.

public static T ContainsSingle<T>(ReadOnlyMemory<T> collection, string? message = "", string collectionExpression = "");
static member ContainsSingle : ReadOnlyMemory<'T> * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As ReadOnlyMemory(Of T), Optional message As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the memory items.

Parameters

collection
ReadOnlyMemory<T>

The memory.

message
String

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(IEnumerable<T>, String)

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs

Tests whether the specified collection contains exactly one element.

public static T ContainsSingle<T>(System.Collections.Generic.IEnumerable<T> collection, string? message);
static member ContainsSingle : seq<'T> * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As IEnumerable(Of T), message As String) As T

Type Parameters

T

The type of the collection items.

Parameters

collection
IEnumerable<T>

The collection.

message
String

The message to display when the assertion fails.

Returns

T

The item.

Applies to

ContainsSingle<T>(Memory<T>, String, String)

Tests whether the specified memory contains exactly one element.

public static T ContainsSingle<T>(Memory<T> collection, string? message = "", string collectionExpression = "");
static member ContainsSingle : Memory<'T> * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As Memory(Of T), Optional message As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the memory items.

Parameters

collection
Memory<T>

The memory.

message
String

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(IEnumerable<T>, Assert.AssertSingleInterpolatedStringHandler<T>)

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs

Tests whether the specified collection contains exactly one element.

public static T ContainsSingle<T>(System.Collections.Generic.IEnumerable<T> collection, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertSingleInterpolatedStringHandler<T> message);
static member ContainsSingle : seq<'T> * AssertSingleInterpolatedStringHandler -> 'T
Public Shared Function ContainsSingle(Of T) (collection As IEnumerable(Of T), ByRef message As Assert.AssertSingleInterpolatedStringHandler(Of T)) As T

Type Parameters

T

The type of the collection items.

Parameters

collection
IEnumerable<T>

The collection.

message
Assert.AssertSingleInterpolatedStringHandler<T>

The message to display when the assertion fails.

Returns

T

The item.

Applies to

ContainsSingle<T>(ReadOnlyMemory<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Tests whether the specified memory contains exactly one element.

public static T ContainsSingle<T>(ReadOnlyMemory<T> collection, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertSingleInterpolatedStringHandler<T> message, string collectionExpression = "");
static member ContainsSingle : ReadOnlyMemory<'T> * AssertSingleInterpolatedStringHandler * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As ReadOnlyMemory(Of T), ByRef message As Assert.AssertSingleInterpolatedStringHandler(Of T), Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the memory items.

Parameters

collection
ReadOnlyMemory<T>

The memory.

message
Assert.AssertSingleInterpolatedStringHandler<T>

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(IEnumerable<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.ContainsSingle.cs

Tests whether the specified collection contains exactly one element.

public static T ContainsSingle<T>(System.Collections.Generic.IEnumerable<T> collection, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertSingleInterpolatedStringHandler<T> message, string collectionExpression = "");
static member ContainsSingle : seq<'T> * AssertSingleInterpolatedStringHandler * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As IEnumerable(Of T), ByRef message As Assert.AssertSingleInterpolatedStringHandler(Of T), Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the collection items.

Parameters

collection
IEnumerable<T>

The collection.

message
Assert.AssertSingleInterpolatedStringHandler<T>

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(IEnumerable<T>)

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs

Tests whether the specified collection contains exactly one element.

public static T ContainsSingle<T>(System.Collections.Generic.IEnumerable<T> collection);
static member ContainsSingle : seq<'T> -> 'T
Public Shared Function ContainsSingle(Of T) (collection As IEnumerable(Of T)) As T

Type Parameters

T

The type of the collection items.

Parameters

collection
IEnumerable<T>

The collection.

Returns

T

The item.

Applies to

ContainsSingle<T>(IEnumerable<T>, String, String)

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.ContainsSingle.cs

Tests whether the specified collection contains exactly one element.

public static T ContainsSingle<T>(System.Collections.Generic.IEnumerable<T> collection, string? message = "", string collectionExpression = "");
static member ContainsSingle : seq<'T> * string * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As IEnumerable(Of T), Optional message As String = "", Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the collection items.

Parameters

collection
IEnumerable<T>

The collection.

message
String

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(Func<T,Boolean>, IEnumerable<T>, String)

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs

Tests whether the specified collection contains exactly one element that matches the given predicate.

public static T ContainsSingle<T>(Func<T,bool> predicate, System.Collections.Generic.IEnumerable<T> collection, string message = "");
static member ContainsSingle : Func<'T, bool> * seq<'T> * string -> 'T
Public Shared Function ContainsSingle(Of T) (predicate As Func(Of T, Boolean), collection As IEnumerable(Of T), Optional message As String = "") As T

Type Parameters

T

The type of the collection items.

Parameters

predicate
Func<T,Boolean>

A function to test each element for a condition.

collection
IEnumerable<T>

The collection.

message
String

The message format to display when the assertion fails.

Returns

T

The item that matches the predicate.

Applies to

ContainsSingle<T>(Memory<T>, Assert.AssertSingleInterpolatedStringHandler<T>, String)

Tests whether the specified memory contains exactly one element.

public static T ContainsSingle<T>(Memory<T> collection, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertSingleInterpolatedStringHandler<T> message, string collectionExpression = "");
static member ContainsSingle : Memory<'T> * AssertSingleInterpolatedStringHandler * string -> 'T
Public Shared Function ContainsSingle(Of T) (collection As Memory(Of T), ByRef message As Assert.AssertSingleInterpolatedStringHandler(Of T), Optional collectionExpression As String = "") As T

Type Parameters

T

The type of the memory items.

Parameters

collection
Memory<T>

The memory.

message
Assert.AssertSingleInterpolatedStringHandler<T>

The message to display when the assertion fails.

collectionExpression
String

The syntactic expression of collection as given by the compiler via caller argument expression. Users shouldn't pass a value for this parameter.

Returns

T

The item.

Applies to

ContainsSingle<T>(IEnumerable<T>, String, Object[])

Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs
Source:
Assert.Contains.cs

Tests whether the specified collection contains exactly one element.

public static T ContainsSingle<T>(System.Collections.Generic.IEnumerable<T> collection, string? message, params object?[]? parameters);
static member ContainsSingle : seq<'T> * string * obj[] -> 'T
Public Shared Function ContainsSingle(Of T) (collection As IEnumerable(Of T), message As String, ParamArray parameters As Object()) As T

Type Parameters

T

The type of the collection items.

Parameters

collection
IEnumerable<T>

The collection.

message
String

The message format to display when the assertion fails.

parameters
Object[]

The parameters to format the message.

Returns

T

The item.

Applies to