chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
We are currently investigating if we should use Natural mocks instead of Reflective mocks. The simple syntax and the ability to mock "chained calls" are really nice. However, one of our tests failed when we changed it from using reflective mocks to natural mocks.

The test can easily be reproduced. Just mock System.Data.OracleClient.OracleConnection like this:

        [TestMethod, VerifyMocks]
        public void OracleConnectionNatural() {
            using (RecordExpectations r = new RecordExpectations()) {
                OracleConnection moc = new OracleConnection();
            }
            OracleConnection oc = new OracleConnection();
        }


When the test is run an exception is thrown:

System.TypeInitializationException: The type initializer for 'System.Data.OracleClient.OracleConnection' threw an exception. --->  System.TypeLoadException: Method 'GetConnectionPoolGroup' on type 'MockDbConnectionFactory' from assembly 'DynamicMockAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a0857b23fb3f20d9' is overriding a method that is not visible from that assembly..


at System.Reflection.Emit.TypeBuilder._TermCreateClass(Int32 handle, Module module)
   at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
   at System.Reflection.Emit.TypeBuilder.CreateType()
   at az.a(Type A_0, Object[] A_1)
   at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
   at TypeMock.MockManager.MockObject(Type type, Object[] args)
   at TypeMock.Mock.b(String A_0)
   at TypeMock.Mock.h()
   at TypeMock.RecorderManager.a(String A_0, String A_1, Object A_2, Type A_3, Boolean A_4)
   at TypeMock.RecorderManager.a(String A_0, String A_1, Object A_2, Object[] A_3, MethodBase A_4, Object A_5, StackTrace A_6)
   at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
   at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
   at System.Data.OracleClient.OracleConnection..cctor()
 --- End of inner exception stack trace ---
    at System.Data.OracleClient.OracleConnection..ctor()
   at LibraryTest.QueueTest.OracleConnection() in C:workspacesTypeMock2005LibraryTestQueueTest.cs:line 97
   at TypeMock.VerifyMocksAttribute.Execute()
   at TypeMock.MethodDecorator.e()
   at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
   at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)


I'm aware that the example is not really useful as a test, but I have removed the test code itself to illustrate the problem. Just mocking the constructor is enough to trigger the exception. The odd thing is that when we use reflective mocks to mock the OracleConnection we don't see the problem:

        [TestMethod, VerifyMocks]
        public void OracleConnectionReflective() {
            Mock moc = MockManager.Mock<OracleConnection>(Constructor.Mocked);
            OracleConnection oc = new OracleConnection();
        }


Please comment.
asked by brian.rasmussen (7.2k points)

3 Answers

0 votes
Hi Brian
I tried to re-create the problem (on VS5005 and VS2008) but it without success.
Can you please send me the logs?
I'll send you a mail with my address offline.
answered by ohad (35.4k points)
0 votes
Ohad,

I was getting this exception (and some other interesting behavior) when mocking SqlConnection so I created a reproduction for it and sent it to support back on 2/6/08. Check with Lior; he followed up with me and said he'd check it out. I have not heard a resolution.
answered by tillig (6.7k points)
0 votes
Hi Travis
Thanks for the info.
I'll check it out.
answered by ohad (35.4k points)
...