Is(TValue) Method

Moq 2.6

Matches any value that satisfies the given predicate.

Namespace:  Moq
Assembly:  Moq (in Moq.dll) Version: 2.6.1014.1 (2.6.0.0)

Syntax

C#
public static TValue Is<TValue>(
	Expression<Predicate<TValue>> match
)

Parameters

match
Type: Expression<(Of <(Predicate<(Of <(TValue>)>)>)>)
The predicate used to match the method argument.

Type Parameters

TValue
Type of the argument to check.

Remarks

Allows the specification of a predicate to perform matching of method call arguments.

Examples

This example shows how to return the value 1 whenever the argument to the Do method is an even number.
CopyC#
mock.Expect(x => x.Do(It.Is<int>(i => i % 2 == 0)))
    .Returns(1);
This example shows how to throw an exception if the argument to the method is a negative number:
CopyC#
mock.Expect(x => x.GetUser(It.Is<int>(i => i < 0)))
    .Throws(new ArgumentException());

See Also