Callback Method (Action)

Moq

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

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

Syntax

C#
IReturnsThrows<TMock, TResult> Callback(
	Action action
)

Parameters

action
Type: System..::..Action
The callback method to invoke.

Examples

The following example specifies a callback to set a boolean value that can be used later:
CopyC#
var called = false;
mock.Setup(x => x.Execute())
    .Callback(() => called = true)
    .Returns(true);
Note that in the case of value-returning methods, after the Callback call you can still specify the return value.

See Also