make your server implement something like IServer
, let's say with event SendData
.
Have your client side class with injectable server. Example:
public class client{
readonly IServer _server;
public client(IServer server){this._server = server;}
}
All that remains is creating a client
object
with a mock
IServer
in your tests.
Note: this is testing the behavior of your client, not testing network.
Also, to do TDD, start with a test method like this:
[TestMethod]
public void ClientReceivesData()
{
var mockServer = new Mock<IServer>();//fails, makes you create the interface
var client = new Client(mockServer.Object); // fails, makes you create client
mockServer.Raise(s=>s.SendData+=null).Returns("test");
// makes you create an event in the interface. Please check the syntax
client.Listen();
//makes you have some code on the client side to listen to server data.
Assert.AreEqual("test", client.ReceivedData);// one of the many ways of asserting
}