Pages

Monday 7 December 2009

Moq Setup Causes Compiler Error CA1506

I have been using Moq to help enable some unit tests and I've been getting intermittent build exceptions caused by the Code Analysis engine when calling the Setup method of my new mock object.

Example:

var mock = new Mock<IDoSomething>();

mock.Setup(x => x.DoSomething());

CA1506 is raised as a warning to Avoid excessive class coupling. This is, obviously, a little strange. Stranger still is that this warning results in a compilation error.

Anyway, it's a bug in Visual Studio. The workaround is just to remove this check from your Code Analysis (goto Project Properties | Code Analysis | Maintainability Rules and uncheck CA1506).

No comments:

Post a Comment