Table of Contents

Class DefaultValueProvider

Namespace
Moq
Assembly
Moq.dll

DefaultValueProvider is the abstract base class for default value providers. These are responsible for producing e. g. return values when mock methods or properties get invoked unexpectedly. In other words, whenever there is no setup that would determine the return value for a particular invocation, Moq asks the mock's default value provider to produce a return value.

public abstract class DefaultValueProvider
Inheritance
DefaultValueProvider
Derived
Inherited Members

Constructors

DefaultValueProvider()

Initializes a new instance of the DefaultValueProvider class.

protected DefaultValueProvider()

Properties

Empty

Gets the DefaultValueProvider corresponding to Empty; that is, a default value provider returning "empty" values e. g. for collection types.

public static DefaultValueProvider Empty { get; }

Property Value

DefaultValueProvider

Mock

Gets the DefaultValueProvider corresponding to Mock; that is, a default value provider returning mocked objects or "empty" values for unmockable types.

public static DefaultValueProvider Mock { get; }

Property Value

DefaultValueProvider

Methods

GetDefaultParameterValue(ParameterInfo, Mock)

Produces a default argument value for the specified method parameter. May be overridden in derived classes.

By default, this method will delegate to GetDefaultValue(Type, Mock).

protected virtual object GetDefaultParameterValue(ParameterInfo parameter, Mock mock)

Parameters

parameter ParameterInfo

The ParameterInfo describing the method parameter for which a default argument value should be produced.

mock Mock

The Mock on which an unexpected invocation has occurred.

Returns

object

Remarks

Implementations may assume that all parameters have valid, non-null, non-void values.

GetDefaultReturnValue(MethodInfo, Mock)

Produces a default return value for the specified method. May be overridden in derived classes.

By default, this method will delegate to GetDefaultValue(Type, Mock).

protected virtual object GetDefaultReturnValue(MethodInfo method, Mock mock)

Parameters

method MethodInfo

The MethodInfo describing the method for which a default return value should be produced.

mock Mock

The Mock on which an unexpected invocation has occurred.

Returns

object

Remarks

Implementations may assume that all parameters have valid, non-null, non-void values.

GetDefaultValue(Type, Mock)

Produces a default value of the specified type. Must be overridden in derived classes.

protected abstract object GetDefaultValue(Type type, Mock mock)

Parameters

type Type

The Type of the requested default value.

mock Mock

The Mock on which an unexpected invocation has occurred.

Returns

object

Remarks

Implementations may assume that all parameters have valid, non-null, non-void values.