public async Task CopyToAsync_InvalidArguments_Throws()
{
await RunWithConnectedNetworkStreamsAsync((stream, _) =>
{
// Null destination
Assert.Throws<ArgumentNullException>("destination", () => { stream.CopyToAsync(null); });
// Buffer size out-of-range
Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { stream.CopyToAsync(new MemoryStream(), 0); });
Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { stream.CopyToAsync(new MemoryStream(), -1, CancellationToken.None); });
// Copying to non-writable stream
Assert.Throws<NotSupportedException>(() => { stream.CopyToAsync(new MemoryStream(new byte[0], writable: false)); });
// Copying after disposing the stream
stream.Dispose();
Assert.Throws<ObjectDisposedException>(() => { stream.CopyToAsync(new MemoryStream()); });
return Task.CompletedTask;
});
}