Mocking Inner Classes with RhinoMocks

So, I have a bunch of inner classes that I'm trying to make fun of with RhinoMocks. I added the following line to assemblyinfo.cs:

[assembly:InternalsVisibleTo(RhinoMocks.StrongName)] 

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

MyTests.SomeTest: System.TypeLoadException: method 'SomeMethod' of type 'SomeType504cf40be6b444abfd417dccf5d6752' from assembly 'DynamicProxyGenAssembly2, Version = 0.0.0.0, Culture = neutral, PublicKeyToken = null' does not override this method.

Please note that I am using the "merged" version of RhinoMocks (and not the "assembly with Castle" boot option). I do not know how Castle was combined with RhinoMocks, but should not make my internal elements visible to RhinoMocks, similarly make it visible to Castle (which is part of Rhino.Mocks.dll)?

+4
source share
2 answers

So, I finally got some time and decided that all I need to do is add the following to AssemblyInfo.cs:

 [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] 
+10
source

Your problem is that RhinoMocks dynamically generates an assembly with dynamic proxies. Thus, your internal visibilities for RhinoMocks do not help. The only possible solution to your problem, I see:

  • Make the classes you want to make fun of publicly.
  • Write a manual layout class in the test project assembly and change the InternalVisibleTo attribute to provide access to the test assembly.
+2
source

Source: https://habr.com/ru/post/1286388/


All Articles