Skip to content

Commit

Permalink
updated tests to include testing client->server message sending
Browse files Browse the repository at this point in the history
  • Loading branch information
shanetrotter committed Jun 27, 2009
1 parent bf82060 commit d1d3f7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions QuickFIX.NET/QuickFIX.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Compile Include="Session.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Transport\SocketConnector.cs" />
<Compile Include="Transport\SocketInitiator.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
17 changes: 16 additions & 1 deletion UnitTests/SocketInitiatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace UnitTests
public class SocketInitiatorTests
{
[Test]
public void TestConnect()
public void TestConnectAndReceive()
{
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
TcpListener listener = new TcpListener(localAddr, 56123);
Expand All @@ -32,13 +32,28 @@ public void TestConnect()
i.Start();

Thread.Sleep(100);
// Server sends initiator a message.
_clientSocket.Send(Encoding.UTF8.GetBytes("TESTING123\n"));
Thread.Sleep(100);

// Assert that the initiator is connected and receives it.
Assert.That(_clientSocket.Connected, Is.True);
Assert.That(i.Connected, Is.True);
Assert.That(_lastReceived, Is.EqualTo("TESTING123"));

// Send message from initiator to server.
string testSend = "TESTING456";
i.Send(testSend);

byte[] r = new byte[256];
_clientSocket.Receive(r);
string received = Encoding.UTF8.GetString(r);
Thread.Sleep(100);

// Assert that dummy server receives our test message.
// Note the substring, our dummy TcpListener is only receiving raw socket blocks of 256 bytes,
// so we only assert that what we sent is contained in the first part of the 256 byte block.
Assert.That(received.Substring(0, testSend.Length), Is.EqualTo(testSend));

_clientSocket.Shutdown(SocketShutdown.Both);
i.Close();
Expand Down

0 comments on commit d1d3f7e

Please sign in to comment.