문제

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.

도움이 되었습니까?

해결책 2

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")]

다른 팁

Found and documented the solution.

http://www.rhyous.com/2012/05/03/nmock2-internal-interface/

Turns out that the newer version of NMock2 (I got it here: NMock2 Project) only needs one and it is different.

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top