Auto mocking provider for Moq.
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.
class NeatoRepository {
public NeatoRepository(ISomething something){
// ..
}
}
var mocker = new AutoMoqer();
var neatoRepository = mocker.Create();
// but what about ISomething?
mocker.GetMock(); // I was injected as ISomethingLet's pretend you did not use AutoMoq and you changed your dependencies:
// I wrote this code in my tests...
var neatoRepository = new NeatoRepository(null);
// ... then I changed my class...
class NeatoRepository {
public NeatoRepository(ISomething something, ISomethingElse somethingElse){
// ..
}
}
// NOW I HAVE TO FIX ALL OTHER REFERENCES TO GET A BUILD
var neatoRepository = new NeatoRepository(null);If you used AutoMoq, this could would always compile:
var neatoRepository = mocker.Create();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:
var mocker = new AutoMoqer();
mocker.GetMock()
.Setup(x => x.GetData())
.Returns("TEST DATA");
var classToTest = mocker.Resolve();
classToTest.DoSomething();
mocker.GetMock()
.Setup(x=>x.CallMe("TEST"), Times.Once());
It's a simple tool, but it can save a lot of headaches.
No open issues yet, or sync has not completed.