Example #1
0
        // ReSharper disable InconsistentNaming
        public void SocketTimerElapsedTest1_GetBufferChunks()
        // ReSharper restore InconsistentNaming
        {
            using (var connection = new Connection(CreateClientFactory()))
            {
                Connect(connection);

                bool dataLengthReceivedFired = false;
                connection.DataLengthReceived += (sender, args) => dataLengthReceivedFired = true;
                var buffer = connection.InternalBuffer;
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
                    new Func <byte[], int, int, int>(FillBufferWithTestData));

                connection.SocketTimerElapsed(null, null);

                Assert.IsTrue(dataLengthReceivedFired);
                // check GetBuffer() and DataAvailable
                Assert.IsTrue(connection.DataAvailable);
                var connectionBuffer = connection.GetBufferChunks(false).MergeChunks().ToString();
                Assert.IsFalse(String.IsNullOrEmpty(connectionBuffer));
                Assert.IsTrue(connection.DataAvailable);
                connectionBuffer = connection.GetBufferChunks().MergeChunks().ToString();
                Assert.IsFalse(String.IsNullOrEmpty(connectionBuffer));
                Assert.IsFalse(connection.DataAvailable);
            }

            _tcpClient.VerifyAllExpectations();
            _stream.VerifyAllExpectations();
        }
Example #2
0
        public void SocketTimerElapsedTest4()
        {
            using (var connection = new Connection(CreateClientFactory()))
            {
                Connect(connection);

                var buffer = connection.InternalBuffer;
                // when we call Close() ourselves then the Read() method called by
                // Update() will throw a WSACancelBlockingCall error code as the
                // inner exception of an IOException.  in this case Close() does
                // not need called again since it was called through the API.
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Throw(new IOException(String.Empty, new SocketException(10004)));

                connection.SocketTimerElapsed(null, null);
            }

            _tcpClient.VerifyAllExpectations();
            _stream.VerifyAllExpectations();
        }
Example #3
0
        public void SocketTimerElapsedTest2()
        {
            using (var connection = new Connection(CreateClientFactory()))
            {
                Connect(connection);

                var buffer = connection.InternalBuffer;
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
                    new Func <byte[], int, int, int>(FillBufferWithTestData));

                connection.SocketTimerElapsed(null, null);

                // check ClearBuffer() and DataAvailable
                Assert.IsTrue(connection.DataAvailable);
                connection.ClearBuffer();
                Assert.IsFalse(connection.DataAvailable);
            }

            _tcpClient.VerifyAllExpectations();
            _stream.VerifyAllExpectations();
        }
Example #4
0
        public void SocketTimerElapsedTest3()
        {
            using (var connection = new Connection(CreateClientFactory()))
            {
                Connect(connection);

                var buffer = connection.InternalBuffer;
                // when Read returns 0 the connection has been lost and the
                // implementation throws an IOException
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Return(0);
                // as a result the connection is closed, set expectations
                _stream.Expect(x => x.Close());
                _tcpClient.Expect(x => x.Close());

                bool statusMessageFired = false;
                connection.StatusMessage += (sender, args) => statusMessageFired = true;
                connection.SocketTimerElapsed(null, null);

                Assert.IsTrue(statusMessageFired);
            }

            _tcpClient.VerifyAllExpectations();
            _stream.VerifyAllExpectations();
        }
Example #5
0
        public void SocketTimerElapsedTest4()
        {
            using (var connection = new Connection(CreateClientFactory()))
             {
            Connect(connection);

            var buffer = connection.InternalBuffer;
            // when we call Close() ourselves then the Read() method called by
            // Update() will throw a WSACancelBlockingCall error code as the
            // inner exception of an IOException.  in this case Close() does
            // not need called again since it was called through the API.
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Throw(new IOException(String.Empty, new SocketException(10004)));

            connection.SocketTimerElapsed(null, null);
             }

             _tcpClient.VerifyAllExpectations();
             _stream.VerifyAllExpectations();
        }
Example #6
0
        public void SocketTimerElapsedTest3()
        {
            using (var connection = new Connection(CreateClientFactory()))
             {
            Connect(connection);

            var buffer = connection.InternalBuffer;
            // when Read returns 0 the connection has been lost and the
            // implementation throws an IOException
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Return(0);
            // as a result the connection is closed, set expectations
            _stream.Expect(x => x.Close());
            _tcpClient.Expect(x => x.Close());

            bool statusMessageFired = false;
            connection.StatusMessage += (sender, args) => statusMessageFired = true;
            connection.SocketTimerElapsed(null, null);

            Assert.IsTrue(statusMessageFired);
             }

             _tcpClient.VerifyAllExpectations();
             _stream.VerifyAllExpectations();
        }
Example #7
0
        public void SocketTimerElapsedTest2()
        {
            using (var connection = new Connection(CreateClientFactory()))
             {
            Connect(connection);

            var buffer = connection.InternalBuffer;
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
               new Func<byte[], int, int, int>(FillBufferWithTestData));

            connection.SocketTimerElapsed(null, null);

            // check ClearBuffer() and DataAvailable
            Assert.IsTrue(connection.DataAvailable);
            connection.ClearBuffer();
            Assert.IsFalse(connection.DataAvailable);
             }

             _tcpClient.VerifyAllExpectations();
             _stream.VerifyAllExpectations();
        }
Example #8
0
        public void SocketTimerElapsedTest1_GetBufferChunks()
        {
            using (var connection = new Connection(CreateClientFactory()))
             {
            Connect(connection);

            bool dataLengthReceivedFired = false;
            connection.DataLengthReceived += (sender, args) => dataLengthReceivedFired = true;
            var buffer = connection.InternalBuffer;
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
               new Func<byte[], int, int, int>(FillBufferWithTestData));

            connection.SocketTimerElapsed(null, null);

            Assert.IsTrue(dataLengthReceivedFired);
            // check GetBuffer() and DataAvailable
            Assert.IsTrue(connection.DataAvailable);
            var connectionBuffer = connection.GetBufferChunks(false).MergeChunks().ToString();
            Assert.IsFalse(String.IsNullOrEmpty(connectionBuffer));
            Assert.IsTrue(connection.DataAvailable);
            connectionBuffer = connection.GetBufferChunks().MergeChunks().ToString();
            Assert.IsFalse(String.IsNullOrEmpty(connectionBuffer));
            Assert.IsFalse(connection.DataAvailable);
             }

             _tcpClient.VerifyAllExpectations();
             _stream.VerifyAllExpectations();
        }