Corey Coogan

Python, .Net, C#, ASP.NET MVC, Architecture and Design

  • Subscribe

  • Archives

  • Blog Stats

    • 47,176 hits
  • Meta

Archive for December, 2009

Showing Strong Named Internal Classes to Rhino Mocks

Posted by coreycoogan on December 5, 2009

Other possible titles include:

Rhino Mocks 3.5 Public Key, Rhino Mocks 3.6 Public Key, Rhino Mocks Strong Named Mocking

When you design your code to be testable with a mocking framework like Rhino Mocks, you typically end up marking otherwise private classes as Internal.  This allows you to share your internal classes with test project[s].  To do this, you have to use the InternalVisibleTo assembly attribute in the AssemblyInfo class that you want to share.

[assembly: InternalsVisibleTo(“S2sol.ProjectA.TestProject”)]

This attribute is essentially doing what it says, “Make my stuff that is marked internal visible to the specified class”.  When the project under test is strongly named, for whatever reason, it is also required that you put the public key (not the public key token) of the test project in there with the assembly name.  This to ensure that the internals that are being exposed are only exposed to an assembly that is known.

Rhino Mocks uses Castle’s Dynamic Proxy for mocking.  It creates classes at runtime to act as proxies, or interceptors, whenever you create a mock or stub using MockRepository.Create…  This means that the project under test must verify the dynamic proxy class via the InternalVisibleTo attribute, which means we’ll need the PublicKey for the dynamic assembly. 

I found this somewhere on the web over a year ago and took it for granted until I needed it again today.  After I hunted in some of my old code and found it, seemed like a great post that will surely help someone else out there.  So when you are in this scenario, using Rhino 3.5/3.6, add this to the AssemblyInfo of the component you want to test and you will be good to go:

NOTE: breaks in the public key are intentional for rendering.  It works like this or if the key is one line.

  
//required for Rhino Mocks  
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=00240000048000009"+     
"40000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f" +   
"3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cd" +    
"cf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74" +     
"c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]  

Posted in Alt.Net, C#, Rhino Mocks, TDD | Tagged: , , , , , , | Leave a Comment »

ALT.NET Content in MSDN

Posted by coreycoogan on December 1, 2009

Microsoft has been doing a decent job of including many Alt.net-ish articles in each issue.  Most notably the Jeremy D. Miller articles that have appeared throughout the 2009 year.  The December 2009 issue is following the trend with not one, but two articles from the community.

First, an article on NHibernate from Ayende (Oren Eini).  It’s great to see MS embracing NHibernate and this looks to be a great article (although I haven’t read it yet).

The second article comes from David Laribee, he who coined the term Alt.Net.  He’s written an article on paying back technical debt with Agile techniques, which I’m also looking forward to reading.

Go check it out!

Posted in Agile, Alt.Net, Architecture and Design, NHibernate | Tagged: , , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.