Auto-mocking container extension

Jun 27, 2009 at 7:31 AM

I wrote a container extension that auto generates mocks for any interfaces that aren't explicitly registered. I use it for reducing the amount of setup required in test code. You can use it like this:

public void SetUp()
container = new UnityContainer();

public void Should_be_really_easy_to_test()
.Expect(d => d.MyMethod(It.IsAny<int>()))
.Returns("I want to specify the return value");

var service = container.Resolve<ServiceWithThreeDependencies>();
var result = service.DoSomething();

Assert.AreEqual("Look mom, I didn't have to mock the other 2 dependencies!", result);

There is full post with source code here