Table of Contents

Namespace Moq

Classes

Capture

Allows to create parameter captures in setup expressions.

CaptureMatch<T>

Allows creation custom matchers that can be used on setups to capture parameter values.

DefaultValueProvider

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.

ExpressionCompiler

An ExpressionCompiler compiles LINQ expression trees (Expression) to delegates. Whenever Moq needs to compile an expression tree, it uses the instance set up by Instance.

It

Allows the specification of a matching condition for an argument in a method invocation, rather than a specific argument value. "It" refers to the argument being matched.

It.IsAnyType

A type matcher that matches any generic type argument.

If the generic type parameter is constrained to struct (C#) / Structure (VB.NET), use It.IsValueType instead.

If the generic type parameter has more specific constraints, you can define your own type matcher inheriting from the type to which the type parameter is constrained. See TypeMatcherAttribute and ITypeMatcher.

It.IsSubtype<T>

A type matcher that matches subtypes of T, as well as T itself.

It.Ref<TValue>

Contains matchers for ref (C#) / ByRef (VB.NET) parameters of type TValue.

LookupOrFallbackDefaultValueProvider

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.

Match

Allows creating custom value matchers that can be used on setups and verification, completely replacing the built-in It class with your own argument matching rules.

Match<T>

Allows creating custom value matchers that can be used on setups and verification, completely replacing the built-in It class with your own argument matching rules.

Mock

Base class for mocks and static helper class with methods that apply to mocked objects, such as Get<T>(T) to retrieve a Mock<T> from an object instance.

MockException

Exception thrown by mocks when they are not properly set up, when setups are not matched, when verification fails, etc.

MockRepository

Utility repository class to use to construct multiple mocks when consistent verification is desired for all of them.

MockSequence

Helper class to setup a full trace between many mocks

Mock<T>

Provides a mock implementation of T.

Mocks

Allows querying the universe of mocks for those that behave according to the LINQ query specification.

TypeMatcherAttribute

Marks a type as a type matcher, optionally specifying another ITypeMatcher type that will perform the matching.

Type matchers preferably implement ITypeMatcher themselves. Use the parameterized form of this attribute where this is not possible, such as when the type matcher needs to be a delegate or enum type in order to satisfy generic type constraints of the method where it is used.

Structs

InvocationAction

A delegate-like type for use with setup.Callback which instructs the Callback verb to provide the callback with the current IInvocation, instead of with a list of arguments.

This type is useful in scenarios involving generic type argument matchers (such as It.IsAnyType) as IInvocation allows the discovery of both arguments and type arguments.

InvocationFunc

A delegate-like type for use with setup.Returns which instructs the Returns verb to provide the callback with the current IInvocation, instead of with a list of arguments.

This type is useful in scenarios involving generic type argument matchers (such as It.IsAnyType) as IInvocation allows the discovery of both arguments and type arguments.

It.IsValueType

A type matcher that matches any value type.

Times

Defines the number of invocations allowed by a mocked method.

Interfaces

IInvocation

Provides information about an invocation of a mock object.

IInvocationList

A list of invocations which have been performed on a mock.

IMock<T>

Covariant interface for Mock<T> such that casts between IMock<Employee> to IMock<Person> are possible. Only covers the covariant members of Mock<T>.

ISetup

A setup configured on a mock.

ISetupList

A list of setups that have been configured on a mock, in chronological order (that is, oldest setup first, most recent setup last).

ITypeMatcher

Types that implement this interface represent a criterion against which generic type arguments are matched.

To be used in combination with TypeMatcherAttribute.

Enums

DefaultValue

Determines the way default values are generated calculated for loose mocks.

MockBehavior

Options to customize the behavior of the mock.

Range

Kind of range to use in a filter specified through IsInRange<TValue>(TValue, TValue, Range).

Switches

Represents a switch, or a combination of switches, that can be either enabled or disabled. When set via Switches or Switches, they determine how a mock will operate.