Пример #1
0
        public async Task BufferingDataPastEndOfStreamCanBeReadAgain()
        {
            var        helloBytes = Encoding.ASCII.GetBytes("Hello World");
            var        stream     = new ThrowAfterZeroByteReadStream(helloBytes);
            PipeReader reader     = PipeReader.Create(stream);


            ReadResult readResult = await reader.ReadAsync();

            ReadOnlySequence <byte> buffer = readResult.Buffer;

            reader.AdvanceTo(buffer.Start, buffer.End);

            // Make sure IsCompleted is true
            readResult = await reader.ReadAsync();

            buffer = readResult.Buffer;
            reader.AdvanceTo(buffer.Start, buffer.End);
            Assert.True(readResult.IsCompleted);

            var value = await ReadFromPipeAsString(reader);

            Assert.Equal("Hello World", value);
            reader.Complete();
        }
Пример #2
0
        public async Task BufferingDataPastEndOfStreamCanBeReadAgain()
        {
            var protocol = new TestProtocol();
            var stream   = new ThrowAfterZeroByteReadStream();
            var writer   = PipeWriter.Create(stream);
            var reader   = new MessagePipeReader(PipeReader.Create(stream), protocol);

            protocol.WriteMessage(Encoding.ASCII.GetBytes("Hello World"), writer);
            await writer.FlushAsync().ConfigureAwait(false);

            stream.Position = 0;

            var readResult = await reader.ReadAsync();

            var buffer = readResult.Buffer;

            reader.AdvanceTo(buffer.Start, buffer.End);

            // Make sure IsCompleted is true
            readResult = await reader.ReadAsync();

            buffer = readResult.Buffer;
            reader.AdvanceTo(buffer.Start, buffer.End);
            Assert.True(readResult.IsCompleted);

            var value = await ReadFromPipeAsString(reader);

            Assert.Equal("Hello World", value);
            reader.Complete();
        }
Пример #3
0
        public async Task ReadAsyncAfterReceivingCompletedReadResultDoesNotThrow()
        {
            Stream = new ThrowAfterZeroByteReadStream();
            Reader = new StreamPipeReader(Stream);
            var readResult = await Reader.ReadAsync();

            readResult = await Reader.ReadAsync();

            Assert.True(readResult.Buffer.IsEmpty);
            Assert.True(readResult.IsCompleted);
        }
Пример #4
0
        public async Task ReadAsyncAfterReceivingCompletedReadResultDoesNotThrow()
        {
            var        stream     = new ThrowAfterZeroByteReadStream();
            PipeReader reader     = PipeReader.Create(stream);
            ReadResult readResult = await reader.ReadAsync();

            Assert.True(readResult.Buffer.IsEmpty);
            Assert.True(readResult.IsCompleted);
            reader.AdvanceTo(readResult.Buffer.End);

            readResult = await reader.ReadAsync();

            Assert.True(readResult.Buffer.IsEmpty);
            Assert.True(readResult.IsCompleted);
            reader.AdvanceTo(readResult.Buffer.End);
            reader.Complete();
        }