public async Task ReadLineAsync_ThrowsOnConnectionClose() { var listener = new TcpListener(IPAddress.Loopback, 0); try { listener.Start(); var acceptTask = listener.AcceptTcpClientAsync(); var client = new TcpClient(); await client.ConnectAsync(IPAddress.Loopback, ((IPEndPoint)listener.LocalEndpoint).Port); using (var serverTcpClient = await acceptTask) { var channel = new TcpClientConnectionChannel(serverTcpClient); client.Dispose(); await Assert.ThrowsAsync <ConnectionUnexpectedlyClosedException>(async() => { await channel.ReadLineAsync(); }); } } finally { listener.Stop(); } }
public async Task ReadLineAsync_ThrowsOnConnectionClose() { TcpListener listener = new TcpListener(IPAddress.Loopback, 0); try { listener.Start(); Task<TcpClient> acceptTask = listener.AcceptTcpClientAsync(); TcpClient client = new TcpClient(); await client.ConnectAsync(IPAddress.Loopback, ((IPEndPoint)listener.LocalEndpoint).Port); using (TcpClient serverTcpClient = await acceptTask) { TcpClientConnectionChannel channel = new TcpClientConnectionChannel(serverTcpClient); client.Dispose(); await Assert.ThrowsAsync<ConnectionUnexpectedlyClosedException>(async () => { await channel.ReadLineAsync(); }); } } finally { listener.Stop(); } }
public async Task ReadLineAsync_ThrowsOnConnectionClose() { TcpListener listener = new TcpListener(IPAddress.Loopback, 0); try { listener.Start(); Task <TcpClient> acceptTask = listener.AcceptTcpClientAsync(); TcpClient client = new TcpClient(); await client.ConnectAsync(IPAddress.Loopback, ((IPEndPoint)listener.LocalEndpoint).Port).ConfigureAwait(false); using (TcpClient serverTcpClient = await acceptTask.ConfigureAwait(false)) { TcpClientConnectionChannel channel = new TcpClientConnectionChannel(serverTcpClient, Encoding.Default); client.Dispose(); await Assert.ThrowsAsync <ConnectionUnexpectedlyClosedException>(async() => { await channel.ReadLine().ConfigureAwait(false); }).ConfigureAwait(false); } } finally { listener.Stop(); } }