c# - How to unit test a class derived from NetworkStream? -



c# - How to unit test a class derived from NetworkStream? -

as part of project have class derives networkstream. in case provides wrapped implementations of methods such read , readbyte provide context specific safety (it calls base of operations methods additional logic).

but testing issue. class requires socket in constructor (concrete type) , mocking not work me (using moq here, perhaps typemock would, avoid costly tooling).

another alternative might compose rather inherit, , create class wraps networkstream , implements own interface similar networkstream. problem. consumers of streams in bcl such streamreader etc. require concrete stream or derived type, , hence not work composed class.

so, can think of alternatives? it's not i'd sense happy leaving without decent coverage - it's area much go wrong, , should solid.

you might want take @ pex , moles project http://research.microsoft.com/en-us/projects/pex/ . more moles part. here's direct link getting started. http://research.microsoft.com/en-us/projects/pex/molestutorial.pdf

c# unit-testing networkstream

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -