本文整理汇总了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();
}
示例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();
}
示例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();
}
示例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();
}