Hello,
Recently I had to find out, that creating mocked objects for internal interfaces fails. It does not matter wheter the interface is placed in the same assembly as the test-code or in an other one using the InternalsVisibleToAttribute.
Steps to Reproduce:
1. Insert the following interface in your TestProject (non-nested):
internal interface ITest
{
void BlaBlubb();
}
2. Try to create a mocked object using either
MockObject MockedInternalInterface = MockManager.MockObject(typeof(ITest), false);
ITest Test = (ITest)MockedInternalInterface.Object;
or
ITest Test = (Itest)RecorderManager.CreateMockedObject(typeof(ITest));
Expected Results:
-> Test should contain the mocked object derived from the given interface.
Actual results:
-> The following TypeLoadException is thrown:
Der Typ Mocktest in der Assembly DynamicMockAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null versucht, eine Schnittstelle zu implementieren, auf die nicht zugegriffen werden kann.
bei System.Reflection.Emit.TypeBuilder.TermCreateClass(Int32 handle, Module module)
bei System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
bei System.Reflection.Emit.TypeBuilder.CreateType()
bei t.a(Type A_0, Object[] A_1)
bei TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
bei TypeMock.MockManager.MockObject(Type type, Object[] args)
bei TypeMock.RecorderManager.CreateMockedObject(Type typeToMock)
bei epiSource.Common.SystemImageListTest.Init() in D:ProjekteSrcMeine Projektes2005ProjectsepiSource.CommonepiSource.WinAPITestManagedSystemImageListTestSystemImageListTest.cs:Zeile 32.
Workaround:
Create an (internal or public) class derived from ITest. Nearly no code needs to be written, as Visual Studio does this using the implement interface feature. This class can now be mocked.[/quote]