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
i have the following test code:
        public abstract class Database 
            public virtual System.Data.IDataReader ExecuteReader(System.Data.Common.DbCommand dbCmd)
                return null;

            public  System.Data.Common.DbCommand GetSqlStringCommand(string p)
                return null;

        public void TypeMockFailureTest()
            Database dataBase = (Database)RecorderManager.CreateMockedObject(typeof(Database));
            System.Data.Common.DbCommand dbCmd = (System.Data.Common.DbCommand)RecorderManager.CreateMockedObject(typeof(System.Data.Common.DbCommand));
            using (RecordExpectations recorder = RecorderManager.StartRecording())
                // CAUTION: ALL calls here are mocked!!!

                dataBase.GetSqlStringCommand("bla bla");

            System.Data.Common.DbCommand cmd = dataBase.GetSqlStringCommand("bla bla");
            System.Data.IDataReader reader = dataBase.ExecuteReader(cmd);

This UnitTest Code fails with
TypeMock Verification: Unexpected Call to UnitTests.TypeMockTest+Database.GetSqlStringCommand().

It happenes in recording stage.
The problems goes away if we remove the two attributes over “Database” class.

If we leave only the “ConfigurationNameMapper” attribute, the unittest fails with:

Test method UnitTests.TypeMockTest.TypeMockFailureTest threw exception: TypeMock.TypeMockException:
*** Cannot return a value for AssemblyResolver.OnResolve() because no value was set. use recorder.Return().
*** Note: Cannot mock types from mscorlib assembly..

It is clearly a bug.
I use Microsoft Enterprise Library 3.1, Data Access Application Block (although DAAB is not involved in the failed code...)

can you suggest a fix or a workaround? i need to be able to mock a database object and excpect calls.

thank you.
asked by mod (5.8k points)

3 Answers

0 votes

Regarding the first problem you have, we are not sure why this is happening we will need to investigate and see why this is happening. Can you describe in short what is the purpose of the two attributes?

The other problem you reported is something that was encountered before and fixed. The fix for this is included in the 4.2.1 beta which can be downloaded here
answered by lior (13.2k points)
0 votes
first, thanks for the quick answer.

these attributes, are standard attributes of the enterprise library.
i actually don't know what they're for, because I've just copied them from the class i was trying to mock.

the actual class i'm trying to mock is not the one appearing in the code i wrote, but the Data Access Application Block's 'Database' class, which has these two attributes.
i guess they're important to the correct operation of the class.

hope you'll find a workaround soon :)
answered by mod (5.8k points)
0 votes
quick question.
Which version are you running with?

Im having trouble reproducing the issue with our latest version.
answered by lior (13.2k points)