chaliasos
chaliasos

Reputation: 9783

Get Mock with AutoMock.Create<>()

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.

Upvotes: 0

Views: 2163

Answers (2)

GabSP
GabSP

Reputation: 53

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

Upvotes: 1

Sunny Milenov
Sunny Milenov

Reputation: 22310

var mock = Mock.Get(myMockedService);
mock.Setup(...)

Upvotes: 0

Related Questions