AutoMoqer is an "auto-mocking" container that creates objects for you. Just tell it what class to create and it will create it.
It injects mocks as any undefined dependencies.
classNeatoRepository{publicNeatoRepository(ISomethingsomething){// ..}}varmocker=newAutoMoqer();varneatoRepository=mocker.Create<NeatoRepository>();// but what about ISomething?mocker.GetMock<ISomething>();// I was injected as ISomethingLet's pretend you did not use AutoMoq and you changed your dependencies:
// I wrote this code in my tests...varneatoRepository=newNeatoRepository(null);// ... then I changed my class...classNeatoRepository{publicNeatoRepository(ISomethingsomething,ISomethingElsesomethingElse){// ..}}// NOW I HAVE TO FIX ALL OTHER REFERENCES TO GET A BUILDvarneatoRepository=newNeatoRepository(null);If you used AutoMoq, this could would always compile:
varneatoRepository=mocker.Create<NeatoRepository>();Leaving you to just worry about how to change your logic, not your syntax.
The dependencies injected into the class you are testing can be accessed before and/or after you call Create. Like so:
varmocker=newAutoMoqer();mocker.GetMock<IDataDependency>().Setup(x =>x.GetData()).Returns("TEST DATA");varclassToTest=mocker.Resolve<ClassToTest>();classToTest.DoSomething();mocker.GetMock<IDependencyToCheck>().Setup(x=>x.CallMe("TEST"),Times.Once());It's a simple tool, but it can save a lot of headaches.