I have a windows service which recieves messages from a 3rd party service
Each time it recieves a message it updates an in-memory record (held in List<MyObj>) and periodically broadcasts them
I would like to test the state of the List
Options I have come up with are
-
Change the visibility of the List from private to protected. Then make a Test-Specific subclass which has a public property that exposes the state
-
add a public property to the class that is only compiled when in debug mode.
i.e.
#if (DEBUG)
public IList<MyObj> TestProperty
{
get { return _myObj; }
}
#endif
Which is the best solution (or least bad)?
Is there a better way?
*EDIT*
Just found this article which provides a thorough run down of all the options
You have two options:
internalproperty to expose the field and then grant access via theInternalsVisibleToattribute to your test assembly. This way, you can keep encapsulation.PrivateObjectin MSTest orMirrorin MbUnit…).HTH.
Thomas