In an attempt to DRY up my unit tests, I'm trying to use AutoFixture as an IoC container to instantiate my system under test (SUT), which in this particular case are ASP.NET MVC Controller
s. Therefore, I want to customize AutoFixture to create controllers without auto-properties.
I tried adding a customization for ControllerBase
, but it doesn't seem to work for subclasses of ControllerBase
.
fixture.Customize<ControllerBase>(c => c.OmitAutoProperties());
Here's an example of the test I want to be able to write:
[Theory, AutoFixtureData]
public void ControllerTest(AccountController controller) {
Assert.Equal(default(UrlHelper), controller.Url);
}
Naturally, it works if I manually add one customization for each specific controller in my project, but who wants to do that? Is there a better way?