Here the proof.
Any idea what is wrong in this code ?
[TestMethod]
public void TestTest()
{
var tcp = new TcpClient() { ReceiveTimeou
There are a few problems there that pop out:
CancellationToken throws OperationCanceledException, not TimeoutException (cancellation is not always due to timeout).ReceiveTimeout doesn't apply, since you're doing an asynchronous read. Even if it did, you'd have a race condition between IOException and OperationCanceledException.The correct way to test asynchronous code is with an asynchronous test:
[TestMethod]
public async Task TestTest()
{
var tcp = new TcpClient() { ReceiveTimeout = 5000, SendTimeout = 20000 };
tcp.Connect(IPAddress.Parse("176.31.100.115"), 25);
await Read(tcp.GetStream());
}