public async Task Write_InvokedSynchronously() { (Stream stream1, Stream stream2) = TestHelper.GetConnectedStreams(); var clientStream = new PreReadWriteActionDelegatingStream(stream1); using (var clientSslStream = new SslStream(clientStream, false, AllowAnyServerCertificate)) using (var serverSslStream = new SslStream(stream2)) { await DoHandshake(clientSslStream, serverSslStream); // Validate that the write call to the underlying stream is made as part of the // synchronous call to the write method on SslStream, even if the method is async. using (var tl = new ThreadLocal <int>()) { tl.Value = 42; clientStream.PreReadWriteAction = () => Assert.Equal(42, tl.Value); Task t = WriteAsync(clientSslStream, new byte[1], 0, 1); tl.Value = 0; await t; } } }
public async Task Read_InvokedSynchronously() { var network = new VirtualNetwork(); var clientStream = new PreReadWriteActionDelegatingStream(new VirtualNetworkStream(network, isServer: false)); using (var clientSslStream = new SslStream(clientStream, false, AllowAnyServerCertificate)) using (var serverSslStream = new SslStream(new VirtualNetworkStream(network, isServer: true))) { await DoHandshake(clientSslStream, serverSslStream); // Validate that the read call to the underlying stream is made as part of the // synchronous call to the read method on SslStream, even if the method is async. using (var tl = new ThreadLocal <int>()) { await WriteAsync(serverSslStream, new byte[1], 0, 1); tl.Value = 42; clientStream.PreReadWriteAction = () => Assert.Equal(42, tl.Value); Task t = ReadAsync(clientSslStream, new byte[1], 0, 1); tl.Value = 0; await t; } } }