#21 NMock don't work with interfaces with visiblity internal

closed-wont-fix
nobody
None
5
2007-10-12
2007-06-20
Anonymous
No

If you define an interface like:

interface ITest
{
uint GetValue();
}

an try to create a Mock object like:

mocks = new Mockery();
mock = mocks.NewMock<ITest>();

you get an exception by testing with NUnit.
System.TypeLoadException : Access is denied: 'MockTest.Test'.

Discussion

  • Steve Mitcham
    Steve Mitcham
    2007-10-12

    Logged In: YES
    user_id=1572889
    Originator: NO

    The dynamic code generators for .NET cannot violate the visibility rules for assemblies. Since the mocks are put into a dynamic assembly they do not inherit the InternalsVisibleTo setting if you've used it.

    A work around is possible and described at http://blog.ashmind.com/index.php/2007/07/07/mocking-internal-interfaces-with-nmock2

    However, this will probably not work with signed assemblies.

     
  • Steve Mitcham
    Steve Mitcham
    2007-10-12

    • status: open --> closed-wont-fix