Callback(T) Method ((T))

Moq 2.6

Specifies a callback to invoke when the method is called that receives the original arguments.

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

Syntax

C#
IReturnsThrows<TResult> Callback<T>(
	Action<T> callback
)

Parameters

callback
Type: Action<(Of <(T>)>)
Callback method to invoke.

Type Parameters

T
Type of the argument of the invoked method.

Examples

Invokes the given callback with the concrete invocation argument value.

Notice how the specific string argument is retrieved by simply declaring it as part of the lambda expression for the callback:

CopyC#
mock.Expect(x => x.Execute(It.IsAny<string>()))
    .Callback((string command) => Console.WriteLine(command))
    .Returns(true);

See Also