Is a same method you would use with NMock2, but with “DynamicProxyGenAssembly2″ in InternalsVisibleTo.
This strange name is a default dynamic assembly name used by Castle.DynamicProxy.

Do not forget that the attribute should be added to the assembly with internal types, not to the tests assembly (obvious, but I got it wrong the first time).

Update: yesthatmcgurk has pointed me to the fact that for strongly named assemblies you have to specify the public key as well. So the correct attribute for the strongly named assembly should be

[assembly:InternalsVisibleTo("DynamicProxyGenAssembly2,
PublicKey=002400000480000094000000060200000024000052534
1310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b
3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d926665
4753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb
4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c486
1eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
// without line-breaks
  • Patrick

    Great, I was looking for that everywhere! Thanx!!!

  • Patrick

    Great, I was looking for that everywhere! Thanx!!!

  • Patrick

    Great, I was looking for that everywhere! Thanx!!!

  • Cyr1dian

    Actually the public key makes it _not_ work for me. Same thing happens here: http://groups.google.com/group/moqdisc/browse_t…

    Just using it without the public key solves the problem. Maybe it's a version thing.

    Otherwise very helpful post, thank you!

  • http://markegilbert.wordpress.com/2011/12/07/with-a-little-help-from-my-friends-tdd-mocking-and-internalsvisibleto/ With a little help from my Friends – TDD, Mocking, and InternalsVisibleTo « Mark Gilbert’s Blog

    [...] of course had the answer.  Andrey Shchekin had the solution – DynamicProxyGenAssembly2 (http://blog.ashmind.com/2008/05/09/mocking-internal-interfaces-with-moq/).  Yeah, that was totally going to be my next guess.  [...]