Table of Contents

Class LookupOrFallbackDefaultValueProvider

Namespace
Moq
Assembly
Moq.dll

Abstract base class for default value providers that look up and delegate to value factory functions for the requested type(s). If a request cannot be satisfied by any registered factory, the default value gets produced by a fallback strategy.

public abstract class LookupOrFallbackDefaultValueProvider : DefaultValueProvider
Inheritance
LookupOrFallbackDefaultValueProvider
Inherited Members

Remarks

Derived classes can register and deregister factory functions with Register(Type, Func<Type, Mock, object>) and Deregister(Type), respectively.

The fallback value generation strategy is implemented by the overridable GetFallbackDefaultValue(Type, Mock) method.

This base class sets up factory functions for task types (Task, Task<TResult>, and ValueTask<TResult>) that produce completed tasks containing default values. If this behavior is not desired, derived classes may deregister those standard factory functions via Deregister(Type).

Constructors

LookupOrFallbackDefaultValueProvider()

Initializes a new instance of the LookupOrFallbackDefaultValueProvider class.

protected LookupOrFallbackDefaultValueProvider()

Methods

Deregister(Type)

Deregisters any factory function that might currently be registered for the given type(s). Subsequent requests for values of the given type(s) will be handled by the fallback strategy.

protected void Deregister(Type factoryKey)

Parameters

factoryKey Type

The type(s) for which to remove any registered factory function.

GetDefaultParameterValue(ParameterInfo, Mock)

protected override sealed object GetDefaultParameterValue(ParameterInfo parameter, Mock mock)

Parameters

parameter ParameterInfo
mock Mock

Returns

object

GetDefaultReturnValue(MethodInfo, Mock)

protected override sealed object GetDefaultReturnValue(MethodInfo method, Mock mock)

Parameters

method MethodInfo
mock Mock

Returns

object

GetDefaultValue(Type, Mock)

protected override sealed object GetDefaultValue(Type type, Mock mock)

Parameters

type Type
mock Mock

Returns

object

GetFallbackDefaultValue(Type, Mock)

Determines the default value for the given type when no suitable factory is registered for it. May be overridden in derived classes.

protected virtual object GetFallbackDefaultValue(Type type, Mock mock)

Parameters

type Type

The type of which to produce a value.

mock Mock

The Mock on which an unexpected invocation has occurred.

Returns

object

Register(Type, Func<Type, Mock, object>)

Registers a factory function for the given type(s). Subsequent requests for values of the given type(s) will be handled by the specified function.

protected void Register(Type factoryKey, Func<Type, Mock, object> factory)

Parameters

factoryKey Type

The type(s) for which to register the given factory function.

All array types are represented by typeof(Array). Generic types are represented by their open generic type definition, e. g. typeof(IEnumerable<>).

factory Func<Type, Mock, object>

The factory function responsible for producing values for the given type.