You will be interested in this project if you use an IoC container in conjunction with unit tests and mocking (with Moq). You probably find yourself writing setups like:
[SetUp] public void Given() { _service = Mock<IService>(); Container.Register(For<IService>().Instance(service.Object)); } [Test] public void I_did_something() { var test = new TestThingy(); test.DoSomething(); _service.Verify(x => x.Something(), Times.Once(); }
When you use an auto-mocking container, the container will create mocks at resolve-time if it doesn't already have a component for it. So in the above example, the setup would drop out completely as there wouldn't be any need to explicitly create and register the mock:
[Test] public void I_did_something() { var test = new TestThingy(); test.DoSomething(); _service.Verify(x => x.Something(), Times.Once(); }
We will release an alpha version of the Castle.Windsor auto-mocking container later this week. Soon after we will add an Autofac container and start working towards a regular release schedule. If you are interested, visit the site at codeplex and give feedback through the discussion groups.
Happy Mocking!
No comments:
Post a Comment