views:

34

answers:

1

What is the recommended way to unit test an object that publishes via NamedPipeServerStreams?

My thought was to use a NamedPipeClientStream in the unit test but the test just ends up hanging; I suspect this is due to both of them being in the same process.

+1  A: 

I would write an interface that abstracts away the hard to test parts of the named pipe.

The implementation of this would be fairly straightforward (using the NamedPipe... apis) and I wouldn't unit test that.

Once thats done I use the interface in the application code. I'd have a mock implementation in the test code and I would use the mock object to do stuff on the pipe.

E.g. my interface would have a ClientConnected event exposing some data about the client.

I'd then implement this interface in a mock object and have it raise the client connected event and assert that the application did the correct things when the client was connected.

HTH.

obelix