ExpectationSetup

An ExpectationSetup object allows you to set various properties of the expectation, such as: - what action should be taken when method matching expectation is called - return value, action to call, exception to throw, etc

Members

Functions

action
ExpectationSetup action(T delegate(U) action)

When the method which matches this expectation is called execute the given delegate. The delegate's signature must match the signature of the called method. If it does not, an exception will be thrown. The called method will return whatever the given delegate returns.

customArgsComparator
ExpectationSetup customArgsComparator(bool delegate(Dynamic expected, Dynamic provided) del)

Allow providing custom argument comparator for matching calls to this expectation.

ignoreArgs
ExpectationSetup ignoreArgs()

Ignore method argument values in matching calls to this expectation.

passThrough
ExpectationSetup passThrough()

Instead of returning or throwing a given value, pass the call through to the mocked type object. For mock***PassTo(obj) obj has to be valid for this to work.

repeat
ExpectationSetup repeat(int min, int max)

This expectation must match to at least min number of calls and at most to max number of calls.

repeat
ExpectationSetup repeat(int i)

This expectation will match exactly i times.

repeatAny
ExpectationSetup repeatAny()

This expectation will match to any number of calls.

returns
ExpectationSetup returns(T value)

Set the value to return when method matching this expectation is called on a mock object.

throws
ExpectationSetup throws(Exception e)

When the method which matches this expectation is called, throw the given exception. If there are any actions specified (via the action method), they will not be executed.

Examples

Mocker m = new Mocker;
Object o = m.Mock!(Object);
o.toString;
m.LastCall().returns("Are you still there?").repeat(1, 12);

Meta