Beispiel #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;
            });
        }
Beispiel #2
0
        public static async Task Test_Buffered_Peeking_Can_Peek_Counted_Bytes_Async()
        {
            //arrange
            DefaultStreamReaderStrategyAsync reader = new DefaultStreamReaderStrategyAsync(new byte[] { 5, 6, 7, 5 });

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

            byte[] peekedBytes = await peekedBufferReader.PeekBytesAsync(4);

            byte[] peekedBytesAgain = await peekedBufferReader.PeekBytesAsync(2);

            byte[] readBytes = await peekedBufferReader.ReadBytesAsync(4);


            //assert
            Assert.AreEqual(4, readBytes.Length);
            for (int i = 0; i < peekedBytes.Length; i++)
            {
                Assert.AreEqual(peekedBytes[i], readBytes[i]);
            }

            for (int i = 0; i < peekedBytesAgain.Length; i++)
            {
                Assert.AreEqual(peekedBytes[i], peekedBytesAgain[i]);
            }

            Assert.Throws <InvalidOperationException>(() => peekedBufferReader.ReadByte());
        }
Beispiel #3
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;
            });
        }