Example #1
0
        public static async Task Test_Buffered_Peeking_Can_Peek_Counted_Bytes_With_ReadAllAsync()
        {
            //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 b = peekedBufferReader.ReadByte();

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

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

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

            Assert.Throws <InvalidOperationException>(() => peekedBufferReader.ReadByte());
        }
Example #2
0
        public static void Test_That_Prepended_Reader_Contains_Bytes_After_The_Prended_Portion(byte[] bytes)
        {
            //arrange
            DefaultStreamReaderStrategyAsync reader = new DefaultStreamReaderStrategyAsync(new byte[] { 5, 7 });

            //act
            IWireStreamReaderStrategyAsync bufferedReader = reader.PreprendWithBytesAsync(bytes);

            byte[] readBytes = bufferedReader.ReadBytes(bytes.Length);

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

            Assert.AreEqual(5, bufferedReader.ReadByte());
            Assert.AreEqual(7, bufferedReader.ReadByte());

            Assert.Throws <InvalidOperationException>(() => bufferedReader.ReadByte());
        }