identify a solid pattern to abstract a network layer to allow testability <p>I've read various questions here on the argument like</p> <p><a href="http://stackoverflow.com/questions/741981/how-do-you-unit-test-a-tcp-server-is-it-even-worth-it">How do you unit-test a TCP Server? Is it even worth it?</a></p> <p>and others more specific questions as</p> <p><a href="http://stackoverflow.com/questions/1263581/has-anyone-successfully-mocked-the-socket-class-in-net">Has anyone successfully mocked the Socket class in .NET?</a></p> <p><a href="http://stackoverflow.com/questions/8092182/rhino-mocks-how-to-build-a-fake-socket">rhino mocks: how to build a fake socket?</a></p> <p>but I anyway feel to post the question.</p> <p>I need to design an <strong>abstract network layer</strong>. It should be abstract to decouple consumer code from depending upon a specific implementation and, last but not least, be completely testable with fakes.</p> <p>I'm ended up that I don't need to mock a <code>Socket</code> class, but rather define am higher level abstraction and mock it.</p> <pre><code>interface INetworkLayer { void OnConnect(Stream netwokStream); void OnException(Exception e); // doubts on this } </code></pre> <p>Has anyone done something close to this that can provide observations, comments or explain how may look the right direction?</p>