.net - How can I mock an internal interface using NMock2? -


itemprop = "text">

If I try this, I get only one exception:

  System.TypeLoadException: Access is prohibited: 'Namespace'  

Making the interface public is not an acceptable solution. I do not want to change the visibility of my API to check it.

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

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -