Verifies that a property has been set on the mock, regardless of the value but only the specified number of times.

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

Syntax

C#
public static void VerifySet<T, TProperty>(
	Mock<T> mock,
	Expression<Func<T, TProperty>> expression,
	Times times
)
where T : class

Parameters

mock
Type: Moq..::.Mock<(Of <(T>)>)
The mock instance.
expression
Type: Expression<(Of <(Func<(Of <(T, TProperty>)>)>)>)
Expression to verify.
times
Type: Moq..::.Times
The number of times a method is allowed to be called.

Type Parameters

T
Mocked type.
TProperty
Type of the property to verify. Typically omitted as it can be inferred from the expression's return type.

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<IWarehouse>();
// exercise mock
//...
// Will throw if the test code didn't set the IsClosed property.
mock.VerifySet(warehouse => warehouse.IsClosed);

Exceptions

ExceptionCondition
Moq..::.MockExceptionThe invocation was not performed on the mock.
Moq..::.MockExceptionThe invocation was not call the times specified by times.

See Also