Table of Contents

Interface ISetup

Namespace
Moq
Assembly
Moq.dll

A setup configured on a mock.

public interface ISetup

Properties

Expression

The setup expression.

LambdaExpression Expression { get; }

Property Value

LambdaExpression
See Also

InnerMock

Gets the inner mock of this setup (if present and known).

An "inner mock" is the Mock instance associated with a setup's return value, if that setup is configured to return a mock object.

This property will be null if a setup either does not return a mock object, or if Moq cannot safely determine its return value without risking any side effects. For instance, Moq is able to inspect the return value if it is a constant (e.g. `.Returns(value)`); if, on the other hand, it gets computed by a factory function (e.g. `.Returns(() => value)`), Moq will not attempt to retrieve that value just to find the inner mock, since calling a user-provided function could have effects beyond Moq's understanding and control.

Mock InnerMock { get; }

Property Value

Mock
See Also

IsConditional

Gets whether this setup is conditional.

bool IsConditional { get; }

Property Value

bool
See Also

IsMatched

Gets whether this setup was matched by at least one invocation on the mock.

bool IsMatched { get; }

Property Value

bool
See Also

IsOverridden

Gets whether this setup has been overridden (that is, whether it is being shadowed by a more recent non-conditional setup with an equal expression).

bool IsOverridden { get; }

Property Value

bool
See Also

IsVerifiable

Gets whether this setup is "verifiable".

bool IsVerifiable { get; }

Property Value

bool

Remarks

This property gets sets by the .Verifiable() setup verb.

Note that setups can be verified even if this property is false: VerifyAll() completely ignores this property. Verify(), however, will only verify setups where this property is true.

See Also

Mock

Returns the Mock instance to which this setup belongs.

Mock Mock { get; }

Property Value

Mock
See Also

OriginalExpression

Returns the original setup expression from which this setup resulted.

For setups doing a simple member access or method invocation (such as `mock => mock.Member`), this property will be equal to Expression.

For setups whose expression involves member chaining (such as `parent => parent.Child.Member`), Moq does not create a single setup, but one for each member access/invocation. The example just given will result in two setups:

  1. a setup for `parent => parent.Child` on the parent mock; and
  2. on its inner mock, a setup for `(child) => (child).Member`.
These are the setups that will be put in the mocks' Setups collections; their Expression will return the partial expression for just a single member access, while their OriginalExpression will return the original, full expression.

This property may also return null if this setup was created automatically, e.g. by SetupAllProperties() or by Mock.

Expression OriginalExpression { get; }

Property Value

Expression
See Also

Methods

Verify(bool)

Verifies this setup and optionally all verifiable setups of its inner mock (if present and known).

If recursive is set to true, the semantics of this method are essentially the same as those of Verify(), except that this setup (instead of a mock) is used as the starting point for verification, and will always be verified itself (even if not flagged as verifiable).

void Verify(bool recursive = true)

Parameters

recursive bool

Specifies whether recursive verification should be performed.

Exceptions

MockException

Verification failed due to one or more unmatched setups.

See Also

VerifyAll()

Verifies this setup and all setups of its inner mock (if present and known), regardless of whether they have been flagged as verifiable.

The semantics of this method are essentially the same as those of VerifyAll(), except that this setup (instead of a mock) is used as the starting point for verification.

void VerifyAll()

Exceptions

MockException

Verification failed due to one or more unmatched setups.

See Also

See Also