VerifySet Method (Action(T), String)

Moq

Collapse image Expand Image Copy image CopyHover image
Verifies that a property was set on the mock, specifying a failure message.

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

Syntax

C#
public void VerifySet(
	Action<T> setterExpression,
	string failMessage
)

Parameters

setterExpression
Type: System..::..Action<(Of <(<'T>)>)>
Expression to verify.
failMessage
Type: System..::..String
Message to show if verification fails.

Examples

This example assumes that the mock has been used, and later we want to verify that a given property was set on it:
CopyC#
var mock = new Mock<IWarehouse>();
// exercise mock
//...
// Will throw if the test code didn't set the IsClosed property.
mock.VerifySet(warehouse => warehouse.IsClosed = true, "Warehouse should always be closed after the action");

Exceptions

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

See Also