public async Task ReadAsyncIsCalledFromCallingRead() { var pipeReader = await SetupMockPipeReader(); var stream = new ReadOnlyPipeStream(pipeReader.Object); stream.Read(new byte[1]); pipeReader.Verify(m => m.ReadAsync(It.IsAny <CancellationToken>())); }
public async Task ReadsCanBeCanceledViaProvidedCancellationToken() { var readOnlyStream = new ReadOnlyPipeStream(new HangingPipeReader()); var pipeReader = new StreamPipeReader(readOnlyStream); var cts = new CancellationTokenSource(1); await Task.Delay(1); await Assert.ThrowsAsync <TaskCanceledException>(async() => await pipeReader.ReadAsync(cts.Token)); }
public async Task ReadAsyncCancellationTokenIsPassedIntoReadAsync() { var pipeReader = await SetupMockPipeReader(); var stream = new ReadOnlyPipeStream(pipeReader.Object); var token = new CancellationToken(); await stream.ReadAsync(new byte[1], token); pipeReader.Verify(m => m.ReadAsync(token)); }
public async Task CheckBasicReadPipeApi() { var pipe = new Pipe(); var readStream = new ReadOnlyPipeStream(pipe.Reader); var pipeReader = new StreamPipeReader(readStream); await pipe.Writer.WriteAsync(new byte[10]); var res = await pipeReader.ReadAsync(); Assert.Equal(new byte[10], res.Buffer.ToArray()); }
public async Task ThrowsOperationCanceledExceptionIfCancelPendingReadWasCalledOnInnerPipeReader() { var readOnlyPipeStream = new ReadOnlyPipeStream(Reader); var readOperation = readOnlyPipeStream.ReadAsync(new byte[1]); Assert.False(readOperation.IsCompleted); Reader.CancelPendingRead(); var ex = await Assert.ThrowsAsync <OperationCanceledException>(async() => await readOperation); Assert.Equal(ThrowHelper.CreateOperationCanceledException_ReadCanceled().Message, ex.Message); }
public async Task CheckBasicReadStreamApi() { var stream = new MemoryStream(); await stream.WriteAsync(new byte[10]); stream.Position = 0; var pipeReader = new StreamPipeReader(stream); var readOnlyStream = new ReadOnlyPipeStream(pipeReader); var resSize = await readOnlyStream.ReadAsync(new byte[10]); Assert.Equal(10, resSize); }
public async Task CheckNestedPipeApi() { var pipe = new Pipe(); var reader = pipe.Reader; for (var i = 0; i < 3; i++) { var readStream = new ReadOnlyPipeStream(reader); reader = new StreamPipeReader(readStream); } await pipe.Writer.WriteAsync(new byte[10]); var res = await reader.ReadAsync(); Assert.Equal(new byte[10], res.Buffer.ToArray()); }
public async Task CheckNestedStreamApi() { var stream = new MemoryStream(); await stream.WriteAsync(new byte[10]); stream.Position = 0; Stream readOnlyStream = stream; for (var i = 0; i < 3; i++) { var pipeReader = new StreamPipeReader(readOnlyStream); readOnlyStream = new ReadOnlyPipeStream(pipeReader); } var resSize = await readOnlyStream.ReadAsync(new byte[10]); Assert.Equal(10, resSize); }
public async Task ReadCanBeCancelledViaCancelPendingReadWhenReadIsAsync() { var readOnlyStream = new ReadOnlyPipeStream(new HangingPipeReader()); var pipeReader = new StreamPipeReader(readOnlyStream); var result = new ReadResult(); var tcs = new TaskCompletionSource <int>(TaskCreationOptions.RunContinuationsAsynchronously); var task = Task.Run(async() => { var readingTask = pipeReader.ReadAsync(); tcs.SetResult(0); result = await readingTask; }); await tcs.Task; pipeReader.CancelPendingRead(); await task; Assert.True(result.IsCanceled); }
public void BlockSyncIOThrows() { var readOnlyPipeStream = new ReadOnlyPipeStream(Reader, allowSynchronousIO: false); Assert.Throws <InvalidOperationException>(() => readOnlyPipeStream.Read(new byte[0], 0, 0)); }
public PipeStreamTest() { Pipe = new Pipe(); ReadingStream = new ReadOnlyPipeStream(Reader); WritingStream = new WriteOnlyPipeStream(Writer); }
public void InnerPipeReaderReturnsPipeReader() { var readOnlyPipeStream = new ReadOnlyPipeStream(Reader, allowSynchronousIO: false); Assert.Equal(Reader, readOnlyPipeStream.InnerPipeReader); }