Popularity
3.5
Growing
Activity
0.0
Stable
191
11
43

Description

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

Programming language: C#
License: MIT License
Tags: Testing     Mocking     Moq    
Latest version: v2.0.0

AutoMoq alternatives and similar packages

Based on the "Testing" category.
Alternatively, view AutoMoq alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of AutoMoq or a related project?

Add another 'Testing' Package

README

AutoMoq

Build Status

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.

class NeatoRepository {
  public NeatoRepository(ISomething something){
    // ..
  }
}

var mocker = new AutoMoqer();

var neatoRepository = 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...
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<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:



   var mocker = new AutoMoqer();

   mocker.GetMock<IDataDependency>()
      .Setup(x => x.GetData())
      .Returns("TEST DATA");

   var classToTest = 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.