本文整理汇总了C#中BufferedStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream.Dispose方法的具体用法?C# BufferedStream.Dispose怎么用?C# BufferedStream.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferedStream
的用法示例。
在下文中一共展示了BufferedStream.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyToAsync_InvalidArguments_Throws
public void CopyToAsync_InvalidArguments_Throws()
{
using (var s = new BufferedStream(new MemoryStream()))
{
// Null destination
Assert.Throws<ArgumentNullException>("destination", () => { s.CopyToAsync(null); });
// Buffer size out-of-range
Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { s.CopyToAsync(new MemoryStream(), 0); });
Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { s.CopyToAsync(new MemoryStream(), -1, CancellationToken.None); });
// Copying to non-writable stream
Assert.Throws<NotSupportedException>(() => { s.CopyToAsync(new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: true)); });
// Copying to a non-writable and non-readable stream
Assert.Throws<ObjectDisposedException>(() => { s.CopyToAsync(new WrappedMemoryStream(canRead: false, canWrite: false, canSeek: false)); });
// Copying after disposing the buffer stream
s.Dispose();
Assert.Throws<ObjectDisposedException>(() => { s.CopyToAsync(new MemoryStream()); });
}
// Copying after disposing the underlying stream
using (var ms = new MemoryStream())
using (var s = new BufferedStream(ms))
{
ms.Dispose();
Assert.Throws<ObjectDisposedException>(() => { s.CopyToAsync(new MemoryStream()); });
}
// Copying from a non-readable source
using (var s = new BufferedStream(new WrappedMemoryStream(canRead: false, canWrite: true, canSeek: true)))
{
Assert.Throws<NotSupportedException>(() => { s.CopyToAsync(new MemoryStream()); });
}
}