Returns(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) Method (Func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult))

Moq

Collapse image Expand Image Copy image CopyHover image
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: 4.0.10827.0 (4.0.0.0)

Syntax

C#
IReturnsResult<TMock> Returns<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
	Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> valueFunction
)

Parameters

valueFunction
Type: System..::..Func<(Of <(<'T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>)>)>
The function that will calculate the return value.

Type Parameters

T1
The type of the first argument of the invoked method.
T2
The type of the second argument of the invoked method.
T3
The type of the third argument of the invoked method.
T4
The type of the fourth argument of the invoked method.
T5
The type of the fifth argument of the invoked method.
T6
The type of the sixth argument of the invoked method.
T7
The type of the seventh argument of the invoked method.
T8
The type of the eighth argument of the invoked method.
T9
The type of the nineth argument of the invoked method.
T10
The type of the tenth argument of the invoked method.

Examples

The return value is calculated from the value of the actual method invocation arguments. Notice how the arguments are retrieved by simply declaring them as part of the lambda expression:

CopyC#
mock.Setup(x => x.Execute(
                     It.IsAny<int>(), 
                     It.IsAny<int>(), 
                     It.IsAny<int>(), 
                     It.IsAny<int>(), 
                     It.IsAny<int>(), 
                     It.IsAny<int>(), 
                     It.IsAny<int>(), 
                     It.IsAny<int>(), 
                     It.IsAny<int>(), 
                     It.IsAny<int>()))
    .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10);

See Also