Code Monkey home page Code Monkey logo

automoq's Introduction

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.

automoq's People

Contributors

darrencauthon avatar issafram avatar dansweeting avatar victorarias avatar kayone avatar

Watchers

Kenneth Cochran avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.