I have a class that uses 'System.Net.Sockets.Socket' directly for network comunication, and currently I use the following two interfaces to break dependency on the Socket class :
public interface ISocketListener
{
void Listen(int backlog);
ISocket Accept();
void Bind(EndPoint endpoint);
}
public interface ISocket
{
void Connect (EndPoint ep);
Stream CommunicationStream { get; }
void Close();
void Close(int timeout);
void Shutdown();
}
In the production implementation I just redirect all the method calls to the private Socket object. In testing environment I use a MemoryStream as the comunication 'pipe' between the sockets. Since I have little experience in the subject, some questions appeared in my head while writing tests : Are there any 'formal' good practices in testing this kind of software? When doing integration testing, how do I test the performance of this server in multiple connections/high latency situations (more specifically, how to simulate these situations)? Why there are asynchronous versions of Socket.Accept/Socket.Receive? Can I replace the asynchronous methods for handling their synchronous versions in separate threads?