• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 15 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Auto mocking provider for Moq.

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.

More Repositories

1

csharp-sparkpost

C# Client Library for SparkPost Email Service
C#
55
star
2

AutoMapperAssist

Assists using and testing AutoMapper.
C#
15
star
3

SpecFlowAssist

Spec Flow assistance
C#
10
star
4

AppBus

Application bus, heavily inspired by MvcContrib but TDD'd up myself
C#
6
star
5

Shoon

A simple SQL denormalizer for Simple CQRS
C#
5
star
6

simple_data_and_specflow_sample

A sample showing how Simple.Data can be used in SpecFlow specs
C#
4
star
7

starting_blocks

Run your minitest tests & specs immediately, with no setup or project edits.
Ruby
4
star
8

lemonade_stand

Ruby
4
star
9

CastAs

Casting for people who read left-to-right
C#
3
star
10

MvcTurbine.MembershipProvider

Easy membership provider for MVC Turbine
C#
3
star
11

xml_hate

Reading XML with my own ten-foot poll.
Ruby
2
star
12

kcruby_rtanque

Ruby
2
star
13

twitter_huginn_agents

Ruby
2
star
14

subtle

A few subtle twists to make my Ruby even more concise.
Ruby
2
star
15

MembershipProviderSample

A simple demonstration of MvcTurbine.MembershipProvider.
JavaScript
2
star
16

MvcTurbine.GoogleSiteMap

A google site map for MvcTurbine
C#
2
star
17

MvcTurbine.Diagnostic

A simple diagnostics tool.
C#
1
star
18

seam

Ruby
1
star
19

thirty

Helpful conventions for IoC registration.
C#
1
star
20

mathstuff

Math functions for jquery
JavaScript
1
star
21

dockerfiles

My dockerfiles
Shell
1
star
22

panic_board_data

Export data to Panic Board
Ruby
1
star
23

MvcTurbine.MetadataProvider

Metadata Provider for MVCTurbine
C#
1
star
24

SimpleCaching

A very simple library for caching in memory.
C#
1
star
25

MvcTurbine.AppBus

A MvcTurbine blade for AppBus
C#
1
star
26

MvcTurbine.FluentValidation

A FluentValidation blade for MvcTurbine.
C#
1
star
27

MVCTurbine-IoC-Demo

A demo MVC Turbine V3 project that shows benchmarks for the main .Net IoC containers
JavaScript
1
star
28

three

A simple authorization gem
Ruby
1
star
29

seam-mongodb

MongoDB support for seam
Ruby
1
star
30

huginn_agent

Huginn Agents WIP
Ruby
1
star
31

freeboard-rails

Rails engine for freeboard (no affiliation with freeboard)
JavaScript
1
star
32

SimpleCQRSDemo

A simple, SimpleCQRS demo. Watch the screencast at: http://bit.ly/g3C7fV (Part1) and http://bit.ly/eFAXvN (Part 2)
C#
1
star
33

elixir_katas

trying katas in elixir
Elixir
1
star
34

leankitkanban_mobile

Mobile app for Lean Kit Kanban.
Ruby
1
star
35

horse_rails

horse rails
Ruby
1
star
36

ghsb

github api + panic statusboard
Ruby
1
star
37

MvcTurbine.Laziness

Adds ILazy<T> to your IoC of choice.
C#
1
star
38

proof_of_concept_huginn_agents

Proof of concept: Stand-alone Huginn agents
Ruby
1
star
39

NebCC_CompositeMVC_Example

This is a copy of the "composite" version of the MVC Music Store project I presented at the 2011 Nebraska Code Camp.
JavaScript
1
star
40

halitosis

Ruby
1
star