Quickstart Guide

Include the right using statement for the container you wish to use.

using MoqContrib.AutoMock.Castle;

Then create a container and use it

var container = new AutoMockContainer();

// the ShoppingCart class takes an IFinanceSystem as a dependency in the constructor
container.Mock.Of<IFinanceSystem>().SetupGet(x => x.IsNewCustomer).Returns(false);

// Build the shoppingCart (Subject Under Test or SUT) with all dependencies injected as mocks
var shoppingCart = container.Mock.CreateSut<ShoppingCart>();

// generate a mock. The container holds a reference to it, so you don't have to

// now the method we're testing

// Time for verifications
container.Mock.Of<SaleItem>().VerifyGet(x => x.Price);

// ShoppingCart also has a dependency on IShippingSystem that was mocked
// when we created the SUT. It didn't require setups, but we want to verify something.
container.Mock.Of<IShippingSystem>().Verify(x => x.SendShipment(It.IsAny<Address>()));

The container interface

MoqContrib ships with AutoMocking IoC containers for Castle and Autofac (and more to come soon). The AutoMockContainer extends the container that you would normally use.

Last edited Apr 22, 2011 at 3:32 PM by tkellogg, version 2


No comments yet.