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
How would I mock the following variable?

public static class IncHolder 
{
private static Inc _Parent;
//...
}

asked by trp (4.1k points)

2 Answers

0 votes
Hi Tom

Currently there's no way to fake fields in the AAA API
The alternatives are:
1. Wrap the field with property and use only the property when accessing the field. I think this is the best choice putting the testing issue aside, If you'll want to add some logic in the future when accessing the field you'll have to change the code only in one place.

2. Use ObjectState
The ObjectState class will let you change values of fields.
ObjectState state = new ObjectState(typeof(IncHolder));
state.SetField("_Parent", 5);
answered by ohad (35.5k points)
0 votes
I made the variable a property instead of a variable and that works fine now.

Thanks!
answered by trp (4.1k points)
...