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
Is there a way to set a { get; private set; } property? I am aware of PrivateObject.SetProperty() but am wondering if there is an Isolator way to do this.

Object.SetField() does not do it:

[ img ]
asked by Neil (27.7k points)

3 Answers

0 votes
Hi Neil,

ObjectState is designed to control non-public fields, rather than properties. Isolator can control oroperties are just like methods, so you can use Isolator's non-public API:
A a = new A();
Isolate.NonPublic.Property.WhenGetCalled(a, "A").WillReturn(10);


Hope this helps,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Neil,

I just noticed that your property is in fact public - the API I showed in my previous post is the non-public API. It will still work, but you can use the type-safe public API instead:
A a = new A();
Isolate.WhenCalled(() => a.X).WillReturn(10);


Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Hi doron,

I had forgotten about WhenCalled().WillReturn(). Thanks.
answered by Neil (27.7k points)
...