.net - How can I mock an internal interface using NMock2? -
If I try this, I get only one exception: Making the interface public is not an acceptable solution. I do not want to change the visibility of my API to check it.
System.TypeLoadException: Access is prohibited: 'Namespace'
I found the answer:
Nmk 2, (and other funky frameworks) Will create mock objects in dynamically-generated assemblies. In order to make the fake item order for the funky structure, the internal should be visible to these assemblies
Just add the following declarations to the AssemblyInfo.cs class for the module under Test.
// Allow unit testing and mock assemblies to view internal members. [Assembly: InternalsVisibleTo ("MyAssembly.UnitTest")] [Assembly: InternalsVisibleTo ("NMock2")] [Assembly: InternalsVisibleTo ("Mocks")] [Assembly: InternalsVisibleTo ("MockObjects")]
Comments
Post a Comment