c# - Testing behavior of a derived class in isolation -


i'm attempting isolate , test particular class in existing code base derived base , has private class member want mock:

public class derived : base  {     protected something<other> _othersomething = new something<other>(); } 

specifically, i'd use tests verify derived raises event dosomething in response _othersomething raising ithappened event.

in attempt accomplish this, created in test project mockedderived class derived:

public class mockderived : derived {    public something<other> othersomething     {        set { _othersomething = value; }     } } 

i'm using nsubstitute part of mstest test method mock out class , want so:

[testmethod] public void testmethod1() {    var sub = substitute.for<something<other>>();    mockedderived md = new mockedderived();    bool wasraised = false;    md.dosomething += (sender, args) => wasraised = true;    md.othersomething = sub;    sub.ithappened += raise.event<ithappenedeventhandler<other>>(new ithappenedeventargs<other>());    assert.istrue(wasraised); } 

where i'm having difficulty in there fair amount of baggage base class brings table, namely creates objects of other classes , have timers , involve database.

it gets messy.

and want ensure derived class exhibits particular behaviors , responds expected.

any suggestions on how isolate testing of derived behavior messy base , various members? perhaps i'm not seeing obvious solution.

you facing situation of testing legacy code base class takes in concrete dependencies rather depending on interfaces. might want refer sprout method , sprout classes described in michael feather's book "working legacy code".


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -