public void SocketClosedBeforeSendTest() { NetworkConnection connection = new NetworkConnection(_client); _serverClient.Close(); _client.Close(); Assert.Throws<SocketException>(() => connection.SendData(_buffer)); }
public void StopReceivingTest() { int shutdownCount = 0; ManualResetEvent resetEvent = new ManualResetEvent(false); NetworkConnection connection = new NetworkConnection(_client); connection.Shutdown += (sender, args) => { shutdownCount++; resetEvent.Set(); }; connection.Start(); // Server stops receiving data _serverClient.Shutdown(SocketShutdown.Receive); connection.SendData(_buffer); Assert.That(resetEvent.WaitOne(2000)); Assert.That(shutdownCount, Is.EqualTo(1)); }
public void SendData() { int eventCount = 0; ManualResetEvent resetEvent = new ManualResetEvent(false); NetworkConnection connection = new NetworkConnection(_client); connection.DataSent += ( sender, args ) => { eventCount++; resetEvent.Set(); }; byte[] buffer = new byte[10]; _serverClient.BeginReceive( buffer, 0, 10, SocketFlags.None, ar =>_serverClient.EndReceive( ar ), null ); connection.SendData(_buffer); Assert.That(resetEvent.WaitOne(2000)); Assert.That(buffer[0], Is.EqualTo(1), "Data not sent to server"); Assert.That(eventCount, Is.EqualTo(1)); }