mocking - C# set value of private variable -


this private value want set

 private phaselist stages; 

this test

    mockrepository mocks = new mockrepository();         mocks.stub<useraction>();         game g = new game(players, cardlist);         type stage = typeof(phaselist);         fieldinfo stinfo = stage.getfield("stages",         bindingflags.nonpublic | bindingflags.instance);          phaselist p = new phaselist();         p.add(new discardphase(players[0]));         p.add(new discardphase(players[0]));         stinfo.setvalue(g, p);         g.processuserinput(0, mocks.stub<useraction>()); 

i error:

system.nullreferenceexception: object reference not set instance of object. 

it points line:

stinfo.setvalue(g, p); 

i dont understand why stinfo=null;

can me?

you're attempting type of phaselist class, , private field inside named stages. doesn't have field named "stages", i'm assuming, null.

what do have field named "stages" in other class that's potentially instance of phaselist class.

type stage = typeof(whatever_class_has_the_stages_field_in_it);  fieldinfo stinfo = stage.getfield("stages", bindingflags.nonpublic | bindingflags.instance); 

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -