Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Why did this work in 5.2.1 but not in 5.2.3?

+2 votes
I set up these two mocks:
var intReader = Isolate.Fake.Instance<IRecordsReader>();
            Isolate.WhenCalled(() => intReader.GetDbType()).WillReturn("Integer");

            var ntextReader = Isolate.Fake.Instance<IRecordsReader>();
            Isolate.WhenCalled(() => ntextReader.GetDbType()).WillReturn("Ntext");


But when I run the test I get this error:
TypeMock.VerifyException:
TypeMock Verification: Call to IRecordsReader.GetDbType() Parameter: 1
passed object [Mock0000IRecordsReader]
is not the same instance as expected [Mock0000IRecordsReader].


As stated this worked fine in 5.2.1 but I finally got around to upgrading to 5.2.3 and now the test doesn't work.
Any idea why?
asked Mar 16, 2009 by slace (820 points)

4 Answers

+2 votes
Slace,

Can you post the full test here (or a complete test that recreates the issue)? It seems like a mix up happens somewhere between verification methods, but I need to see the complete scenario to understand what happened.

Thanks,
Doron
Typemock Support
answered Mar 16, 2009 by doron (26,680 points)
+2 votes
Sure, the code isn't super useful as it's a bit out-of-context, but here it is:

var intReader = Isolate.Fake.Instance<IRecordsReader>();
            Isolate.WhenCalled(() => intReader.GetDbType()).WillReturn("Integer");

            var ntextReader = Isolate.Fake.Instance<IRecordsReader>();
            Isolate.WhenCalled(() => ntextReader.GetDbType()).WillReturn("Ntext");

DocTypeObjectBuilder target = new DocTypeObjectBuilder(string.Empty);
            var intProp = target.BuildProperty(intReader);
            var ntextProp = target.BuildProperty(ntextReader);

Assert.AreEqual(typeof(int), intProp.DatabaseType);
            Assert.AreEqual(typeof(string), ntextProp.DatabaseType);



The error is happening on the second time I do Isolate.WhenCalled, I don't get passed there.
answered Mar 16, 2009 by slace (820 points)
+2 votes
slace,

I couldn't recreate the issue from the test code (I tried the first 4 lines before you sent the rest and it worked as well). Would it be possible for you to send our support mailbox a small solution recreating this? The error message itself is very strange and I for one did not encounter this sort of behavior.

Doron
Typemock Support
answered Mar 16, 2009 by doron (26,680 points)
+2 votes
I'll see if i can create it outside of the current project I'm having the bug in (to see if it's reproducable)
answered Mar 17, 2009 by slace (820 points)
...