Class Capture
- Namespace
- Moq
- Assembly
- Moq.dll
Allows to create parameter captures in setup expressions.
public static class Capture
- Inheritance
-
Capture
- Inherited Members
Methods
In<T>(ICollection<T>)
Creates a parameter capture that will store values in a collection.
public static T In<T>(ICollection<T> collection)
Parameters
collectionICollection<T>The collection that will store captured parameter values
Returns
- T
Type Parameters
TThe captured object type
Examples
Arrange code:
var parameters = new List{string}();
mock.Setup(x => x.DoSomething(Capture.In(parameters)));
Assert code:
Assert.Equal("Hello!", parameters.Single());
In<T>(IList<T>, Expression<Func<T, bool>>)
Creates a parameter capture that will store specific values in a collection.
public static T In<T>(IList<T> collection, Expression<Func<T, bool>> predicate)
Parameters
collectionIList<T>The collection that will store captured parameter values
predicateExpression<Func<T, bool>>A predicate used to filter captured parameters
Returns
- T
Type Parameters
TThe captured object type
Examples
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());
With<T>(CaptureMatch<T>)
Creates a parameter capture using specified CaptureMatch<T>.
public static T With<T>(CaptureMatch<T> match)
Parameters
matchCaptureMatch<T>
Returns
- T
Type Parameters
TThe captured object type
Examples
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);