Callback(T) Method (Action(T))

Moq

Collapse image Expand Image Copy image CopyHover image
Specifies a callback to invoke when the method is called that receives the original arguments.

Namespace: Moq.Language
Assembly: Moq (in Moq.dll) Version: 4.0.10827.0 (4.0.0.0)

Syntax

C#
ICallbackResult Callback<T>(
	Action<T> action
)

Parameters

action
Type: System..::..Action<(Of <(<'T>)>)>
The callback method to invoke.

Type Parameters

T
The argument type 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.Setup(x => x.Execute(It.IsAny<string>()))
    .Callback((string command) => Console.WriteLine(command));

See Also