







![]() |
Moq |
IReturns<(Of <(TResult>)>)..::.Returns<(Of <(T>)>) Method (<(Of <(T, TResult>)>)) |
IReturns<(Of <(TResult>)>) Interface Example See Also Send Feedback |
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
Namespace:
Moq.Language
Assembly:
Moq (in Moq.dll) Version: 2.6.1014.1 (2.6.0.0)
Syntax
C# |
---|
IReturnsResult Returns<T>( Func<T, TResult> valueFunction ) |
Parameters
- valueFunction
- Type: Func<(Of <(T, TResult>)>)
The function that will calculate the return value.
Type Parameters
- T
- Type of the argument of the invoked method.
Examples
Return a calculated value which is evaluated lazily at the time of the invocation.
CopyC#
The lookup list can change between invocations and the expectation will return different values accordingly. Also, notice how the specific string argument is retrieved by simply declaring it as part of the lambda expression:

mock.Expect(x => x.Execute(It.IsAny<string>())) .Returns((string command) => returnValues[command]);