moqautofacautomockingautomoq

What is the purpose of Autofacs AutoMock


Hi I just started learning how to use an IOC Container. I picked Autofac and was registering services to inject into my MVC controllers.

Now I want to do Unit Test. I know that moq is to mock up dependencies that my controller needs. But then what is AutoFac's AutoMock for? What advantage would I have?

I noticed that the containerbuilder from AutoMock.GetLoose() has no knowledge of the registrations from the main project.


Solution

  • It is basically just a wrapper for Moq that automatically helps you creating the class you want to test and will inject all required mock-instances into that class.

    It makes unit-testing easier because whenever you add another dependency to the constructor of the class under test, you basically don't have to manually create another mock. You will only need to setup behavior, if required.

    The documentation is quite good, I'd advice you to look into that.