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
Hello,

One of our developers had code that in 5.2.1 ran successfully.

UserDS.UserRow usr = Isolate.Fake.Instance<UserDS>();
Isolate.WhenCalled(() => usr.CountryCode).WillReturn("DEU");

var fakeDataReader = Isolate.Fake.Instance<DataReader>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => fakeDataReader.User(userID).User[0]).WillReturn(usr);
Isolate.Swap.NextInstance<DataReader>().With(fakeDataReader);


UserDS is a dataset of user records. "CountryCode" is one if its columns.

After upgrading to version 5.2.2 he received the following exception:

TypeMock.TypeMockException :
*** The call to System.Text.RegularExpressions.ExclusiveReference.Get() was made on an uninitialized field.
Tests.TestAccountManager.<>c__DisplayClass45.<ChooseFunding_WithOneBankAccountsAndOneExpiredCreditCard_ReturnsCreditCard>b__42()
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)

He suspected that this was because chained call:
fakeDataReader.User(userID).User[0]

so he changed the code:

UserDS fakeds = Isolate.Fake.Instance<UserDS>();
Isolate.WhenCalled(() => fakeds.User[0]).WillReturn(Isolate.Fake.Instance<UserDS>());
Isolate.WhenCalled(() => fakeds.User[0].CountryCode).WillReturn("DEU");

var fakeDataReader = Isolate.Fake.Instance<DataReader>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => fakeDataReader.User(userID)).WillReturn(fakeds);
Isolate.Swap.NextInstance<DataReader>().With(fakeDataReader);


Now the code works, but he need to fake Dataset and Datarow separately. Before he managed with only faked row that he actually needed.

UPDATE. Previously I listed other failures related to SqlException, but they were caused by incorrect installation. Still the bug listed above remains.
asked by (19.4k points)

6 Answers

0 votes
I'll need a repro to further investigate this issue - let's take it offline
answered by (11.9k points)
0 votes
I think that the part of the problem is an old bug that was previously fixed. I reported it earlier: https://www.typemock.com/community/viewtopic.php?t=1127

When it comes to other things, I am ready for offline talk at vagif@contopronto.com
answered by (19.4k points)
0 votes
Disregard my bug report about SqlException problem. I've rerun the tests, and they worked fine. But the problem listed in the original message (failed Dataset/Datarow mocking when switching from 5.2.1 to 5.2.2) still remains.
answered by (19.4k points)
0 votes
Let's take it offline - Please send me a project that show the problem.
answered by (11.9k points)
0 votes
Hello again,

I tried to reproduce the failed behavior in a sample project (sending the original solution was not an option since it had too many external dependecies) and found that problem was in fact caused by improperly implemented class on our side. The class was rewritten long ago, but the developer that found a problem worked on an old branch for a legacy project.

I can report now that all our tests work. Sorry for the false alarm.
answered by (19.4k points)
0 votes
Same Typemock Exception is reproduced in this thread
https://www.typemock.com/community/viewt ... 81&forum=5
answered by (800 points)
...