Create(T) Method (Object[])

Moq

Collapse image Expand Image Copy image CopyHover image
Creates a new mock with the default MockBehavior specified at factory construction time 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>(
	params Object[] args
)
where T : class

Parameters

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

CopyC#
var factory = new MockFactory(MockBehavior.Default);

var mock = factory.Create<MyBase>("Foo", 25, true);
// use mock on tests

factory.Verify();

See Also