Moq |
MockFactory..::..Create<(Of <(<'T>)>)> Method (MockBehavior, array<Object>[]()[][]) |
MockFactory Class Example See Also Send Feedback |
Creates a new mock with the given behavior
and with the the given constructor arguments for the class.
Namespace: Moq
Assembly: Moq (in Moq.dll) Version: 4.0.10827.0 (4.0.0.0)
Syntax
C# |
---|
public Mock<T> Create<T>( MockBehavior behavior, params Object[] args ) where T : class |
Parameters
- behavior
- Type: Moq..::..MockBehavior
Behavior to use for the mock, which overrides the default behavior specified at factory construction time.
- args
- Type: array<System..::..Object>[]()[][]
Constructor arguments for mocked classes.
Type Parameters
- T
- Type to mock.
Return Value
A new Mock<(Of <(<'T>)>)>.Remarks
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.
Examples
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:
CopyC#
var factory = new MockFactory(MockBehavior.Default); var mock = factory.Create<MyBase>(MockBehavior.Strict, "Foo", 25, true);