Skip to content

Latest commit

History

91 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

AutoMoq

AutoMoqer is an "auto-mocking" container that creates objects for you. Just tell it what class to create and it will create it.

But how?

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 ISomething

But why?

Let'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.

Another Example

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());

That's It

It's a simple tool, but it can save a lot of headaches.

About

Auto mocking provider for Moq.

Resources

Code of conduct

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages