Returns Method ((TProperty))

Moq 2.6

Specifies a function that will calculate the value to return for the property.

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

Syntax

C#
IReturnsResult Returns(
	Func<TProperty> valueFunction
)

Parameters

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

Examples

Return a calculated value when the property is retrieved:
CopyC#
mock.ExpectGet(x => x.Suspended)
    .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 property is retrieved and the value the returnValues array has at that moment.

See Also