Question

Here's my scenario.

I need to connect to a TCP Server and receive message from it. The message is encapsulated with start tag and end tag.

I want to implement it in TDD way, but I do not know where to start.

I have been doing the bowling game kata for some days now, but still can't apply it to real world case.

An example of it would be much appreciated.

Thanks.

Was it helpful?

Solution

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top