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
0 votes
I have a class with the following members:

private readonly ICollection<string> m_Items = new List<string>();
public ICollection<string> Items { get { return this.m_Items; } }

The instances of this class are faked when using Members.ReturnRecursiveFakes mode. A faked instance contains m_Items set to null, but Items property is set to an empty list. Why does this happen? Shouldn't m_Items field also be assigned an empty list when the instance is faked?

Thanks in advance
asked by vagif (19.4k points)

4 Answers

0 votes
Hi

When you use Members.ReturnRecursiveFakes it affects all methods
and properties of the faked class but not the fields.

Do you see a case where you need the fields to be faked as well?
answered by ohad (35.5k points)
0 votes
Hi

When you use Members.ReturnRecursiveFakes it affects all methods
and properties of the faked class but not the fields.

Do you see a case where you need the fields to be faked as well?


Well, actually I managed to rewrute the class to use properties, and it now works. However I can see that such behavior can cause problems with recursively faked classes. Class implementation may use fields directly and not the properties. As long as fields and properties return different things, the class behavior will be inconsistent.
answered by vagif (19.4k points)
0 votes
Hi Vagif,

We have a planned feature that will cause fields in recursive fakes to contain recursive fakes as well. Expect this in an upcoming version - we'll also let you know specifically when this is ready.

Thanks,
Doron
Typemock support
answered by doron (17.2k points)
0 votes
Thanks doron!
answered by vagif (19.4k points)
...