Returns Method ((TResult))

Moq 2.6

Specifies a function that will calculate the value to return from the method.

Namespace:  Moq.Language
Assembly:  Moq (in Moq.dll) Version: 2.6.1014.1 (2.6.0.0)

Syntax

C#
IReturnsResult Returns(
	Func<TResult> valueFunction
)

Parameters

valueFunction
Type: Func<(Of <(TResult>)>)
The function that will calculate the return value.

Examples

Return a calculated value when the method is called:
CopyC#
mock.Expect(x => x.Execute("ping"))
    .Returns(() => returnValues[0]);
The lambda expression to retrieve the return value is lazy-executed, meaning that its value may change depending on the moment the method is executed and the value the returnValues array has at that moment.

See Also