Verify Method (Expression(Action(T)))

Moq

Collapse image Expand Image Copy image CopyHover image
Verifies that a specific invocation matching the given expression was performed on the mock. Use in conjuntion with the default Loose.

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

Syntax

C#
public void Verify(
	Expression<Action<T>> expression
)

Parameters

expression
Type: System.Linq.Expressions..::..Expression<(Of <(<'Action<(Of <(<'T>)>)>>)>)>
Expression to verify.

Examples

This example assumes that the mock has been used, and later we want to verify that a given invocation with specific parameters was performed:
CopyC#
var mock = new Mock<IProcessor>();
// exercise mock
//...
// Will throw if the test code didn't call Execute with a "ping" string argument.
mock.Verify(proc => proc.Execute("ping"));

Exceptions

Exception Condition
Moq..::..MockException The invocation was not performed on the mock.

See Also