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
Why does this test pass?

[ img ]

But this test fail?

[ img ]
Code for the above:

The two tests are the same except the first test defines A as a field and the second test defines A as a property.

Is this a bug? If not, what is the right way to work with properties?
asked by Neil (27.7k points)

2 Answers

0 votes
Hi Neil,

Interesting case :). The root cause for this lies in a limitation Isolator has, not being able to record field access. The culprit here is not B, but rather A - A.C is a field, and as such the access to it is not recorded in the WhenCalled() statement. Here's where things get interesting and two negatives balance each other out. The short story - turning C into a property (and allowing it to be recorded) sets everything aright. The full story is below.

What happens in the first case (where A is a field) is that out of the entire b.A.C.ReturnInt() chain, b.A and A.C are field accesses, so only C.ReturnInt() was recorded. C is a valid object (it was constructed with A), so the recording succeeds. In the second case (where A is a property) the case is different: b.A is properly recorded, but A.C is not. We are left with an odd case of the recording consisting of b.A and C.ReturnInt(), which throws Isolator completely off, resulting in the null reference exception. I will look into improving this exception message in this hard to identify situation. Turning C into a property in the second case would mean that the entire chain is properly recorded and behaves as expected.

Hope this helps,
Typemock Support
answered by doron (16.5k points)
0 votes
Thanks for the detailed response doron. Changing A.C to a property made the test pass. I will be sure to not use fields in my WhenCalled calls in the future.
answered by Neil (27.7k points)