views:

19

answers:

1

If I try this, I just get an exception:

System.TypeLoadException : Access is denied: 'Namespace.IInternalInterface'.

Making the interface public is not an acceptable solution. I don't want to change the visiblity of my API in order to test it.

A: 

I found the answer to this:

NMock2, (and other mocking frameworks). Will create the mock objects in dynamically generated assemblies. In order for the mocking framework to create the mock object, the internals should be visible to these assemblies.

Just add the following declarations to the AssemblyInfo.cs class for the Module Under Test:

// Allow unit test and mock assemblies to see internal members.
[assembly: InternalsVisibleTo("MyAssembly.UnitTest")]
[assembly: InternalsVisibleTo("NMock2")]
[assembly: InternalsVisibleTo("Mocks")]
[assembly: InternalsVisibleTo("MockObjects")]
Matt Brunell