Moq
is a kind of that works by
applying a delegate to a light-weight proxy that records the invocation
happening to it, and auto-generates the same kind of recording proxy for its return value.
That way, a chain of invocation records is generated from which a LINQ expression tree can be
reconstructed.
Recursively gets the result of (i.e. "unwraps") completed awaitables
until a value is found that isn't a successfully completed awaitable.
As an example, given := Task.FromResult(Task.FromResult(42)),
this method will return 42.
The (possibly awaitable) object to be "unwrapped".
Abstract base class that facilitates type-safe implementation of
for awaitables that do not produce a result when awaited.
Abstract base class that facilitates type-safe implementation of
for awaitables that produce a result when awaited.
Allows to create parameter captures in setup expressions.
Creates a parameter capture that will store values in a collection.
The captured object type
The collection that will store captured parameter values
Arrange code:
var parameters = new List{string}();
mock.Setup(x => x.DoSomething(Capture.In(parameters)));
Assert code:
Assert.Equal("Hello!", parameters.Single());
Creates a parameter capture that will store specific values in a collection.
The captured object type
The collection that will store captured parameter values
A predicate used to filter captured parameters
Arrange code:
var parameters = new List{string}();
mock.Setup(x => x.DoSomething(Capture.In(parameters, p => p.StartsWith("W"))));
Assert code:
Assert.Equal("Hello!", parameters.Single());
Creates a parameter capture using specified .
The captured object type
Arrange code:
var capturedValue = string.Empty;
var match = new CaptureMatch{string}(x => capturedValue = x);
mock.Setup(x => x.DoSomething(Capture.With(match)));
Assert code:
Assert.Equal("Hello!", capturedValue);
Allows creation custom matchers that can be used on setups to capture parameter values.
Initializes an instance of the capture match.
An action to run on captured value
Initializes an instance of the capture match.
An action to run on captured value
A predicate used to filter captured parameters
Determines the way default values are generated
calculated for loose mocks.
Default behavior, which generates empty values for
value types (i.e. default(int)), empty array and
enumerables, and nulls for all other reference types.
Whenever the default value generated by
is null, replaces this value with a mock (if the type
can be mocked).
For sealed classes, a null value will be generated.
All default value generation strategies other than or
are represented by this enumeration value.
Do not set (nor ) to this value.
If you want to set up a custom default value generation strategy, set
or instead.
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.
Gets the corresponding to ;
that is, a default value provider returning "empty" values e. g. for collection types.
Gets the corresponding to ;
that is, a default value provider returning mocked objects or "empty" values for unmockable types.
Initializes a new instance of the class.
Gets the enumeration value that corresponds to this default value provider.
Must be overridden by Moq's internal providers that have their own corresponding .
Produces a default value of the specified type.
Must be overridden in derived classes.
The of the requested default value.
The on which an unexpected invocation has occurred.
Implementations may assume that all parameters have valid, non-, non- values.
Produces a default argument value for the specified method parameter.
May be overridden in derived classes.
By default, this method will delegate to .
The describing the method parameter for which a default argument value should be produced.
The on which an unexpected invocation has occurred.
Implementations may assume that all parameters have valid, non-, non- values.
Produces a default return value for the specified method.
May be overridden in derived classes.
By default, this method will delegate to .
The describing the method for which a default return value should be produced.
The on which an unexpected invocation has occurred.
Implementations may assume that all parameters have valid, non-, non- values.
A that returns an empty default value
for invocations that do not have setups or return values, with loose mocks.
This is the default behavior for a mock.
Provides partial evaluation of subtrees, whenever they can be evaluated locally.
Matt Warren: http://blogs.msdn.com/mattwar
Documented by InSTEDD: http://www.instedd.org
Performs evaluation and replacement of independent sub-trees
The root of the expression tree.
A function that decides whether a given expression
node can be part of the local function.
A new tree with sub-trees evaluated and replaced.
Performs evaluation and replacement of independent sub-trees
The root of the expression tree.
A new tree with sub-trees evaluated and replaced.
Evaluates and replaces sub-trees when first candidate is reached (top-down)
Performs bottom-up analysis to determine which nodes can possibly
be part of an evaluated sub-tree.
Represents a set (or the "shape") of invocations
against which concrete s can be matched.
An compiles LINQ expression trees () to delegates.
Whenever Moq needs to compile an expression tree, it uses the instance set up by .
The default instance, which simply delegates to the framework's .
Gets or sets the instance that Moq uses to compile (LINQ expression trees).
Defaults to .
Initializes a new instance of the class.
Compiles the specified LINQ expression tree.
The LINQ expression tree that should be compiled.
Compiles the specified LINQ expression tree.
The type of delegate to which the expression will be compiled.
The LINQ expression tree that should be compiled.
Wraps this in a node if needed.
The which should be wrapped.
The with which to make the compatible.
LINQ expression trees generally enforce type compatibility rules that are stricter than
the assignment-compatibility used by e.g. . For
example, while is assignable-to , you
will need a conversion in a LINQ expression tree to model the value-type boxing operation.
Checks whether the given expression can be split by .
Splits an expression such as `m => m.A.B(x).C[y] = z` into a chain of parts
that can be set up one at a time:
- `m => m.A`
,
- `... => ....B(x)`
,
- `... => ....C`
,
- `... => ...[y] = z`
.
The split points are chosen such that each part has exactly one associated
and optionally some argument expressions.
It was not possible to completely split up the expression.
Converts the body of the lambda expression into the referenced by it.
Checks whether the body of the lambda expression is a property access.
Checks whether the body of the lambda expression is a indexer access.
TODO: remove this code when https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=331583
is fixed.
Applies the specified to this expression tree.
The to which should be applied.
The that should be applied to .
A reconstructs LINQ expression trees ()
from delegates. It is the counterpart to .
Reconstructs a from the given delegate.
The delegate for which to reconstruct a LINQ expression tree.
Arguments to pass to a parameterized constructor of . (Optional.)
Extracts the arguments from a lambda expression that calls a constructor.
The constructor expression.
Extracted argument values.
Evaluates variables that have been closed over by a lambda function.
Replaces nodes for property or indexer accessor methods
with equivalent nodes.
-
In the case of getter accessors such as `x.get_Property()`, the result will be
a single node: `x.Property`.
-
In the case of setter accessors such as `x.set_Property(y)`, the result will be
a combination of and :
`x.Property = y`.
Gets the default value for the specified type. This is the Reflection counterpart of C#'s operator.
Gets the least-derived in the given type that provides
the implementation for the given .
Gets whether the given is a delegate type.
Visits all constituent parts of , replacing all type matchers
that match the type argument at the corresponding position in .
The type to be matched. May be, or contain, type matchers.
The type argument to match against .
Ensures the given is not null.
Throws otherwise.
Ensures the given string is not null or empty.
Throws in the first case, or
in the latter.
Provides information about an invocation of a mock object.
Gets the method of the invocation.
Gets the arguments of the invocation.
Gets the setup that matched this invocation (or if there was no matching setup).
Gets whether this invocation was successfully verified by any of the various `Verify` methods.
The value being returned for a non-void method if no exception was thrown.
Optional exception if the method invocation results in an exception being thrown.
A list of invocations which have been performed on a mock.
Resets all invocations recorded for this mock.
Covariant interface for such that casts between IMock<Employee> to IMock<Person>
are possible. Only covers the covariant members of .
Exposes the mocked object instance.
Behavior of the mock, according to the value set in the constructor.
Whether the base member virtual implementation will be called for mocked classes if no setup is matched.
Defaults to .
Specifies the behavior to use when returning default values for unexpected invocations on loose mocks.
Implemented by all generated mock object instances.
Reference the Mock that contains this as the mock.Object value.
Implemented by all generated mock object instances.
Reference the Mock that contains this as the mock.Object value.
An implementation of that is based on Castle DynamicProxy.
This hook tells Castle DynamicProxy to proxy the default methods it suggests,
plus some of the methods defined by , e.g. so we can intercept
and give mocks useful default names.
This role interface represents a 's ability to intercept method invocations for its .
It is meant for use by .
Do not use. (Moq requires this class so that methods can be set up on interface mocks.)
Do not use. (Moq requires this interface so that methods can be set up on interface mocks.)
Base class for mocks and static helper class with methods that apply to mocked objects,
such as to retrieve a from an object instance.
Creates a mock object of the indicated type.
The type of the mocked object.
The mocked object created.
Creates a mock object of the indicated type.
Behavior of the mock.
The type of the mocked object.
The mocked object created.
Creates a mock object of the indicated type.
The predicate with the specification of how the mocked object should behave.
The type of the mocked object.
The mocked object created.
Creates a mock object of the indicated type.
The predicate with the specification of how the mocked object should behave.
Behavior of the mock.
The type of the mocked object.
The mocked object created.
Initializes a new instance of the class.
Retrieves the mock object for the given object instance.
The instance of the mocked object.
Type of the mock to retrieve.
Can be omitted as it's inferred from the object instance passed in as the instance.
The mock associated with the mocked object.
The received instance was not created by Moq.
The following example shows how to add a new setup to an object instance
which is not the original but rather the object associated with it:
// Typed instance, not the mock, is retrieved from some test API.
HttpContextBase context = GetMockContext();
// context.Request is the typed object from the "real" API
// so in order to add a setup to it, we need to get
// the mock that "owns" it
Mock<HttpRequestBase> request = Mock.Get(context.Request);
request.Setup(req => req.AppRelativeCurrentExecutionFilePath)
.Returns(tempUrl);
Verifies that all verifiable expectations have been met.
Not all verifiable expectations were met.
Verifies all expectations regardless of whether they have been flagged as verifiable.
At least one expectation was not met.
Gets the interfaces additionally implemented by the mock object.
This list may be modified by calls to up until the first call to .
Behavior of the mock, according to the value set in the constructor.
Whether the base member virtual implementation will be called for mocked classes if no setup is matched.
Defaults to .
Specifies the behavior to use when returning default values for unexpected invocations on loose mocks.
Gets the mocked object instance.
Gets the interfaces directly inherited from the mocked type ().
Gets list of invocations which have been performed on this mock.
Returns the mocked object value.
Retrieves the type of the mocked object, its generic type argument.
This is used in the auto-mocking of hierarchy access.
Gets or sets the instance that will be used
e. g. to produce default return values for unexpected invocations.
Gets the setups that have been configured on this mock,
in chronological order (that is, oldest setup first, most recent setup last).
A set of switches that influence how this mock will operate.
You can opt in or out of certain features via this property.
Verifies that all verifiable expectations have been met.
Not all verifiable expectations were met.
This example sets up an expectation and marks it as verifiable.
After the mock is used, a Verify() call is issued on the mock
to ensure the method in the setup was invoked:
var mock = new Mock<IWarehouse>();
this.Setup(x => x.HasInventory(TALISKER, 50))
.Returns(true)
.Verifiable();
...
// Will throw if the test code did not call HasInventory.
this.Verify();
Verifies all expectations regardless of whether they have been flagged as verifiable.
At least one expectation was not met.
This example sets up an expectation without marking it as verifiable.
After the mock is used, a call is issued on the mock
to ensure that all expectations are met:
var mock = new Mock<IWarehouse>();
this.Setup(x => x.HasInventory(TALISKER, 50))
.Returns(true);
...
// Will throw if the test code did not call HasInventory,
// even though that expectation was not marked as verifiable.
mock.VerifyAll();
Adds an interface implementation to the mock, allowing setups to be specified for it.
This method can only be called before the first use of the mock property,
at which point the runtime type has already been generated and no more interfaces can be added to it.
Also, must be an interface and not a class,
which must be specified when creating the mock instead.
Type of interface to cast the mock to.
The specified is not an interface.
The mock type has already been generated by accessing the property.
Defines the default return value for all mocked methods or properties with return type .
The return type for which to define a default value.
The default return value.
Default return value is respected only when there is no matching setup for a method call.
Gets the global instance used by Moq.
Initializes a new instance of the class.
The of the concrete proxy object on which a method is being invoked.
The method being invoked.
The arguments with which the specified is being invoked.
Gets the method of the invocation.
Gets the arguments of the invocation.
Arguments may be modified. Derived classes must ensure that by-reference parameters are written back
when the invocation is ended by a call to any of the three Returns methods.
Calls the method implementation
and returns its return value (or for methods).
Internal type to mark invocation results as "exception occurred during execution". The type just
wraps the Exception so a thrown exception can be distinguished from an
return value.
A delegate-like type for use with `setup.Callback` which instructs the `Callback` verb
to provide the callback with the current , instead of
with a list of arguments.
This type is useful in scenarios involving generic type argument matchers (such as
) as allows the discovery of both
arguments and type arguments.
Initializes a new instance of the type.
The delegate that should be wrapped by this instance.
A delegate-like type for use with `setup.Returns` which instructs the `Returns` verb
to provide the callback with the current , instead of
with a list of arguments.
This type is useful in scenarios involving generic type argument matchers (such as
) as allows the discovery of both
arguments and type arguments.
Initializes a new instance of the type.
The delegate that should be wrapped by this instance.
A setup configured on a mock.
The setup expression.
Gets the inner mock of this setup (if present and known).
An "inner mock" is the instance associated with a setup's return value,
if that setup is configured to return a mock object.
This property will be if a setup either does not return a mock object,
or if Moq cannot safely determine its return value without risking any side effects. For instance,
Moq is able to inspect the return value if it is a constant (e.g. `.Returns(value)`);
if, on the other hand, it gets computed by a factory function (e.g. `.Returns(() => value)`),
Moq will not attempt to retrieve that value just to find the inner mock,
since calling a user-provided function could have effects beyond Moq's understanding and control.
Gets whether this setup is conditional.
Gets whether this setup was matched by at least one invocation on the mock.
Gets whether this setup has been overridden
(that is, whether it is being shadowed by a more recent non-conditional setup with an equal expression).
Gets whether this setup is "verifiable".
This property gets sets by the `.Verifiable()` setup verb.
Note that setups can be verified even if this property is :
completely ignores this property.
, however, will only verify setups where this property is .
Returns the instance to which this setup belongs.
Returns the original setup expression from which this setup resulted.
For setups doing a simple member access or method invocation (such as `mock => mock.Member`),
this property will be equal to .
For setups whose expression involves member chaining (such as `parent => parent.Child.Member`),
Moq does not create a single setup, but one for each member access/invocation.
The example just given will result in two setups:
- a setup for `parent => parent.Child` on the parent mock; and
- on its inner mock, a setup for `(child) => (child).Member`.
These are the setups that will be put in the mocks' collections;
their will return the partial expression for just a single member access,
while their will return the original, full expression.
This property may also return if this setup was created automatically,
e.g. by or by .
Verifies this setup and optionally all verifiable setups of its inner mock (if present and known).
If is set to ,
the semantics of this method are essentially the same as those of ,
except that this setup (instead of a mock) is used as the starting point for verification,
and will always be verified itself (even if not flagged as verifiable).
Specifies whether recursive verification should be performed.
Verification failed due to one or more unmatched setups.
Verifies this setup and all setups of its inner mock (if present and known),
regardless of whether they have been flagged as verifiable.
The semantics of this method are essentially the same as those of ,
except that this setup (instead of a mock) is used as the starting point for verification.
Verification failed due to one or more unmatched setups.
A list of setups that have been configured on a mock,
in chronological order (that is, oldest setup first, most recent setup last).
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.
This class allows the setup to match a method invocation with an arbitrary value,
with a value in a specified range, or even one that matches a given predicate.
Contains matchers for (C#) / (VB.NET) parameters of type .
The parameter type.
Matches any value that is assignment-compatible with type .
Matches any value of the given type.
Type of the value.
Typically used when the actual argument value for a method call is not relevant.
// Throws an exception for a call to Remove with any string value.
mock.Setup(x => x.Remove(It.IsAny<string>())).Throws(new InvalidOperationException());
A type matcher that matches any generic type argument.
If the generic type parameter is constrained to (C#) /
(VB.NET), use 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 and .
Matches any value of the given type, except null.
Type of the value.
Matches any value that satisfies the given predicate.
The predicate used to match the method argument.
Type of the argument to check.
Allows the specification of a predicate to perform matching of method call arguments.
This example shows how to return the value 1 whenever the argument to
the Do method is an even number.
mock.Setup(x => x.Do(It.Is<int>(i => i % 2 == 0)))
.Returns(1);
This example shows how to throw an exception if the argument to the method
is a negative number:
mock.Setup(x => x.GetUser(It.Is<int>(i => i < 0)))
.Throws(new ArgumentException());
Matches any value that satisfies the given predicate.
Use this overload when you specify a type matcher for .
The callback you provide will then receive the actual parameter type
as well as the invocation argument.
The predicate used to match the method argument.
Type of the argument to check.
Allows the specification of a predicate to perform matching of method call arguments.
Matches any value that equals the using the .
To use the default comparer for the specified object, specify the value inline,
i.e. mock.Verify(service => service.DoWork(value)).
Use this overload when you specify a value and a comparer.
The value to match with.
An with which the values should be compared.
Type of the argument to check.
Matches any value that is in the range specified.
The lower bound of the range.
The upper bound of the range.
The kind of range. See .
Type of the argument to check.
The following example shows how to expect a method call with an integer argument
within the 0..100 range.
mock.Setup(x => x.HasInventory(
It.IsAny<string>(),
It.IsInRange(0, 100, Range.Inclusive)))
.Returns(false);
Matches any value that is present in the sequence specified.
The sequence of possible values.
Type of the argument to check.
The following example shows how to expect a method call with an integer argument
with value from a list.
var values = new List<int> { 1, 2, 3 };
mock.Setup(x => x.HasInventory(
It.IsAny<string>(),
It.IsIn(values)))
.Returns(false);
Matches any value that is present in the sequence specified.
The sequence of possible values.
An with which the values should be compared.
Type of the argument to check.
Matches any value that is present in the sequence specified.
The sequence of possible values.
Type of the argument to check.
The following example shows how to expect a method call with an integer argument
with a value of 1, 2, or 3.
mock.Setup(x => x.HasInventory(
It.IsAny<string>(),
It.IsIn(1, 2, 3)))
.Returns(false);
Matches any value that is not found in the sequence specified.
The sequence of disallowed values.
Type of the argument to check.
The following example shows how to expect a method call with an integer argument
with value not found from a list.
var values = new List<int> { 1, 2, 3 };
mock.Setup(x => x.HasInventory(
It.IsAny<string>(),
It.IsNotIn(values)))
.Returns(false);
Matches any value that is not found in the sequence specified.
The sequence of disallowed values.
An with which the values should be compared.
Type of the argument to check.
Matches any value that is not found in the sequence specified.
The sequence of disallowed values.
Type of the argument to check.
The following example shows how to expect a method call with an integer argument
of any value except 1, 2, or 3.
mock.Setup(x => x.HasInventory(
It.IsAny<string>(),
It.IsNotIn(1, 2, 3)))
.Returns(false);
Matches a string argument if it matches the given regular expression pattern.
The pattern to use to match the string argument value.
The following example shows how to expect a call to a method where the string argument
matches the given regular expression:
mock.Setup(x => x.Check(It.IsRegex("[a-z]+")))
.Returns(1);
Matches a string argument if it matches the given regular expression pattern.
The pattern to use to match the string argument value.
The options used to interpret the pattern.
The following example shows how to expect a call to a method where the string argument
matches the given regular expression, in a case insensitive way:
mock.Setup(x => x.Check(It.IsRegex("[a-z]+", RegexOptions.IgnoreCase)))
.Returns(1);
A type matcher that matches subtypes of , as well as itself.
The type whose subtypes should match.
A type matcher that matches any value type.
Types that implement this interface represent a criterion against which generic type arguments are matched.
To be used in combination with .
Matches the provided type argument against the criterion represented by this type matcher.
The generic type argument that should be matched.
if the provided type argument matched the criterion represented by this instance;
otherwise, .
Implements the fluent API.
Implements the fluent API.
Implements the fluent API.
Implements the fluent API.
Implements the fluent API.
Implements the fluent API.
Implements the fluent API.
Implements the fluent API.
Implements the fluent API.
Implements the fluent API.
Defines the Callback verb and overloads.
Specifies a callback to invoke when the method is called that receives the original .
This overload is intended to be used in scenarios involving generic type argument matchers
(such as ). The callback will receive the current ,
which allows discovery of both arguments and type arguments.
For all other use cases, you should prefer the other Callback overloads as they provide
better static type safety.
Figure out the generic type argument used for a mocked method call:
mock.Setup(m => m.DoSomethingWith<It.IsAnyType>(...))
.Callback(new InvocationAction(invocation =>
{
var typeArgument = invocation.Method.GetGenericArguments()[0];
// do something interesting with the type argument
});
mock.Object.DoSomethingWith<Something>();
Specifies a callback of any delegate type to invoke when the method is called.
This overload specifically allows you to define callbacks for methods with by-ref parameters.
By-ref parameters can be assigned to.
The callback method to invoke. Must have return type void (C#) or be a Sub (VB.NET).
Invokes the given callback with the concrete invocation argument value. You can modify
by-ref parameters inside the callback.
delegate void ExecuteAction(ref Command command);
Command c = ...;
mock.Setup(x => x.Execute(ref c))
.Callback(new ExecuteAction((ref Command command) => Console.WriteLine("Executing command...")));
Specifies a callback to invoke when the method is called.
The callback method to invoke.
The following example specifies a callback to set a boolean
value that can be used later:
var called = false;
mock.Setup(x => x.Execute())
.Callback(() => called = true);
Specifies a callback to invoke when the method is called that receives the original arguments.
The argument type of the invoked method.
The callback method to invoke.
Invokes the given callback with the concrete invocation argument value.
Notice how the specific string argument is retrieved by simply declaring
it as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(It.IsAny<string>()))
.Callback((string command) => Console.WriteLine(command));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2) => Console.WriteLine(arg1 + arg2));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3) => Console.WriteLine(arg1 + arg2 + arg3));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The type of the fifteenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15));
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The type of the fifteenth argument of the invoked method.
The type of the sixteenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15, string arg16) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16));
Defines the Callback verb and overloads for callbacks on
setups that return a value.
Mocked type.
Type of the return value of the setup.
Specifies a callback to invoke when the method is called that receives the original .
This overload is intended to be used in scenarios involving generic type argument matchers
(such as ). The callback will receive the current ,
which allows discovery of both arguments and type arguments.
For all other use cases, you should prefer the other Callback overloads as they provide
better static type safety.
Figure out the generic type argument used for a mocked method call:
mock.Setup(m => m.DoSomethingWith<It.IsAnyType>(...))
.Callback(new InvocationAction(invocation =>
{
var typeArgument = invocation.Method.GetGenericArguments()[0];
// do something interesting with the type argument
});
mock.Object.DoSomethingWith<Something>();
Specifies a callback of any delegate type to invoke when the method is called.
This overload specifically allows you to define callbacks for methods with by-ref parameters.
By-ref parameters can be assigned to.
The callback method to invoke. Must have return type void (C#) or be a Sub (VB.NET).
Invokes the given callback with the concrete invocation argument value. You can modify
by-ref parameters inside the callback.
delegate void ExecuteAction(ref Command command);
Command c = ...;
mock.Setup(x => x.Execute(ref c))
.Callback(new ExecuteAction((ref Command command) => Console.WriteLine("Executing command...")));
Specifies a callback to invoke when the method is called.
The callback method to invoke.
The following example specifies a callback to set a boolean value that can be used later:
var called = false;
mock.Setup(x => x.Execute())
.Callback(() => called = true)
.Returns(true);
Note that in the case of value-returning methods, after the Callback
call you can still specify the return value.
Specifies a callback to invoke when the method is called that receives the original arguments.
The type of the argument of the invoked method.
Callback method to invoke.
Invokes the given callback with the concrete invocation argument value.
Notice how the specific string argument is retrieved by simply declaring
it as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(It.IsAny<string>()))
.Callback(command => Console.WriteLine(command))
.Returns(true);
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2) => Console.WriteLine(arg1 + arg2));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3) => Console.WriteLine(arg1 + arg2 + arg3));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The type of the fifteenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15));
Specifies a callback to invoke when the method is called that receives the original
arguments.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The type of the fifteenth argument of the invoked method.
The type of the sixteenth argument of the invoked method.
The callback method to invoke.
A reference to interface.
Invokes the given callback with the concrete invocation arguments values.
Notice how the specific arguments are retrieved by simply declaring
them as part of the lambda expression for the callback:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16));
Defines the Callback verb for property getter setups.
Mocked type.
Type of the property.
Specifies a callback to invoke when the property is retrieved.
Callback method to invoke.
Invokes the given callback with the property value being set.
mock.SetupGet(x => x.Suspended)
.Callback(() => called = true)
.Returns(true);
Defines the Callback verb for property setter setups.
Type of the property.
Specifies a callback to invoke when the property is set that receives the
property value being set.
Callback method to invoke.
Invokes the given callback with the property value being set.
mock.SetupSet(x => x.Suspended)
.Callback((bool state) => Console.WriteLine(state));
Defines the CallBase verb.
Calls the real method of the object.
Defines the Raises verb.
Specifies the event that will be raised
when the setup is met.
An expression that represents an event attach or detach action.
The event arguments to pass for the raised event.
The following example shows how to raise an event when
the setup is met:
var mock = new Mock<IContainer>();
mock.Setup(add => add.Add(It.IsAny<string>(), It.IsAny<object>()))
.Raises(add => add.Added += null, EventArgs.Empty);
Specifies the event that will be raised
when the setup is matched.
An expression that represents an event attach or detach action.
A function that will build the
to pass when raising the event.
Specifies the custom event that will be raised
when the setup is matched.
An expression that represents an event attach or detach action.
The arguments to pass to the custom delegate (non EventHandler-compatible).
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
The type of the eighth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
The type of the eighth argument received by the expected invocation.
The type of the ninth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
The type of the eighth argument received by the expected invocation.
The type of the ninth argument received by the expected invocation.
The type of the tenth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
The type of the eighth argument received by the expected invocation.
The type of the ninth argument received by the expected invocation.
The type of the tenth argument received by the expected invocation.
The type of the eleventh argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
The type of the eighth argument received by the expected invocation.
The type of the ninth argument received by the expected invocation.
The type of the tenth argument received by the expected invocation.
The type of the eleventh argument received by the expected invocation.
The type of the twelfth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
The type of the eighth argument received by the expected invocation.
The type of the ninth argument received by the expected invocation.
The type of the tenth argument received by the expected invocation.
The type of the eleventh argument received by the expected invocation.
The type of the twelfth argument received by the expected invocation.
The type of the thirteenth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
The type of the eighth argument received by the expected invocation.
The type of the ninth argument received by the expected invocation.
The type of the tenth argument received by the expected invocation.
The type of the eleventh argument received by the expected invocation.
The type of the twelfth argument received by the expected invocation.
The type of the thirteenth argument received by the expected invocation.
The type of the fourteenth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
The type of the eighth argument received by the expected invocation.
The type of the ninth argument received by the expected invocation.
The type of the tenth argument received by the expected invocation.
The type of the eleventh argument received by the expected invocation.
The type of the twelfth argument received by the expected invocation.
The type of the thirteenth argument received by the expected invocation.
The type of the fourteenth argument received by the expected invocation.
The type of the fifteenth argument received by the expected invocation.
Specifies the event that will be raised when the setup is matched.
The expression that represents an event attach or detach action.
The function that will build the
to pass when raising the event.
The type of the first argument received by the expected invocation.
The type of the second argument received by the expected invocation.
The type of the third argument received by the expected invocation.
The type of the fourth argument received by the expected invocation.
The type of the fifth argument received by the expected invocation.
The type of the sixth argument received by the expected invocation.
The type of the seventh argument received by the expected invocation.
The type of the eighth argument received by the expected invocation.
The type of the ninth argument received by the expected invocation.
The type of the tenth argument received by the expected invocation.
The type of the eleventh argument received by the expected invocation.
The type of the twelfth argument received by the expected invocation.
The type of the thirteenth argument received by the expected invocation.
The type of the fourteenth argument received by the expected invocation.
The type of the fifteenth argument received by the expected invocation.
The type of the sixteenth argument received by the expected invocation.
Defines the Returns verb.
Mocked type.
Type of the return value from the expression.
Specifies the value to return.
The value to return, or .
Return a true value from the method call:
mock.Setup(x => x.Execute("ping"))
.Returns(true);
Specifies a function that will calculate the value to return from the method.
This overload is intended to be used in scenarios involving generic type argument matchers,
such as . The function will receive the current ,
which allows discovery of both arguments and type arguments.
For all other use cases, you should prefer the other Returns overloads as they provide
better static type safety.
Mock a method to act like a generic factory method:
factory.Setup(m => m.Create<It.IsAnyType>())
.Returns(new InvocationFunc(invocation =>
{
var typeArgument = invocation.Method.GetGenericArguments()[0];
return Activator.CreateInstance(typeArgument);
});
var something = factory.Object.Create<Something>();
Specifies a function that will calculate the value to return from the method.
This overload specifically allows you to specify a function with by-ref parameters.
Those by-ref parameters can be assigned to (though you should probably do that from
a Callback instead).
The function that will calculate the return value.
Return a calculated value when the method is called:
delegate bool ExecuteFunc(ref Command command);
Command c = ...;
mock.Setup(x => x.Execute(ref c))
.Returns(new ExecuteFunc((ref Command command) => command.IsExecutable));
Specifies a function that will calculate the value to return from the method.
The function that will calculate the return value.
Return a calculated value when the method is called:
mock.Setup(x => x.Execute("ping"))
.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 method
is executed and the value the returnValues array has at
that moment.
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the argument of the invoked method.
The function that will calculate the return value.
Return a calculated value which is evaluated lazily at the time of the invocation.
The lookup list can change between invocations and the setup
will return different values accordingly. Also, notice how the specific
string argument is retrieved by simply declaring it as part of the lambda
expression:
mock.Setup(x => x.Execute(It.IsAny<string>()))
.Returns((string command) => returnValues[command]);
Calls the real method of the object and returns its return value.
The value calculated by the real method of the object.
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
mock.Setup(x => x.Execute(
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2) => arg1 + arg2);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
mock.Setup(x => x.Execute(
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3) => arg1 + arg2 + arg3);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
mock.Setup(x => x.Execute(
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3, int arg4) => arg1 + arg2 + arg3 + arg4);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
mock.Setup(x => x.Execute(
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5) => arg1 + arg2 + arg3 + arg4 + arg5);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
mock.Setup(x => x.Execute(
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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>(),
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11, int arg12) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11, int arg12, int arg13) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11, int arg12, int arg13, int arg14) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The type of the fifteenth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11, int arg12, int arg13, int arg14, int arg15) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15);
Specifies a function that will calculate the value to return from the method,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The type of the fifteenth argument of the invoked method.
The type of the sixteenth argument of the invoked method.
The function that will calculate the return value.
Returns a calculated value which is evaluated lazily at the time of the invocation.
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:
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>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>()))
.Returns((int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11, int arg12, int arg13, int arg14, int arg15, int arg16) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16);
Defines the Returns verb for property get setups.
Mocked type.
Type of the property.
Specifies the value to return.
The value to return, or .
Return a true value from the property getter call:
mock.SetupGet(x => x.Suspended)
.Returns(true);
Specifies a function that will calculate the value to return for the property.
The function that will calculate the return value.
Return a calculated value when the property is retrieved:
mock.SetupGet(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.
Calls the real property of the object and returns its return value.
The value calculated by the real property of the object.
Implements the fluent API.
The expectation will be considered only in the former condition.
The expectation will be considered only in the former condition.
Setups the get.
The type of the property.
The expression.
Setups the set.
The type of the property.
The setter expression.
Setups the set.
The setter expression.
Defines the Pass and Throws verbs for sequence setups
on void methods.
Configures the next call in the sequence to do nothing.
The following code configures the first call to Execute()
to do nothing, and the second call to throw an exception.
mock.SetupSequence(m => m.Execute())
.Pass()
.Throws<InvalidOperationException>();
Configures the next call in the sequence to throw an exception.
The following code configures the first call to Execute()
to do nothing, and the second call to throw an exception.
mock.SetupSequence(m => m.Execute())
.Pass()
.Throws<InvalidOperationException>();
Configures the next call in the sequence to throw an exception.
The following code configures the first call to Execute()
to do nothing, and the second call to throw an exception.
mock.SetupSequence(m => m.Execute())
.Pass()
.Throws(new InvalidOperationException());
Configures the next call in the sequence to throw a calculated exception.
The following code configures the first call to Execute()
to do nothing, and the second call to throw a calculated exception.
mock.SetupSequence(m => m.Execute())
.Pass()
.Throws(() => new InvalidOperationException());
Language for ReturnSequence
Returns value
Uses delegate to get return value
The function that will calculate the return value.
Throws an exception
Throws an exception
Uses delegate to throws an exception
Calls original method
Defines the Throws verb.
Specifies the exception to throw when the method is invoked.
Exception instance to throw.
This example shows how to throw an exception when the method is
invoked with an empty string argument:
mock.Setup(x => x.Execute(""))
.Throws(new ArgumentException());
Specifies the type of exception to throw when the method is invoked.
Type of exception to instantiate and throw when the setup is matched.
This example shows how to throw an exception when the method is
invoked with an empty string argument:
mock.Setup(x => x.Execute(""))
.Throws<ArgumentException>();
Specifies a function that will calculate the exception to throw when the method is invoked.
The function that will calculate the exception to be thrown.
Throw a calculated exception when the method is called:
delegate Exception ExecuteFunc(string name);
String s = ...;
mock.Setup(x => x.Execute(s))
.Throws(new ExecuteFunc((string s) => new Exception(s)));
Specifies a function that will calculate the exception to throw when the method is invoked.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
Throw a calculated exception when the method is called:
mock.Setup(x => x.Execute("ping"))
.Throws(() => new Exception($"bad {returnValues[0]}"));
The lambda expression to retrieve the exception is lazy-executed,
meaning that its exception may change depending on the moment the method
is executed and the value the returnValues array has at
that moment.
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
Throw a calculated exception which is evaluated lazily at the time of the invocation.
The lookup list can change between invocations and the setup
will return different values accordingly. Also, notice how the specific
string argument is retrieved by simply declaring it as part of the lambda
expression:
mock.Setup(x => x.Execute(It.IsAny<string>()))
.Throws((string command) => new Exception(command));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2) => new Exception(arg1 + arg2));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3) => new Exception(arg1 + arg2 + arg3));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4) => new Exception(arg1 + arg2 + arg3 + arg4));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The type of the fifteenth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15));
Specifies a function that will calculate the exception to throw when the method is invoked,
retrieving the arguments for the invocation.
The type of the first argument of the invoked method.
The type of the second argument of the invoked method.
The type of the third argument of the invoked method.
The type of the fourth argument of the invoked method.
The type of the fifth argument of the invoked method.
The type of the sixth argument of the invoked method.
The type of the seventh argument of the invoked method.
The type of the eighth argument of the invoked method.
The type of the ninth argument of the invoked method.
The type of the tenth argument of the invoked method.
The type of the eleventh argument of the invoked method.
The type of the twelfth argument of the invoked method.
The type of the thirteenth argument of the invoked method.
The type of the fourteenth argument of the invoked method.
The type of the fifteenth argument of the invoked method.
The type of the sixteenth argument of the invoked method.
Type of exception that will be calculated and thrown when the setup is matched.
The function that will calculate the exception to be thrown.
The thrown exception 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:
mock.Setup(x => x.Execute(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Throws((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15, string arg16) => new Exception(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16));
Defines the Verifiable verb.
Marks the expectation as verifiable, meaning that a call
to will check if this particular
expectation was met.
The following example marks the expectation as verifiable:
mock.Expect(x => x.Execute("ping"))
.Returns(true)
.Verifiable();
Marks the expectation as verifiable, meaning that a call
to will check if this particular
expectation was met, and specifies a message for failures.
The following example marks the expectation as verifiable:
mock.Expect(x => x.Execute("ping"))
.Returns(true)
.Verifiable("Ping should be executed always!");
Marks the setup as verifiable and specifies the number of expected calls.
and will later verify
that the setup was called the correct number of times.
Marks the setup as verifiable and specifies the number of expected calls.
and will later verify
that the setup was called the correct number of times.
Marks the setup as verifiable and specifies the number of expected calls
and a message for failures.
and will later verify
that the setup was called the correct number of times.
Marks the setup as verifiable and specifies the number of expected calls
and a message for failures.
and will later verify
that the setup was called the correct number of times.
Defines occurrence members to constraint setups.
The expected invocation can happen at most once.
var mock = new Mock<ICommand>();
mock.Setup(foo => foo.Execute("ping"))
.AtMostOnce();
The expected invocation can happen at most specified number of times.
The number of times to accept calls.
var mock = new Mock<ICommand>();
mock.Setup(foo => foo.Execute("ping"))
.AtMost( 5 );
A default implementation of IQueryable for use with QueryProvider
Converts a taken-apart binary expression such as `m.A.B` (==) `x` to
`Mocks.SetupReturns(Mock.Get(m), m' => m'.A.B, (object)x)`.
Body of the expression to set up.
Return value to be configured for .
Locates the root mock object in a setup expression (which is usually, but not always, a ),
stores a reference to it, and finally replaces it with a new .
Utility repository class to use to construct multiple
mocks when consistent verification is
desired for all of them.
If multiple mocks will be created during a test, passing
the desired (if different than the
or the one
passed to the repository constructor) and later verifying each
mock can become repetitive and tedious.
This repository class helps in that scenario by providing a
simplified creation of multiple mocks with a default
(unless overridden by calling
) and posterior verification.
The following is a straightforward example on how to
create and automatically verify strict mocks using a :
var repository = new MockRepository(MockBehavior.Strict);
var foo = repository.Create<IFoo>();
var bar = repository.Create<IBar>();
// no need to call Verifiable() on the setup
// as we'll be validating all of them anyway.
foo.Setup(f => f.Do());
bar.Setup(b => b.Redo());
// exercise the mocks here
repository.VerifyAll();
// At this point all setups are already checked
// and an optional MockException might be thrown.
// Note also that because the mocks are strict, any invocation
// that doesn't have a matching setup will also throw a MockException.
The following examples shows how to setup the repository
to create loose mocks and later verify only verifiable setups:
var repository = new MockRepository(MockBehavior.Loose);
var foo = repository.Create<IFoo>();
var bar = repository.Create<IBar>();
// this setup will be verified when we verify the repository
foo.Setup(f => f.Do()).Verifiable();
// this setup will NOT be verified
foo.Setup(f => f.Calculate());
// this setup will be verified when we verify the repository
bar.Setup(b => b.Redo()).Verifiable();
// exercise the mocks here
// note that because the mocks are Loose, members
// called in the interfaces for which no matching
// setups exist will NOT throw exceptions,
// and will rather return default values.
repository.Verify();
// At this point verifiable setups are already checked
// and an optional MockException might be thrown.
The following examples shows how to setup the repository with a
default strict behavior, overriding that default for a
specific mock:
var repository = new MockRepository(MockBehavior.Strict);
// this particular one we want loose
var foo = repository.Create<IFoo>(MockBehavior.Loose);
var bar = repository.Create<IBar>();
// specify setups
// exercise the mocks here
repository.Verify();
Access the universe of mocks of the given type, to retrieve those
that behave according to the LINQ query specification.
The type of the mocked object to query.
Access the universe of mocks of the given type, to retrieve those
that behave according to the LINQ query specification.
Behavior of the mocks.
The type of the mocked object to query.
Access the universe of mocks of the given type, to retrieve those
that behave according to the LINQ query specification.
The predicate with the setup expressions.
The type of the mocked object to query.
Access the universe of mocks of the given type, to retrieve those
that behave according to the LINQ query specification.
The predicate with the setup expressions.
Behavior of the mocks.
The type of the mocked object to query.
Creates a mock object of the indicated type.
The type of the mocked object.
The mocked object created.
Creates a mock object of the indicated type.
Behavior of the mock.
The type of the mocked object.
The mocked object created.
Creates a mock object of the indicated type.
The predicate with the setup expressions.
The type of the mocked object.
The mocked object created.
Creates a mock object of the indicated type.
The predicate with the setup expressions.
Behavior of the mock.
The type of the mocked object.
The mocked object created.
Creates the mock query with the underlying queryable implementation.
Wraps the enumerator inside a queryable.
Method that is turned into the actual call from .Query{T}, to
transform the queryable query into a normal enumerable query.
This method is never used directly by consumers.
Initializes the repository with the given
for newly created mocks from the repository.
The behavior to use for mocks created
using the repository method if not overridden
by using the overload.
Allows querying the universe of mocks for those that behave
according to the LINQ query specification.
Access the universe of mocks of the given type, to retrieve those
that behave according to the LINQ query specification.
The type of the mocked object to query.
Access the universe of mocks of the given type, to retrieve those
that behave according to the LINQ query specification.
Behavior of the mocks.
The type of the mocked object to query.
Access the universe of mocks of the given type, to retrieve those
that behave according to the LINQ query specification.
The predicate with the setup expressions.
The type of the mocked object to query.
Access the universe of mocks of the given type, to retrieve those
that behave according to the LINQ query specification.
The predicate with the setup expressions.
Behavior of the mocks.
The type of the mocked object to query.
Creates a mock object of the indicated type.
The type of the mocked object.
The mocked object created.
Creates a mock object of the indicated type.
The predicate with the setup expressions.
The type of the mocked object.
The mocked object created.
Creates the mock query with the underlying queryable implementation.
Wraps the enumerator inside a queryable.
Method that is turned into the actual call from .Query{T}, to
transform the queryable query into a normal enumerable query.
This method is never used directly by consumers.
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.
Derived classes can register and deregister factory functions with and ,
respectively.
The fallback value generation strategy is implemented by the overridable method.
This base class sets up factory functions for task types (, ,
and ) that produce completed tasks containing default values.
If this behavior is not desired, derived classes may deregister those standard factory functions via .
Initializes a new instance of the class.
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.
The type(s) for which to remove any registered factory function.
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.
The type(s) for which to register the given function.
All array types are represented by ().
Generic types are represented by their open generic type definition, e. g. (<>).
The factory function responsible for producing values for the given type.
Determines the default value for the given when no suitable factory is registered for it.
May be overridden in derived classes.
The type of which to produce a value.
The on which an unexpected invocation has occurred.
Allows creating custom value matchers that can be used on setups and verification,
completely replacing the built-in class with your own
argument matching rules.
Argument matching is used to determine whether a concrete invocation in the mock
matches a given setup. This matching mechanism is fully extensible.
Creating a custom matcher is straightforward. You just need to create a method
that returns a value from a call to
with your matching condition and optional friendly render expression:
public Order IsBigOrder()
{
return Match.Create<Order>(
o => o.GrandTotal >= 5000,
() => IsBigOrder()); // a friendly expression to render on failures
}
This method can be used in any mock setup invocation:
mock.Setup(m => m.Submit(IsBigOrder())
.Throws<UnauthorizedAccessException>();
At runtime, Moq knows that the return value was a matcher and
evaluates your predicate with the actual value passed into your predicate.
Another example might be a case where you want to match a lists of orders
that contains a particular one. You might create matcher like the following:
public static class Orders
{
public static IEnumerable<Order> Contains(Order order)
{
return Match.Create<IEnumerable<Order>>(orders => orders.Contains(order));
}
}
Now we can invoke this static method instead of an argument in an invocation:
var order = new Order { ... };
var mock = new Mock<IRepository<Order>>();
mock.Setup(x => x.Save(Orders.Contains(order)))
.Throws<ArgumentException>();
Provided for the sole purpose of rendering the delegate passed to the
matcher constructor if no friendly render lambda is provided.
Initializes the matcher with the condition that will be checked
in order to match invocation values.
The condition to match against actual values.
Initializes the matcher with the condition that will be checked
in order to match invocation values.
The condition to match against actual values.
A lambda representation of the matcher, to be used when rendering error messages,
such as () => It.IsAny<string<().
Initializes the matcher with the condition that will be checked in order to match invocation values.
The predicate of this overload will not only be provided with a
method argument, but also with the associated parameter's type. This parameter type essentially
overrides in cases where the latter is a type matcher. Therefore,
use this method overload if you want your custom matcher to work together with type matchers.
The condition to match against actual values.
This function will be passed the invocation argument, as well as the type of the associated parameter.
A lambda representation of the matcher.
Allows creating custom value matchers that can be used on setups and verification,
completely replacing the built-in class with your own
argument matching rules.
Type of the value to match.
A per-thread observer that records invocations to matchers for later inspection.
This component requires the active cooperation of the respective subsystem.
That is, invoked matchers call into if an
observer is active on the current thread.
Returns the current timestamp. The next call will return a timestamp greater than this one,
allowing you to order invocations and matcher observations.
Adds the specified as an observation.
Checks whether at least one observation is available,
and if so, returns the last one.
The observed matcher observed last.
Matcher to treat static functions as matchers.
mock.Setup(x => x.StringMethod(A.MagicString()));
public static class A
{
[Matcher]
public static string MagicString() { return null; }
public static bool MagicString(string arg)
{
return arg == "magic";
}
}
Will succeed if: mock.Object.StringMethod("magic");
and fail with any other call.
An that is bound to a single, specific method.
has the general form
`mock => mock.Method(...arguments)`. Because the method and arguments are frequently needed,
they are cached in and
for faster access.
Abstract base class for setups that target a single, specific method.
Options to customize the behavior of the mock.
Causes the mock to always throw
an exception for invocations that don't have a
corresponding setup.
Will never throw exceptions, returning default
values when necessary (null for reference types,
zero for value types or empty enumerables and arrays).
Default mock behavior, which equals .
A that returns an empty default value
for non-mockable types, and mocks for all other types (interfaces and
non-sealed classes) that can be mocked.
Exception thrown by mocks when they are not properly set up,
when setups are not matched, when verification fails, etc.
A distinct exception type is provided so that exceptions
thrown by a mock can be distinguished from other exceptions
that might be thrown in tests.
Moq does not provide a richer hierarchy of exception types, as
tests typically should not catch or expect exceptions
from mocks. These are typically the result of changes
in the tested class or its collaborators' implementation, and
result in fixes in the mock setup so that they disappear and
allow the test to pass.
Returns the exception to be thrown when a setup has been invoked an incorrect (unexpected) number of times.
Returns the exception to be thrown when finds no invocations (or the wrong number of invocations) that match the specified expectation.
Returns the exception to be thrown when a strict mock has no setup corresponding to the specified invocation.
Returns the exception to be thrown when a strict mock has no setup that provides a return value for the specified invocation.
Returns the exception to be thrown when a setup was not matched.
Returns an exception whose message is the concatenation of the given ' messages
and whose reason(s) is the combination of the given ' reason(s).
Used by when it finds one or more mocks with verification errors.
Returns the exception to be thrown when finds invocations that have not been verified.
Indicates whether this exception is a verification fault raised by Verify()
Supports the serialization infrastructure.
Serialization information.
Streaming context.
Supports the serialization infrastructure.
Serialization information.
Streaming context.
Provides additional methods on mocks.
Resets this mock's state. This includes its setups, configured default return values, registered event handlers, and all recorded invocations.
The mock whose state should be reset.
Resets all invocations recorded for this mock.
The mock whose recorded invocations should be reset.
Helper class to setup a full trace between many mocks
Initialize a trace setup
Allow sequence to be repeated
Contains extension methods that are related to .
Perform an expectation in the trace.
Provides a mock implementation of .
Type to mock, which can be an interface, a class, or a delegate.
Any interface type can be used for mocking, but for classes, only abstract and virtual members can be mocked.
The behavior of the mock with regards to the setups and the actual calls is determined by the optional
that can be passed to the constructor.
The following example shows establishing setups with specific values for method invocations:
// Arrange
var order = new Order(TALISKER, 50);
var warehouse = new Mock<IWarehouse>();
warehouse.Setup(w => w.HasInventory(TALISKER, 50)).Returns(true);
// Act
order.Fill(warehouse.Object);
// Assert
Assert.True(order.IsFilled);
The following example shows how to use the class
to specify conditions for arguments instead of specific values:
// Arrange
var order = new Order(TALISKER, 50);
var warehouse = new Mock<IWarehouse>();
// shows how to expect a value within a range:
warehouse.Setup(x => x.HasInventory(
It.IsAny<string>(),
It.IsInRange(0, 100, Range.Inclusive)))
.Returns(false);
// shows how to throw for unexpected calls.
warehouse.Setup(x => x.Remove(
It.IsAny<string>(),
It.IsAny<int>()))
.Throws(new InvalidOperationException());
// Act
order.Fill(warehouse.Object);
// Assert
Assert.False(order.IsFilled);
Ctor invoked by AsTInterface exclusively.
Initializes an instance of the mock with behavior.
var mock = new Mock<IFormatProvider>();
Initializes an instance of the mock with behavior
and with the given constructor arguments for the class. (Only valid when is a class.)
Optional constructor arguments if the mocked type is a class.
The mock will try to find the best match constructor given the constructor arguments,
and invoke that to initialize the instance.This applies only for classes, not interfaces.
var mock = new Mock<MyProvider>(someArgument, 25);
Initializes an instance of the mock with the specified behavior.
Behavior of the mock.
var mock = new Mock<IFormatProvider>(MockBehavior.Strict);
Initializes an instance of the mock with a specific behavior
and with the given constructor arguments for the class.
Behavior of the mock.
Optional constructor arguments if the mocked type is a class.
The mock will try to find the best match constructor given the constructor arguments,
and invoke that to initialize the instance. This applies only to classes, not interfaces.
Initializes an instance of the mock using the given constructor call including its
argument values and with a specific behavior.
Lambda expression that creates an instance of .
Behavior of the mock.
var mock = new Mock<MyProvider>(() => new MyProvider(someArgument, 25), MockBehavior.Loose);
Gets or sets the instance that will be used
e. g. to produce default return values for unexpected invocations.
Exposes the mocked object instance.
Allows naming of your mocks, so they can be easily identified in error messages (e.g. from failed assertions).
Returns the name of the mock.
Returns the mocked object value.
A set of switches that influence how this mock will operate.
You can opt in or out of certain features via this property.
Adds an interface implementation to the mock, allowing setups to be specified for it.
This method can only be called before the first use of the mock property,
at which point the runtime type has already been generated and no more interfaces can be added to it.
Also, must be an interface and not a class,
which must be specified when creating the mock instead.
Type of interface to cast the mock to.
The specified is not an interface.
The mock type has already been generated by accessing the property.
The following example creates a mock for the main interface
and later adds to it to verify it's called by the consumer code:
var mock = new Mock<IProcessor>();
mock.Setup(x => x.Execute("ping"));
// add IDisposable interface
var disposable = mock.As<IDisposable>();
disposable.Setup(d => d.Dispose())
.Verifiable();
Specifies a setup on the mocked type for a call to a method.
Lambda expression that specifies the expected method invocation.
If more than one setup is specified for the same method or property,
the latest one wins and is the one that will be executed.
var mock = new Mock<IProcessor>();
mock.Setup(x => x.Execute("ping"));
Specifies a setup on the mocked type for a call to a non- (value-returning) method.
Lambda expression that specifies the method invocation.
Type of the return value. Typically omitted as it can be inferred from the expression.
If more than one setup is specified for the same method or property,
the latest one wins and is the one that will be executed.
mock.Setup(x => x.HasInventory("Talisker", 50))
.Returns(true);
Specifies a setup on the mocked type for a call to a property getter.
Lambda expression that specifies the property getter.
Type of the property. Typically omitted as it can be inferred from the expression.
If more than one setup is set for the same property getter,
the latest one wins and is the one that will be executed.
mock.SetupGet(x => x.Suspended)
.Returns(true);
Specifies a setup on the mocked type for a call to a property setter.
The Lambda expression that sets a property to a value.
Type of the property.
If more than one setup is set for the same property setter,
the latest one wins and is the one that will be executed.
This overloads allows the use of a callback already typed for the property type.
mock.SetupSet(x => x.Suspended = true);
Specifies a setup on the mocked type for a call to a property setter.
Lambda expression that sets a property to a value.
If more than one setup is set for the same property setter,
the latest one wins and is the one that will be executed.
mock.SetupSet(x => x.Suspended = true);
Specifies a setup on the mocked type for a call to an event add.
Lambda expression that adds an event.
If more than one setup is set for the same event add,
the latest one wins and is the one that will be executed.
mock.SetupAdd(x => x.EventHandler += (s, e) => {});
Specifies a setup on the mocked type for a call to an event remove.
Lambda expression that removes an event.
If more than one setup is set for the same event remove,
the latest one wins and is the one that will be executed.
mock.SetupRemove(x => x.EventHandler -= (s, e) => {});
Specifies that the given property should have "property behavior",
meaning that setting its value will cause it to be saved and later returned when the property is requested.
(This is also known as "stubbing".)
Property expression to stub.
Type of the property, inferred from the property expression (does not need to be specified).
If you have an interface with an int property Value,
you might stub it using the following straightforward call:
var mock = new Mock<IHaveValue>();
mock.SetupProperty(v => v.Value);
After the SetupProperty call has been issued, setting and retrieving
the object value will behave as expected:
IHaveValue v = mock.Object;
v.Value = 5;
Assert.Equal(5, v.Value);
Specifies that the given property should have "property behavior",
meaning that setting its value will cause it to be saved and later returned when the property is requested.
This overload allows setting the initial value for the property.
(This is also known as "stubbing".)
Property expression to stub.
Initial value for the property.
Type of the property, inferred from the property expression (does not need to be specified).
If you have an interface with an int property Value,
you might stub it using the following straightforward call:
var mock = new Mock<IHaveValue>();
mock.SetupProperty(v => v.Value, 5);
After the SetupProperty call has been issued, setting and retrieving the object value
will behave as expected:
IHaveValue v = mock.Object;
Assert.Equal(5, v.Value); // Initial value was stored
// New value set which changes the initial value
v.Value = 6;
Assert.Equal(6, v.Value);
Specifies that the all properties on the mock should have "property behavior",
meaning that setting their value will cause them to be saved and later returned when the properties is requested.
(This is also known as "stubbing".)
The default value for each property will be the one generated as specified by the
property for the mock.
If the mock's is set to ,
the mocked default values will also get all properties setup recursively.
Return a sequence of values, once per call.
Performs a sequence of actions, one per call.
Allows setting up a conditional setup.
Conditional setups are only matched by an invocation
when the specified condition evaluates to
at the time when the invocation occurs.
The condition that should be checked
when a setup is being matched against an invocation.
Verifies that a specific invocation matching the given expression was performed on the mock.
Use in conjunction with the default .
Expression to verify.
The invocation was not performed on the mock.
This example assumes that the mock has been used, and later we want to verify
that a given invocation with specific parameters was performed:
var mock = new Mock<IProcessor>();
... // exercise mock
// Will throw if the test code didn't call Execute with a "ping" string argument.
mock.Verify(proc => proc.Execute("ping"));
Verifies that a specific invocation matching the given expression was performed on the mock.
Use in conjunction with the default .
Expression to verify.
The number of times a method is expected to be called.
The invocation was not called the number of times specified by .
Verifies that a specific invocation matching the given expression was performed on the mock.
Use in conjunction with the default .
Expression to verify.
The number of times a method is expected to be called.
The invocation was not called the number of times specified by .
Verifies that a specific invocation matching the given expression was performed on the mock,
specifying a failure error message.
Use in conjunction with the default .
Expression to verify.
Message to show if verification fails.
The invocation was not performed on the mock.
Verifies that a specific invocation matching the given expression was performed on the mock,
specifying a failure error message.
Use in conjunction with the default .
Expression to verify.
The number of times a method is expected to be called.
Message to show if verification fails.
The invocation was not called the number of times specified by .
Verifies that a specific invocation matching the given expression was performed on the mock,
specifying a failure error message.
Use in conjunction with the default .
Expression to verify.
The number of times a method is expected to be called.
Message to show if verification fails.
The invocation was not called the number of times specified by .
Verifies that a specific invocation matching the given expression was performed on the mock.
Use in conjunction with the default .
Expression to verify.
Type of return value from the expression.
The invocation was not performed on the mock.
This example assumes that the mock has been used, and later we want to verify
that a given invocation with specific parameters was performed:
var mock = new Mock<IWarehouse>();
... // exercise mock
// Will throw if the test code didn't call HasInventory.
mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50));
Verifies that a specific invocation matching the given expression was performed on the mock.
Use in conjunction with the default .
Expression to verify.
The number of times a method is expected to be called.
Type of return value from the expression.
The invocation was not called the number of times specified by .
Verifies that a specific invocation matching the given expression was performed on the mock.
Use in conjunction with the default .
Expression to verify.
The number of times a method is expected to be called.
Type of return value from the expression.
The invocation was not called the number of times specified by .
Verifies that a specific invocation matching the given expression was performed on the mock,
specifying a failure error message.
Expression to verify.
Message to show if verification fails.
Type of return value from the expression.
The invocation was not performed on the mock.
This example assumes that the mock has been used, and later we want to verify
that a given invocation with specific parameters was performed:
var mock = new Mock<IWarehouse>();
... // exercise mock
// Will throw if the test code didn't call HasInventory.
mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50),
"When filling orders, inventory has to be checked");
Verifies that a specific invocation matching the given expression was performed on the mock,
specifying a failure error message.
Expression to verify.
The number of times a method is expected to be called.
Message to show if verification fails.
Type of return value from the expression.
The invocation was not called the number times specified by .
Verifies that a property was read on the mock.
Expression to verify.
Type of the property to verify. Typically omitted as it can be inferred from the expression's return type.
The invocation was not performed on the mock.
This example assumes that the mock has been used, and later we want to verify
that a given property was retrieved from it:
var mock = new Mock<IWarehouse>();
... // exercise mock
// Will throw if the test code didn't retrieve the IsClosed property.
mock.VerifyGet(warehouse => warehouse.IsClosed);
Verifies that a property was read on the mock.
The number of times a method is expected to be called.
Expression to verify.
Type of the property to verify. Typically omitted as it can be inferred from the expression's return type.
The invocation was not called the number times specified by .
Verifies that a property was read on the mock.
The number of times a method is expected to be called.
Expression to verify.
Type of the property to verify. Typically omitted as it can be inferred from the expression's return type.
The invocation was not called the number times specified by .
Verifies that a property was read on the mock, specifying a failure error message.
Expression to verify.
Message to show if verification fails.
Type of the property to verify. Typically omitted as it can be inferred from the expression's return type.
The invocation was not performed on the mock.
Verifies that a property was read on the mock, specifying a failure error message.
The number of times a method is expected to be called.
Expression to verify.
Message to show if verification fails.
Type of the property to verify. Typically omitted as it can be inferred from the expression's return type.
The invocation was not called the number times specified by .
Verifies that a property was read on the mock, specifying a failure error message.
The number of times a method is expected to be called.
Expression to verify.
Message to show if verification fails.
Type of the property to verify. Typically omitted as it can be inferred from the expression's return type.
The invocation was not called the number times specified by .
Verifies that a property was set on the mock.
Expression to verify.
The invocation was not performed on the mock.
This example assumes that the mock has been used, and later we want to verify
that a given property was set on it:
var mock = new Mock<IWarehouse>();
... // exercise mock
// Will throw if the test code didn't set the IsClosed property.
mock.VerifySet(warehouse => warehouse.IsClosed = true);
Verifies that a property was set on the mock.
The number of times a method is expected to be called.
Expression to verify.
The invocation was not called the number of times specified by .
Verifies that a property was set on the mock.
The number of times a method is expected to be called.
Expression to verify.
The invocation was not called the number of times specified by .
Verifies that a property was set on the mock, specifying a failure message.
Expression to verify.
Message to show if verification fails.
The invocation was not performed on the mock.
This example assumes that the mock has been used, and later we want to verify
that a given property was set on it:
var mock = new Mock<IWarehouse>();
... // exercise mock
// Will throw if the test code didn't set the IsClosed property.
mock.VerifySet(warehouse => warehouse.IsClosed = true,
"Warehouse should always be closed after the action");
Verifies that a property was set on the mock, specifying a failure message.
The number of times a method is expected to be called.
Expression to verify.
Message to show if verification fails.
The invocation was not called the number of times specified by .
Verifies that a property was set on the mock, specifying a failure message.
The number of times a method is expected to be called.
Expression to verify.
Message to show if verification fails.
The invocation was not called the number of times specified by .
Verifies that an event was added to the mock.
Expression to verify.
The invocation was not performed on the mock.
This example assumes that the mock has been used, and later we want to verify
that a given event handler was subscribed to an event:
var mock = new Mock<IWarehouse>();
... // exercise mock
// Will throw if the test code didn't subscribe to the OnClosed event.
mock.VerifyAdd(warehouse => warehouse.OnClosed += It.IsAny<EventHandler>());
Verifies that an event was added to the mock.
The number of times a method is expected to be called.
Expression to verify.
The invocation was not called the number of times specified by .
Verifies that an event was added to the mock.
The number of times a method is expected to be called.
Expression to verify.
The invocation was not called the number of times specified by .
Verifies that an event was added to the mock, specifying a failure message.
Expression to verify.
Message to show if verification fails.
The invocation was not performed on the mock.
Verifies that an event was added to the mock, specifying a failure message.
The number of times a method is expected to be called.
Expression to verify.
Message to show if verification fails.
The invocation was not called the number of times specified by .
Verifies that an event was added to the mock, specifying a failure message.
The number of times a method is expected to be called.
Expression to verify.
Message to show if verification fails.
The invocation was not called the number of times specified by .
Verifies that an event was removed from the mock.
Expression to verify.
The invocation was not performed on the mock.
This example assumes that the mock has been used, and later we want to verify
that a given event handler was removed from an event:
var mock = new Mock<IWarehouse>();
... // exercise mock
// Will throw if the test code didn't unsubscribe from the OnClosed event.
mock.VerifyRemove(warehouse => warehouse.OnClose -= It.IsAny<EventHandler>());
Verifies that an event was removed from the mock.
The number of times a method is expected to be called.
Expression to verify.
The invocation was not called the number of times specified by .
Verifies that an event was removed from the mock.
The number of times a method is expected to be called.
Expression to verify.
The invocation was not called the number of times specified by .
Verifies that an event was removed from the mock, specifying a failure message.
Expression to verify.
Message to show if verification fails.
The invocation was not performed on the mock.
Verifies that an event was removed from the mock, specifying a failure message.
The number of times a method is expected to be called.
Expression to verify.
Message to show if verification fails.
The invocation was not called the number of times specified by .
Verifies that an event was removed from the mock, specifying a failure message.
The number of times a method is expected to be called.
Expression to verify.
Message to show if verification fails.
The invocation was not called the number of times specified by .
Verifies that there were no calls other than those already verified.
There was at least one invocation not previously verified.
Raises the event referenced in using the given argument.
The argument is invalid for the target event invocation,
or the is not an event attach or detach expression.
The following example shows how to raise a
event:
var mock = new Mock<IViewModel>();
mock.Raise(x => x.PropertyChanged -= null, new PropertyChangedEventArgs("Name"));
This example shows how to invoke an event with a custom event arguments class
in a view that will cause its corresponding presenter to react by changing its state:
var mockView = new Mock<IOrdersView>();
var presenter = new OrdersPresenter(mockView.Object);
// Check that the presenter has no selection by default
Assert.Null(presenter.SelectedOrder);
// Raise the event with a specific arguments data
mockView.Raise(v => v.SelectionChanged += null, new OrderEventArgs { Order = new Order("moq", 500) });
// Now the presenter reacted to the event, and we have a selected order
Assert.NotNull(presenter.SelectedOrder);
Assert.Equal("moq", presenter.SelectedOrder.ProductName);
Raises the event referenced in using the given argument for a non--typed event.
The arguments are invalid for the target event invocation,
or the is not an event attach or detach expression.
The following example shows how to raise a custom event that does not adhere
to the standard EventHandler:
var mock = new Mock<IViewModel>();
mock.Raise(x => x.MyEvent -= null, "Name", bool, 25);
Raises the event referenced in using the given arguments
for an event with a Func<..., Task> or Func<..., ValueTask> signature.
The returned completes when all of the s / s
returned by the event handlers have completed.
The arguments are invalid for the target event invocation,
or the is not an event attach or detach expression.
The following example shows how to raise an event with async event handlers:
interface IViewModel
{
event Func<InitializationData, Task> Initialized;
}
var mock = new Mock<IViewModel>();
mock.Object.Initialized += async initializationData => ...;
await mock.RaiseAsync(x => x.Initialized += null, new InitializationData { ... });
Obsolete.
Obsolete.
Obsolete.
Obsolete.
Obsolete.
Marks a method as a matcher, which allows complete replacement
of the built-in class with your own argument
matching rules.
This feature has been deprecated in favor of the new
and simpler .
The argument matching is used to determine whether a concrete
invocation in the mock matches a given setup. This
matching mechanism is fully extensible.
There are two parts of a matcher: the compiler matcher
and the runtime matcher.
-
Compiler matcher
Used to satisfy the compiler requirements for the
argument. Needs to be a method optionally receiving any arguments
you might need for the matching, but with a return type that
matches that of the argument.
Let's say I want to match a lists of orders that contains
a particular one. I might create a compiler matcher like the following:
public static class Orders
{
[Matcher]
public static IEnumerable<Order> Contains(Order order)
{
return null;
}
}
Now we can invoke this static method instead of an argument in an
invocation:
var order = new Order { ... };
var mock = new Mock<IRepository<Order>>();
mock.Setup(x => x.Save(Orders.Contains(order)))
.Throws<ArgumentException>();
Note that the return value from the compiler matcher is irrelevant.
This method will never be called, and is just used to satisfy the
compiler and to signal Moq that this is not a method that we want
to be invoked at runtime.
-
Runtime matcher
The runtime matcher is the one that will actually perform evaluation
when the test is run, and is defined by convention to have the
same signature as the compiler matcher, but where the return
value is the first argument to the call, which contains the
object received by the actual invocation at runtime:
public static bool Contains(IEnumerable<Order> orders, Order order)
{
return orders.Contains(order);
}
At runtime, the mocked method will be invoked with a specific
list of orders. This value will be passed to this runtime
matcher as the first argument, while the second argument is the
one specified in the setup (x.Save(Orders.Contains(order))).
The boolean returned determines whether the given argument has been
matched. If all arguments to the expected method are matched, then
the setup matches and is evaluated.
Using this extensible infrastructure, you can easily replace the entire
set of matchers with your own. You can also avoid the
typical (and annoying) lengthy expressions that result when you have
multiple arguments that use generics.
The following is the complete example explained above:
public static class Orders
{
[Matcher]
public static IEnumerable<Order> Contains(Order order)
{
return null;
}
public static bool Contains(IEnumerable<Order> orders, Order order)
{
return orders.Contains(order);
}
}
And the concrete test using this matcher:
var order = new Order { ... };
var mock = new Mock<IRepository<Order>>();
mock.Setup(x => x.Save(Orders.Contains(order)))
.Throws<ArgumentException>();
// use mock, invoke Save, and have the matcher filter.
Contains obsolete API members as extension methods so that existing code continues to compile,
but new code doesn't see them.
Obsolete.
Obsolete.
Obsolete.
Utility factory class to use to construct multiple
mocks when consistent verification is
desired for all of them.
If multiple mocks will be created during a test, passing
the desired (if different than the
or the one
passed to the factory constructor) and later verifying each
mock can become repetitive and tedious.
This factory class helps in that scenario by providing a
simplified creation of multiple mocks with a default
(unless overridden by calling
) and posterior verification.
The following is a straightforward example on how to
create and automatically verify strict mocks using a :
var factory = new MockFactory(MockBehavior.Strict);
var foo = factory.Create<IFoo>();
var bar = factory.Create<IBar>();
// no need to call Verifiable() on the setup
// as we'll be validating all of them anyway.
foo.Setup(f => f.Do());
bar.Setup(b => b.Redo());
// exercise the mocks here
factory.VerifyAll();
// At this point all setups are already checked
// and an optional MockException might be thrown.
// Note also that because the mocks are strict, any invocation
// that doesn't have a matching setup will also throw a MockException.
The following examples shows how to setup the factory
to create loose mocks and later verify only verifiable setups:
var factory = new MockFactory(MockBehavior.Loose);
var foo = factory.Create<IFoo>();
var bar = factory.Create<IBar>();
// this setup will be verified when we verify the factory
foo.Setup(f => f.Do()).Verifiable();
// this setup will NOT be verified
foo.Setup(f => f.Calculate());
// this setup will be verified when we verify the factory
bar.Setup(b => b.Redo()).Verifiable();
// exercise the mocks here
// note that because the mocks are Loose, members
// called in the interfaces for which no matching
// setups exist will NOT throw exceptions,
// and will rather return default values.
factory.Verify();
// At this point verifiable setups are already checked
// and an optional MockException might be thrown.
The following examples shows how to setup the factory with a
default strict behavior, overriding that default for a
specific mock:
var factory = new MockFactory(MockBehavior.Strict);
// this particular one we want loose
var foo = factory.Create<IFoo>(MockBehavior.Loose);
var bar = factory.Create<IBar>();
// specify setups
// exercise the mocks here
factory.Verify();
Initializes the factory with the given
for newly created mocks from the factory.
The behavior to use for mocks created
using the factory method if not overridden
by using the overload.
Gets the default of mocks created by this repository.
Whether the base member virtual implementation will be called
for mocked classes if no setup is matched. Defaults to .
Specifies the behavior to use when returning default values for
unexpected invocations on loose mocks.
Gets or sets the instance that will be used
e. g. to produce default return values for unexpected invocations.
Gets the mocks that have been created by this factory and
that will get verified together.
A set of switches that influence how mocks created by this factory will operate.
You can opt in or out of certain features via this property.
Creates a new mock with the default
specified at factory construction time.
Type to mock.
A new .
var factory = new MockFactory(MockBehavior.Strict);
var foo = factory.Create<IFoo>();
// use mock on tests
factory.VerifyAll();
Creates a new mock with the default
specified at factory construction time and with the
the given constructor arguments for the class.
The mock will try to find the best match constructor given the
constructor arguments, and invoke that to initialize the instance.
This applies only to classes, not interfaces.
Type to mock.
Constructor arguments for mocked classes.
A new .
var factory = new MockFactory(MockBehavior.Default);
var mock = factory.Create<MyBase>("Foo", 25, true);
// use mock on tests
factory.Verify();
Creates a new mock with the given .
Type to mock.
Behavior to use for the mock, which overrides
the default behavior specified at factory construction time.
A new .
The following example shows how to create a mock with a different
behavior to that specified as the default for the factory:
var factory = new MockFactory(MockBehavior.Strict);
var foo = factory.Create<IFoo>(MockBehavior.Loose);
Creates a new mock with the given
and with the given constructor arguments for the class.
The mock will try to find the best match constructor given the
constructor arguments, and invoke that to initialize the instance.
This applies only to classes, not interfaces.
Type to mock.
Behavior to use for the mock, which overrides
the default behavior specified at factory construction time.
Constructor arguments for mocked classes.
A new .
The following example shows how to create a mock with a different
behavior to that specified as the default for the factory, passing
constructor arguments:
var factory = new MockFactory(MockBehavior.Default);
var mock = factory.Create<MyBase>(MockBehavior.Strict, "Foo", 25, true);
Creates an instance of the mock using the given constructor call including its
argument values and with a specific behavior.
Type to mock.
Lambda expression that creates an instance of .
Behavior of the mock.
A new .
var factory = new MockFactory(MockBehavior.Default);
var mock = factory.Create<MyClass>(() => new MyClass("Foo", 25, true), MockBehavior.Loose);
// use mock on tests
factory.Verify();
Implements creation of a new mock within the factory.
Type to mock.
The behavior for the new mock.
Optional arguments for the construction of the mock.
Verifies all verifiable setups on all mocks created by this factory.
One or more mocks had setups that were not satisfied.
Verifies all setups on all mocks created by this factory.
One or more mocks had setups that were not satisfied.
Calls on all mocks created by this factory.
One or more mocks had invocations that were not verified.
Invokes for each mock
in , and accumulates the resulting
verification exceptions that might be
thrown from the action.
The action to execute against
each mock.
Provides additional methods on mocks.
Provided as extension methods as they confuse the compiler
with the overloads taking Action.
Specifies a setup on the mocked type for a call to
to a property setter, regardless of its value.
If more than one setup is set for the same property setter,
the latest one wins and is the one that will be executed.
Type of the property. Typically omitted as it can be inferred from the expression.
Type of the mock.
The target mock for the setup.
Lambda expression that specifies the property setter.
mock.SetupSet(x => x.Suspended);
This method is not legacy, but must be on an extension method to avoid
confusing the compiler with the new Action syntax.
Verifies that a property has been set on the mock, regardless of its value.
This example assumes that the mock has been used,
and later we want to verify that a given invocation
with specific parameters was performed:
var mock = new Mock<IWarehouse>();
// exercise mock
//...
// Will throw if the test code didn't set the IsClosed property.
mock.VerifySet(warehouse => warehouse.IsClosed);
The invocation was not performed on the mock.
Expression to verify.
The mock instance.
Mocked type.
Type of the property to verify. Typically omitted as it can
be inferred from the expression's return type.
Verifies that a property has been set on the mock, specifying a failure
error message.
This example assumes that the mock has been used,
and later we want to verify that a given invocation
with specific parameters was performed:
var mock = new Mock<IWarehouse>();
// exercise mock
//...
// Will throw if the test code didn't set the IsClosed property.
mock.VerifySet(warehouse => warehouse.IsClosed);
The invocation was not performed on the mock.
Expression to verify.
Message to show if verification fails.
The mock instance.
Mocked type.
Type of the property to verify. Typically omitted as it can
be inferred from the expression's return type.
Verifies that a property has been set on the mock, regardless
of the value but only the specified number of times.
This example assumes that the mock has been used,
and later we want to verify that a given invocation
with specific parameters was performed:
var mock = new Mock<IWarehouse>();
// exercise mock
//...
// Will throw if the test code didn't set the IsClosed property.
mock.VerifySet(warehouse => warehouse.IsClosed);
The invocation was not performed on the mock.
The invocation was not call the times specified by
.
The mock instance.
Mocked type.
The number of times a method is allowed to be called.
Expression to verify.
Type of the property to verify. Typically omitted as it can
be inferred from the expression's return type.
Verifies that a property has been set on the mock, regardless
of the value but only the specified number of times, and specifying a failure
error message.
This example assumes that the mock has been used,
and later we want to verify that a given invocation
with specific parameters was performed:
var mock = new Mock<IWarehouse>();
// exercise mock
//...
// Will throw if the test code didn't set the IsClosed property.
mock.VerifySet(warehouse => warehouse.IsClosed);
The invocation was not performed on the mock.
The invocation was not call the times specified by
.
The mock instance.
Mocked type.
The number of times a method is allowed to be called.
Message to show if verification fails.
Expression to verify.
Type of the property to verify. Typically omitted as it can
be inferred from the expression's return type.
Helper for sequencing return values in the same method.
Return a sequence of values, once per call.
Performs a sequence of actions, one per call.
Return a sequence of tasks, once per call.
Return a sequence of tasks, once per call.
Return a sequence of tasks, once per call.
Return a sequence of tasks, once per call.
Return a sequence of tasks, once per call.
Return a sequence of tasks, once per call.
Throws a sequence of exceptions, once per call.
Throws a sequence of exceptions, once per call.
Throws a sequence of exceptions, once per call.
Throws a sequence of exceptions, once per call.
Allocation-free adapter type for treating a `ParameterInfo[]` array like a `Type[]` array.
A strongly-typed resource class, for looking up localized strings, etc.
Returns the cached ResourceManager instance used by this class.
Overrides the current thread's CurrentUICulture property for all
resource lookups using this strongly typed resource class.
Looks up a localized string similar to Mock type has already been initialized by accessing its Object property. Adding interfaces must be done before that..
Looks up a localized string similar to Value cannot be an empty string..
Looks up a localized string similar to Matcher '{0}' is unmatchable: An implicit conversion operator will convert arguments of type '{1}' to the parameter's type '{2}', which is assignment-incompatible..
Looks up a localized string similar to Can only add interfaces to the mock..
Looks up a localized string similar to CallBase cannot be used with Delegate mocks..
Looks up a localized string similar to Can't set return value for void method {0}..
Looks up a localized string similar to Constructor arguments cannot be passed for delegate mocks..
Looks up a localized string similar to Constructor arguments cannot be passed for interface mocks..
Looks up a localized string similar to A matching constructor for the given arguments was not found on the mocked type..
Looks up a localized string similar to Delays have to be greater than zero to ensure an async callback is used..
Looks up a localized string similar to Expression {0} involves a field access, which is not supported. Use properties instead..
Looks up a localized string similar to Invalid callback. This overload of the "Callback" method only accepts "void" (C#) or "Sub" (VB.NET) delegates with parameter types matching those of the set up method..
Looks up a localized string similar to Invalid callback. Setup on method with {0} parameter(s) cannot invoke callback with different number of parameters ({1})..
Looks up a localized string similar to Invalid callback. Setup on method with parameters ({0}) cannot invoke callback with parameters ({1})..
Looks up a localized string similar to Invalid callback. Setup on method with return type '{0}' cannot invoke callback with return type '{1}'..
Looks up a localized string similar to Cannot retrieve a mock with the given object type {0} as it's not the main type of the mock or any of its additional interfaces.
Please cast the argument to one of the supported types: {1}.
Remember that there's no generics covariance in the CLR, so your object must be one of these types in order for the call to succeed..
Looks up a localized string similar to Invalid callback. This overload of the "Returns" method only accepts non-"void" (C#) or "Function" (VB.NET) delegates with parameter types matching those of the set up method..
Looks up a localized string similar to The return type of the last member shown above is not mockable..
Looks up a localized string similar to The equals ("==" or "=" in VB) and the conditional 'and' ("&&" or "AndAlso" in VB) operators are the only ones supported in the query specification expression. Unsupported expression: {0}.
Looks up a localized string similar to LINQ method '{0}' not supported..
Looks up a localized string similar to Expression contains a call to a method which is not virtual (overridable in VB) or abstract. Unsupported expression: {0}.
Looks up a localized string similar to Could not determine the correct positions for all argument matchers ({0} in total) used in a call to this method: {1}.
This could be caused by an unrecognized type conversion, coercion, narrowing, or widening, and is most likely a bug in Moq. Please report your use case to the Moq team..
Looks up a localized string similar to Member {0}.{1} does not exist..
Looks up a localized string similar to Method {0}.{1} is public. Use strong-typed Expect overload instead:
mock.Setup(x => x.{1}());
.
Looks up a localized string similar to No protected method {0}.{1} found whose signature is compatible with the provided arguments ({2})..
Looks up a localized string similar to Cannot set up {0}.{1} because it is not accessible to the proxy generator used by Moq:
{2}.
Looks up a localized string similar to Minimum delay has to be lower than maximum delay..
Looks up a localized string similar to {0} invocation failed with mock behavior {1}.
{2}.
Looks up a localized string similar to The next member after the last one shown above is non-virtual, sealed, or not visible to the proxy factory..
Looks up a localized string similar to No constructor call could be found..
Looks up a localized string similar to No invocations performed..
Looks up a localized string similar to Expected invocation on the mock at least {0} times, but was {2} times: .
Looks up a localized string similar to Expected invocation on the mock at least once, but was never performed: .
Looks up a localized string similar to Expected invocation on the mock at most {1} times, but was {2} times: .
Looks up a localized string similar to Expected invocation on the mock at most once, but was {2} times: .
Looks up a localized string similar to Expected invocation on the mock between {0} and {1} times (Exclusive), but was {2} times: .
Looks up a localized string similar to Expected invocation on the mock between {0} and {1} times (Inclusive), but was {2} times: .
Looks up a localized string similar to Expected invocation on the mock exactly {0} times, but was {2} times: .
Looks up a localized string similar to Expected invocation on the mock should never have been performed, but was {2} times: .
Looks up a localized string similar to Expected invocation on the mock once, but was {2} times: .
Looks up a localized string similar to All invocations on the mock must have a corresponding setup..
Looks up a localized string similar to Object instance was not created by Moq..
Looks up a localized string similar to Out expression must evaluate to a constant value..
Looks up a localized string similar to Performed invocations:.
Looks up a localized string similar to Property {0}.{1} does not have a getter..
Looks up a localized string similar to Property {0}.{1} does not have a setter..
Looks up a localized string similar to Type {0} does not have matching protected member: {1}.
Looks up a localized string similar to Ref expression must evaluate to a constant value..
Looks up a localized string similar to Invocation needs to return a value and therefore must have a corresponding setup that provides it..
Looks up a localized string similar to Expression is not an event add: {0}.
Looks up a localized string similar to Expression is not an event remove: {0}.
Looks up a localized string similar to Expression is not a property access: {0}.
Looks up a localized string similar to Expression is not a setter: {0}.
Looks up a localized string similar to Type {0} does not have a default (public parameterless) constructor..
Looks up a localized string similar to Type matchers may not be used as the type for 'Callback' or 'Returns' parameters, because no argument will never have that precise type. Consider using type 'object' instead..
Looks up a localized string similar to Type {0} does not implement required interface {1}.
Looks up a localized string similar to Type to mock ({0}) must be an interface, a delegate, or a non-sealed, non-static class..
Looks up a localized string similar to To specify a setup for public property {0}.{1}, use the typed overloads, such as:
mock.Setup(x => x.{1}).Returns(value);
mock.SetupGet(x => x.{1}).Returns(value); //equivalent to previous one
mock.SetupSet(x => x.{1}).Callback(callbackDelegate);
.
Looks up a localized string similar to Unexpected translation of a member access: {0}.
Looks up a localized string similar to Unhandled binding type: {0}.
Looks up a localized string similar to Unhandled expression type: {0}.
Looks up a localized string similar to {0}:
This setup was not matched..
Looks up a localized string similar to Unsupported expression: {0}.
Looks up a localized string similar to Unsupported expression: {0}
{1}.
Looks up a localized string similar to Extension methods (here: {0}) may not be used in setup / verification expressions..
Looks up a localized string similar to Member {0} is not supported for protected mocking..
Looks up a localized string similar to Non-overridable members (here: {0}) may not be used in setup / verification expressions..
Looks up a localized string similar to Static members (here: {0}) may not be used in setup / verification expressions..
Looks up a localized string similar to {0}:
This mock failed verification due to the following unverified invocations:.
Looks up a localized string similar to Use ItExpr.IsNull<TValue> rather than a null argument value, as it prevents proper method lookup..
Looks up a localized string similar to It is impossible to call the provided strongly-typed predicate due to the use of a type matcher. Provide a weakly-typed predicate with two parameters (object, Type) instead..
Looks up a localized string similar to {0}:.
Looks up a localized string similar to {0}:
This mock failed verification due to the following:.
Looks up a localized string similar to The mock repository failed verification due to the following:.
Allows setups to be specified for protected members (methods and properties)
seen through another type with corresponding members (that is, members
having identical signatures as the ones to be set up).
Type of the mocked object.
Any type with members whose signatures are identical to the mock's protected members (except for their accessibility level).
Specifies a setup on the mocked type for a call to a method.
Lambda expression that specifies the expected method invocation.
Specifies a setup on the mocked type for a call to a value-returning method.
Type of the return value. Typically omitted as it can be inferred from the expression.
Lambda expression that specifies the expected method invocation.
Specifies a setup on the mocked type for a call to a property setter.
The Lambda expression that sets a property to a value.
Type of the property.
If more than one setup is set for the same property setter,
the latest one wins and is the one that will be executed.
This overloads allows the use of a callback already typed for the property type.
mock.SetupSet<bool>(x => x.Suspended = true);
Specifies a setup on the mocked type for a call to a property setter.
Lambda expression that sets a property to a value.
If more than one setup is set for the same property setter,
the latest one wins and is the one that will be executed.
mock.SetupSet(x => x.Suspended = true);
Specifies a setup on the mocked type for a call to a property getter.
Type of the property. Typically omitted as it can be inferred from the expression.
Lambda expression that specifies the property getter.
Specifies that the given property should have "property behavior",
meaning that setting its value will cause it to be saved and later returned when the property is requested.
(This is also known as "stubbing".)
Type of the property. Typically omitted as it can be inferred from the expression.
Lambda expression that specifies the property.
Initial value for the property.
Return a sequence of values, once per call.
Type of the return value. Typically omitted as it can be inferred from the expression.
Lambda expression that specifies the expected method invocation.
Performs a sequence of actions, one per call.
Lambda expression that specifies the expected method invocation.
Verifies that a specific invocation matching the given expression was performed on the mock.
Use in conjunction with the default .
Lambda expression that specifies the method invocation.
Number of times that the invocation is expected to have occurred.
If omitted, assumed to be .
Message to include in the thrown if verification fails.
The specified invocation did not occur (or did not occur the specified number of times).
Verifies that a specific invocation matching the given expression was performed on the mock.
Use in conjunction with the default .
Type of the return value. Typically omitted as it can be inferred from the expression.
Lambda expression that specifies the method invocation.
Number of times that the invocation is expected to have occurred.
If omitted, assumed to be .
Message to include in the thrown if verification fails.
The specified invocation did not occur (or did not occur the specified number of times).
Verifies that a property was set on the mock.
Expression to verify.
Number of times that the setter is expected to have occurred.
If omitted, assumed to be .
Message to show if verification fails.
The invocation was not called the number of times specified by .
Verifies that a property was read on the mock.
Type of the property. Typically omitted as it can be inferred from the expression.
Lambda expression that specifies the method invocation.
Number of times that the invocation is expected to have occurred.
If omitted, assumed to be .
Message to include in the thrown if verification fails.
The specified invocation did not occur (or did not occur the specified number of times).
Allows setups to be specified for protected members by using their
name as a string, rather than strong-typing them which is not possible
due to their visibility.
Set up protected members (methods and properties) seen through another type with identical member signatures.
Any type with members whose signatures are identical to the mock's protected members (except for their accessibility level).
Specifies a setup for a void method invocation with the given
, optionally specifying arguments for the method call.
The name of the void method to be invoked.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Specifies a setup for a void method invocation with the given
, optionally specifying arguments for the method call.
The name of the void method to be invoked.
Should the parameter types match exactly types that were provided
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Specifies a setup for a void method invocation with the given
, optionally specifying arguments for the method call.
The name of the void method to be invoked.
An array of types to be substituted for the type parameters of the current generic method definition.
Should the parameter types match exactly types that were provided
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Specifies a setup for an invocation on a property or a non void method with the given
, optionally specifying arguments for the method call.
The name of the method or property to be invoked.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
The return type of the method or property.
Specifies a setup for an invocation on a property or a non void method with the given
, optionally specifying arguments for the method call.
The name of the method or property to be invoked.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Should the parameter types match exactly types that were provided
The return type of the method or property.
Specifies a setup for an invocation on a property or a non void method with the given
, optionally specifying arguments for the method call.
The name of the method or property to be invoked.
An array of types to be substituted for the type parameters of the current generic method definition.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Should the parameter types match exactly types that were provided
The return type of the method or property.
Specifies a setup for an invocation on a property getter with the given
.
The name of the property.
The type of the property.
Specifies a setup for an invocation on a property setter with the given
.
The name of the property.
The property value. If argument matchers are used,
remember to use rather than .
The type of the property.
Performs a sequence of actions, one per call.
Name of the method or property being set up.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Performs a sequence of actions, one per call.
Name of the method or property being set up.
Determines whether the parameter types should exactly match the types provided.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Performs a sequence of actions, one per call.
Name of the method or property being set up.
An array of types to be substituted for the type parameters of the current generic method definition.
Determines whether the parameter types should exactly match the types provided.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Return a sequence of values, once per call.
Name of the method or property being set up.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Return type of the method or property being set up.
Return a sequence of values, once per call.
Name of the method or property being set up.
Determines whether the parameter types should exactly match the types provided.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Return type of the method or property being set up.
Return a sequence of values, once per call.
Name of the method or property being set up.
An array of types to be substituted for the type parameters of the current generic method definition.
Determines whether the parameter types should exactly match the types provided.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Return type of the method or property being set up.
Specifies a verify for a void method with the given ,
optionally specifying arguments for the method call. Use in conjunction with the default
.
The invocation was not call the times specified by
.
The name of the void method to be verified.
The number of times a method is allowed to be called.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Specifies a verify for a void method with the given ,
optionally specifying arguments for the method call. Use in conjunction with the default
.
The invocation was not call the times specified by
.
The name of the void method to be verified.
An array of types to be substituted for the type parameters of the current generic method definition.
The number of times a method is allowed to be called.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Specifies a verify for a void method with the given ,
optionally specifying arguments for the method call. Use in conjunction with the default
.
The invocation was not call the times specified by
.
The name of the void method to be verified.
The number of times a method is allowed to be called.
Should the parameter types match exactly types that were provided
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Specifies a verify for a void method with the given ,
optionally specifying arguments for the method call. Use in conjunction with the default
.
The invocation was not call the times specified by
.
The name of the void method to be verified.
An array of types to be substituted for the type parameters of the current generic method definition.
The number of times a method is allowed to be called.
Should the parameter types match exactly types that were provided
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
Specifies a verify for an invocation on a property or a non void method with the given
, optionally specifying arguments for the method call.
The invocation was not call the times specified by
.
The name of the method or property to be invoked.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
The number of times a method is allowed to be called.
The type of return value from the expression.
Specifies a verify for an invocation on a property or a non void method with the given
, optionally specifying arguments for the method call.
The invocation was not call the times specified by
.
The name of the method or property to be invoked.
An array of types to be substituted for the type parameters of the current generic method definition.
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
The number of times a method is allowed to be called.
The type of return value from the expression.
Specifies a verify for an invocation on a property or a non void method with the given
, optionally specifying arguments for the method call.
The invocation was not call the times specified by
.
The name of the method or property to be invoked.
Should the parameter types match exactly types that were provided
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
The number of times a method is allowed to be called.
The type of return value from the expression.
Specifies a verify for an invocation on a property or a non void method with the given
, optionally specifying arguments for the method call.
The invocation was not call the times specified by
.
The name of the method or property to be invoked.
An array of types to be substituted for the type parameters of the current generic method definition.
Should the parameter types match exactly types that were provided
The optional arguments for the invocation. If argument matchers are used,
remember to use rather than .
The number of times a method is allowed to be called.
The type of return value from the expression.
Specifies a verify for an invocation on a property getter with the given
.
The invocation was not call the times specified by
.
The name of the property.
The number of times a method is allowed to be called.
The type of the property.
Specifies a setup for an invocation on a property setter with the given
.
The invocation was not call the times specified by
.
The name of the property.
The number of times a method is allowed to be called.
The property value.
The type of the property. If argument matchers are used,
remember to use rather than .
Allows the specification of a matching condition for an
argument in a protected member setup, rather than a specific
argument value. "ItExpr" refers to the argument being matched.
Use this variant of argument matching instead of
for protected setups.
This class allows the setup to match a method invocation
with an arbitrary value, with a value in a specified range, or
even one that matches a given predicate, or null.
Contains matchers for (C#) / (VB.NET) parameters of type .
The parameter type.
Matches any value that is assignment-compatible with type .
Matches a null value of the given type.
Required for protected mocks as the null value cannot be used
directly as it prevents proper method overload selection.
// Throws an exception for a call to Remove with a null string value.
mock.Protected()
.Setup("Remove", ItExpr.IsNull<string>())
.Throws(new InvalidOperationException());
Type of the value.
Matches any value of the given type.
Typically used when the actual argument value for a method
call is not relevant.
// Throws an exception for a call to Remove with any string value.
mock.Protected()
.Setup("Remove", ItExpr.IsAny<string>())
.Throws(new InvalidOperationException());
Type of the value.
Matches any value that satisfies the given predicate.
Type of the argument to check.
The predicate used to match the method argument.
Allows the specification of a predicate to perform matching
of method call arguments.
This example shows how to return the value 1 whenever the argument to the
Do method is an even number.
mock.Protected()
.Setup("Do", ItExpr.Is<int>(i => i % 2 == 0))
.Returns(1);
This example shows how to throw an exception if the argument to the
method is a negative number:
mock.Protected()
.Setup("GetUser", ItExpr.Is<int>(i => i < 0))
.Throws(new ArgumentException());
Matches any value that is in the range specified.
Type of the argument to check.
The lower bound of the range.
The upper bound of the range.
The kind of range. See .
The following example shows how to expect a method call
with an integer argument within the 0..100 range.
mock.Protected()
.Setup("HasInventory",
ItExpr.IsAny<string>(),
ItExpr.IsInRange(0, 100, Range.Inclusive))
.Returns(false);
Matches a string argument if it matches the given regular expression pattern.
The pattern to use to match the string argument value.
The following example shows how to expect a call to a method where the
string argument matches the given regular expression:
mock.Protected()
.Setup("Check", ItExpr.IsRegex("[a-z]+"))
.Returns(1);
Matches a string argument if it matches the given regular expression pattern.
The pattern to use to match the string argument value.
The options used to interpret the pattern.
The following example shows how to expect a call to a method where the
string argument matches the given regular expression, in a case insensitive way:
mock.Protected()
.Setup("Check", ItExpr.IsRegex("[a-z]+", RegexOptions.IgnoreCase))
.Returns(1);
used to replace occurrences of `TAnalog.Member` sub-expressions with `T.Member`.
Enables the Protected() method on ,
allowing setups to be set for protected members by using their
name as a string, rather than strong-typing them which is not possible
due to their visibility.
Enable protected setups for the mock.
Mocked object type. Typically omitted as it can be inferred from the mock instance.
The mock to set the protected setups on.
Kind of range to use in a filter specified through
.
The range includes the to and
from values.
The range does not include the to and
from values.
Defines async extension methods on IReturns.
Specifies the value to return from an asynchronous method.
Mocked type.
Type of the return value.
Returns verb which represents the mocked type and the task of return type
The value to return, or .
Specifies the value to return from an asynchronous method.
Mocked type.
Type of the return value.
Returns verb which represents the mocked type and the task of return type
The value to return, or .
Specifies a function that will calculate the value to return from the asynchronous method.
Mocked type.
Type of the return value.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Mocked type.
Type of the return value.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies the exception to throw when the asynchronous method is invoked.
Mocked type.
Returns verb which represents the mocked type and the task return type
Exception instance to throw.
Specifies the exception to throw when the asynchronous method is invoked.
Mocked type.
Returns verb which represents the mocked type and the valuetask return type
Exception instance to throw.
Specifies the exception to throw when the asynchronous method is invoked.
Mocked type.
Type of the return value.
Returns verb which represents the mocked type and the task of return type
Exception instance to throw.
Specifies the exception to throw when the asynchronous method is invoked.
Mocked type.
Type of the return value.
Returns verb which represents the mocked type and the task of return type
Exception instance to throw.
Allows to specify the delayed return value of an asynchronous method.
Allows to specify the delayed return value of an asynchronous method.
Allows to specify the delayed return value of an asynchronous method.
Allows to specify the delayed return value of an asynchronous method.
Allows to specify the delayed return value of an asynchronous method.
Use the argument to pass in (seeded) random generators used across your unit test.
Allows to specify the delayed return value of an asynchronous method.
Use the argument to pass in (seeded) random generators used across your unit test.
Allows to specify the exception thrown by an asynchronous method.
Allows to specify the exception thrown by an asynchronous method.
Allows to specify the exception thrown by an asynchronous method.
Allows to specify the exception thrown by an asynchronous method.
Allows to specify the exception thrown by an asynchronous method.
Use the argument to pass in (seeded) random generators used across your unit test.
Allows to specify the exception thrown by an asynchronous method.
Use the argument to pass in (seeded) random generators used across your unit test.
Defines async extension methods on IReturns.
Specifies a function that will calculate the value to return from the asynchronous method.
Type of the function parameter.
Mocked type.
Type of the return value.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Type of the function parameter.
Mocked type.
Type of the return value.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Specifies a function that will calculate the value to return from the asynchronous method.
Returns verb which represents the mocked type and the task of return type
The function that will calculate the return value.
Programmable setup used by .
Verifies this setup and those of its inner mock (if present and known).
Specifies whether recursive verification should be performed.
Specifies which setups should be verified.
The set of mocks that have already been verified.
This setup or any of its inner mock (if present and known) failed verification.
Represents a switch, or a combination of switches, that can be either enabled or disabled.
When set via or , they determine how a mock will operate.
The default set of switches. The switches covered by this enumeration value may change between different versions of Moq.
When enabled, specifies that source file information should be collected for each setup.
This results in more helpful error messages, but may affect performance.
Defines the number of invocations allowed by a mocked method.
Deconstructs this instance.
This output parameter will receive the minimum required number of calls satisfying this instance (i.e. the lower inclusive bound).
This output parameter will receive the maximum allowed number of calls satisfying this instance (i.e. the upper inclusive bound).
Specifies that a mocked method should be invoked times
as minimum.
The minimum number of times.
An object defining the allowed number of invocations.
Specifies that a mocked method should be invoked one time as minimum.
An object defining the allowed number of invocations.
Specifies that a mocked method should be invoked times
as maximum.
The maximum number of times.
An object defining the allowed number of invocations.
Specifies that a mocked method should be invoked one time as maximum.
An object defining the allowed number of invocations.
Specifies that a mocked method should be invoked between
and times.
The minimum number of times.
The maximum number of times.
The kind of range. See .
An object defining the allowed number of invocations.
Specifies that a mocked method should be invoked exactly
times.
The times that a method or property can be called.
An object defining the allowed number of invocations.
Specifies that a mocked method should not be invoked.
An object defining the allowed number of invocations.
Specifies that a mocked method should be invoked exactly one time.
An object defining the allowed number of invocations.
Returns a value indicating whether this instance is equal to a specified value.
A value to compare to this instance.
if has the same value as this instance;
otherwise, .
Returns a value indicating whether this instance is equal to a specified value.
An object to compare to this instance.
if has the same value as this instance;
otherwise, .
Returns a hash code for this instance.
A hash code for this instance, suitable for use in hashing algorithms
and data structures like a hash table.
Determines whether two specified objects have the same value.
The first .
The second .
if has the same value as ;
otherwise, .
Determines whether two specified objects have different values.
The first .
The second .
if the value of is different from
's; otherwise, .
Checks whether the specified number of invocations matches the constraint described by this instance.
The number of invocations to check.
if matches the constraint described by this instance;
otherwise, .
Marks a type as a type matcher, optionally specifying another type that will perform the matching.
Type matchers preferably implement themselves. Use the parameterized form of this attribute
where this is not possible, such as when the type matcher needs to be a or
type in order to satisfy generic type constraints of the method where it is used.
Initializes a new instance of the class.
Use this constructor overload if the type on which this attribute is placed implements itself.
Initializes a new instance of the class.
Use this constructor overload if the type on which this attribute is placed does not implement .
The specified type will instead provide the implementation of .
The of a type that implements .
Interface that is used to build fluent interfaces by hiding methods declared by from IntelliSense.
Code that consumes implementations of this interface should expect one of two things:
- When referencing the interface from within the same solution (project reference), you will still see the methods this interface is meant to hide.
- When referencing the interface through the compiled output assembly (external reference), the standard Object methods will be hidden as intended.
- When using Resharper, be sure to configure it to respect the attribute: Options, go to Environment | IntelliSense | Completion Appearance and check "Filter members by [EditorBrowsable] attribute".
See https://kzu.github.io/IFluentInterface for more information.
Redeclaration that hides the method from IntelliSense.
Redeclaration that hides the method from IntelliSense.
Redeclaration that hides the method from IntelliSense.
Redeclaration that hides the method from IntelliSense.
Contains the two extension methods
and
.
Appends a string representation of the specified type to this instance.
The instance to which to append.
The of which a string representation should be appended.
Any combination of formatting options that should be applied. (Optional.)
A reference to this instance after the append operation has completed.
Gets a string representation of this instance.
The of which a string representation is requested.
Any combination of formatting options that should be applied. (Optional.)
A string representation of this instance.
Replacement for
which may be slow or even unavailable on earlier target frameworks.
Allows uniform reflection across all target frameworks.
Allows uniform reflection across all target frameworks.
Allows uniform reflection across all target frameworks.
Allows uniform reflection across all target frameworks.
An enumeration of available options when a name's string representation is requested.
The default type name formatting options.
Specifies that a type's namespace should be included.
For example, the type is formatted as "Action" by default.
When this flag is specified, it will be formatted as "System.Action".
Specifies that anonymous types should not be transformed to C#-like syntax.
For example, the anonymous type of "new { Name = "Blob", Count = 17 }" is formatted as
"{string Name, int Count}" by default. When this flag is specified, it will be formatted as
the raw "display class" name, which looks something like "<>f__AnonymousType5<string, int>".
Specifies that an open generic type's parameter names should be omitted.
For example, the open generic type is formatted as "IEquatable<T>" by default.
When this flag is specified, it will be formatted as "IEquatable<>".
Specifies that primitive types should not be mapped to their corresponding C# language keywords.
For example, the type is formatted as "int" by default.
When this flag is specified, it will be formatted as "Int32".
Specifies that nullable types should not be simplified to C# question mark syntax.
For example, the type of is formatted as "int?" by default.
When this flag is specified, it will be formatted as "Nullable<int>".
Specifies that value tuple types should not be transformed to C# tuple syntax.
For example, the type of ,
is formatted as "(bool, int)" by default. When this flag is specified,
it will be formatted as "ValueTuple<bool, int>".