Get Mock with AutoMock.Create<>()

1.9k views Asked by At

I am using the AutoMock integration of Autofaq and Moq

Is there a way to get a mock from AutoMock.Create<Service>()?

The reason I want this, is to mock some methods of the class under test (Service) like shown here and also keep the automatic creation of mock dependencies.

2

There are 2 answers

0
Sunny Milenov On
var mock = Mock.Get(myMockedService);
mock.Setup(...)
0
GabSP On

A bit late, but in case it could help someone else, if you want to get a mock of your service, you should use AutoMock.Mock(), since AutoMock.Create() returns a "real" instance of your service.

You can see the difference between return types in the doc.
Create: https://autofac.org/apidoc/html/93EE0136.htm Mock: https://autofac.org/apidoc/html/66E87E8B.htm