示例#1
0
        public static async Task Test_Buffered_Peeking_Can_Peek_Bytes_Async()
        {
            //arrange
            DefaultStreamReaderStrategyAsync reader = new DefaultStreamReaderStrategyAsync(new byte[] { 5, 6, 7, 5 });

            //act
            IWireStreamReaderStrategyAsync peekedBufferReader = reader.PeekWithBufferingAsync();

            //assert
            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(5, await peekedBufferReader.PeekByteAsync());
            }

            Assert.AreEqual(5, await peekedBufferReader.ReadByteAsync());
            Assert.AreEqual(6, await peekedBufferReader.ReadByteAsync());

            byte[] readBytes = await peekedBufferReader.ReadAllBytesAsync();

            Assert.AreEqual(7, readBytes[0]);
            Assert.AreEqual(5, readBytes[1]);

            Assert.Throws <AggregateException>(() =>
            {
                byte b = peekedBufferReader.ReadByteAsync().Result;
            });
        }
示例#2
0
        public static async Task Test_Buffered_Peeking_Can_Peek_Byte_Async(byte b)
        {
            //arrange
            DefaultStreamReaderStrategyAsync reader = new DefaultStreamReaderStrategyAsync(new byte[] { b });

            //act
            IWireStreamReaderStrategyAsync peekedBufferReader = reader.PeekWithBufferingAsync();

            //assert
            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(b, await peekedBufferReader.PeekByteAsync());
            }

            Assert.AreEqual(b, await peekedBufferReader.ReadByteAsync());

            Assert.Throws <AggregateException>(() =>
            {
                byte sdsdf = peekedBufferReader.ReadByteAsync().Result;
            });
        }