当前位置: 首页>>代码示例>>C#>>正文


C# Connection.SocketTimerElapsed方法代码示例

本文整理汇总了C#中Connection.SocketTimerElapsed方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.SocketTimerElapsed方法的具体用法?C# Connection.SocketTimerElapsed怎么用?C# Connection.SocketTimerElapsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connection的用法示例。


在下文中一共展示了Connection.SocketTimerElapsed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SocketTimerElapsedTest4

        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();
        }
开发者ID:kszysiu,项目名称:hfm-net,代码行数:19,代码来源:ConnectionTests.cs

示例2: SocketTimerElapsedTest2

        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();
        }
开发者ID:kszysiu,项目名称:hfm-net,代码行数:21,代码来源:ConnectionTests.cs

示例3: SocketTimerElapsedTest3

        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();
        }
开发者ID:kszysiu,项目名称:hfm-net,代码行数:24,代码来源:ConnectionTests.cs

示例4: SocketTimerElapsedTest1_GetBufferChunks

        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();
        }
开发者ID:kszysiu,项目名称:hfm-net,代码行数:28,代码来源:ConnectionTests.cs


注:本文中的Connection.SocketTimerElapsed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。