本文整理汇总了C#中BufferedStream.FlushAsync方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream.FlushAsync方法的具体用法?C# BufferedStream.FlushAsync怎么用?C# BufferedStream.FlushAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferedStream
的用法示例。
在下文中一共展示了BufferedStream.FlushAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldAlwaysFlushUnderlyingStreamIfWritable
public async Task ShouldAlwaysFlushUnderlyingStreamIfWritable(bool underlyingCanRead, bool underlyingCanSeek)
{
var underlying = new DelegateStream(
canReadFunc: () => underlyingCanRead,
canWriteFunc: () => true,
canSeekFunc: () => underlyingCanSeek,
readFunc: (_, __, ___) => 123,
writeFunc: (_, __, ___) => { },
seekFunc: (_, __) => 123L
);
var wrapper = new CallTrackingStream(underlying);
var buffered = new BufferedStream(wrapper);
buffered.Flush();
Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.Flush)));
await buffered.FlushAsync();
Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
buffered.WriteByte(0);
buffered.Flush();
Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.Flush)));
await buffered.FlushAsync();
Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
}
示例2: ShouldNotFlushUnderlyingStreamIfReadOnly
public async Task ShouldNotFlushUnderlyingStreamIfReadOnly(bool underlyingCanSeek)
{
var underlying = new DelegateStream(
canReadFunc: () => true,
canWriteFunc: () => false,
canSeekFunc: () => underlyingCanSeek,
readFunc: (_, __, ___) => 123,
writeFunc: (_, __, ___) =>
{
throw new NotSupportedException();
},
seekFunc: (_, __) => 123L
);
var wrapper = new CallTrackingStream(underlying);
var buffered = new BufferedStream(wrapper);
buffered.ReadByte();
buffered.Flush();
Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.Flush)));
await buffered.FlushAsync();
Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
}
示例3: UnderlyingStreamThrowsExceptions
public void UnderlyingStreamThrowsExceptions()
{
var stream = new BufferedStream(new ThrowsExceptionFromAsyncOperationsStream());
Assert.Equal(TaskStatus.Faulted, stream.ReadAsync(new byte[1], 0, 1).Status);
Assert.Equal(TaskStatus.Faulted, stream.WriteAsync(new byte[10000], 0, 10000).Status);
stream.WriteByte(1);
Assert.Equal(TaskStatus.Faulted, stream.FlushAsync().Status);
}