The Auto Mocking Container

time to read 2 min | 331 words

Several months ago the guys from Eleutian released the Auto Mocking Container, a combination of Rhino Mocks and Windsor container. I looked at it at the time, and I liked it, but I didn't really get a chance to work with it until recently.

You can see how a non trivial controller may look like on the left. It has a fair number of collaborators, for data access, logging, notifications, etc.

This approach make building the controller very easy:

imagepublic void DisplayOrdersForApproval()
	if (AuthorizationService.AllowedToApproveOrders() == false)

	PropertyBag["orders"] = Orders.FindAll(
		Where.Order.Status == OrderStatus.WaitingForApproval &&
		Where.Order.Department == CurrentUser.Department

public void RejectOrder(Order order)
	Logger.Info("User {0} had rejected order {1}.", 
		CurrentUser.Name, order.Id);
	order.Stutus = OrderStatus.Rejected;

public void ShipOrder(Order order)
	Logger.Info("User {0} had approved order {1}.",
		CurrentUser.Name, order.Id);


The controller is merely coordinating the work of services in the application, which is what I think it should do. But how do I test such a thing? Setting up seven collaborators per tests is a PITA, and it gets worse if you consider additional dependencies that may be required by the base class.

Enter the Auto Mocking Container, which makes all of this a real pleasure, check this out:

public void RejectingAnOrderWillSendNotification()
	AutoMockingContainer container = new AutoMockingContainer(Mocks);
	OrderApprovalController controller = container.Create<OrderApprovalController>();
	Order order = new Order();
	INotificationService mockedNotificationService = container.Resolve<INotificationService>();

	using (Mocks.Replay())
	using (Mocks.Playback())

There are a lot of interesting options on the Auto Mocking Container that I suggest that you will check out. I really like it.