views:

498

answers:

2

So I have a bunch of internal classes which I am trying to mock with RhinoMocks. I have added the following line to assemblyinfo.cs:

[assembly:InternalsVisibleTo(RhinoMocks.StrongName)]

However, this still does not allow me to mock internal classes; I get the following error message from NUnit:

MyTests.SomeTest: System.TypeLoadException : Method 'SomeMethod' on type 'SomeType504cf40be6b444abfd417dccf5d6752' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is overriding a method that is not visible from that assembly.

Note that I am using the 'merged' version of RhinoMocks (rather than the download option 'with Castle assemblies'). I don't know how Castle was merged into RhinoMocks but shouldn't making my internals visible to RhinoMocks, similarly make it visible to Castle (which is part of the Rhino.Mocks.dll)?

+2  A: 

Your problem is that fact that RhinoMocks dynamically generates an assembly with dynamic proxies. So making your internals visible to RhinoMocks does not help. The only possibly solutions to your problem I see are:

  1. Make the classes you wish to mock public.
  2. Write a mock class by hand in your test projects assembly and modify your InternalVisibleTo attribute to grant your test assembly access.
Bas Bossink
+3  A: 

And so I finally got some time and worked out that all I needed to do was to add the following to AssemblyInfo.cs:

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
jpoh