Start() public method

public Start ( ) : void
return void
        public void CloseTest()
        {
            int shutdownCount = 0;
            int closeCount = 0;

            ManualResetEvent resetEvent = new ManualResetEvent(false);

            NetworkConnection connection = new NetworkConnection(_client);

            connection.Shutdown += (sender, args) =>
            {
                shutdownCount++;
                resetEvent.Set();
            };

            connection.ConnectionClosed += (sender, args) =>
            {
                closeCount++;
                resetEvent.Set();
            };

            connection.Start();
            connection.Close();

            Assert.That(resetEvent.WaitOne(2000));
            Assert.That(shutdownCount, Is.EqualTo(0));
            Assert.That(closeCount, Is.EqualTo(1));
        }
        public void RapidReceiveData()
        {
            ManualResetEvent resetEvent = new ManualResetEvent(false);

            NetworkConnection connection = new NetworkConnection(_client);

            byte[] originalBuffer = new byte[10000];
            List<byte> copiedBuffer = new List<byte>();

            for (int i = 0; i < 10000; i++)
            {
                originalBuffer[i] = (byte) ( i % 100 );
            }

            connection.DataAvailable += (sender, args) =>
                                        {
                                            var receiveBuffer = args.Data;

                                            copiedBuffer.AddRange(receiveBuffer);

                                            if (copiedBuffer.Count() == 10000)
                                            {
                                                resetEvent.Set();
                                            }
                                        };

            connection.Start();

            for (int i = 0; i < 1000; i++)
            {
                byte[] buffer = new byte[10];

                Array.Copy( originalBuffer, i * 10, buffer, 0, 10  );

                _serverClient.Send(buffer);
            }

            Assert.That(resetEvent.WaitOne(2000));
            Assert.That(originalBuffer, Is.EqualTo(copiedBuffer)  );
        }
        public void StopSendingTest()
        {
            int shutdownCount = 0;

            ManualResetEvent resetEvent = new ManualResetEvent(false);

            NetworkConnection connection = new NetworkConnection(_client);

            connection.Shutdown += ( sender, args ) =>
                                          {
                                              shutdownCount++;
                                              resetEvent.Set();
                                          };

            connection.Start();

            _serverClient.Shutdown(SocketShutdown.Send);

            Assert.That(resetEvent.WaitOne(2000));
            Assert.That(shutdownCount, Is.EqualTo(1));
        }
        public void ReceiveData()
        {
            ManualResetEvent resetEvent = new ManualResetEvent(false);

            NetworkConnection connection = new NetworkConnection(_client);

            byte[] buffer = null;
            connection.DataAvailable += ( sender, args ) =>
                                        {
                                            buffer = args.Data;
                                            resetEvent.Set();
                                        };

            // Send data from other end. Place this before the Start method to verify what might happen
            // on an actual network. Data may arrive before we start to receive it.
            _serverClient.Send( _buffer );

            connection.Start();

            Assert.That(resetEvent.WaitOne(2000));
            Assert.That(buffer[0], Is.EqualTo(1));
        }