public void unframe_record_when_provided_with_small_chunks_of_data_at_a_time()
        {
            int unframedCnt = 0;
            var framer = new LengthPrefixSuffixFramer(r =>
            {
                unframedCnt += 1;
                Assert.AreEqual(new byte[] { 0x07, 0x17, 0x27 }, ReadAll(r));
            });

            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x03, 0x00 }));
            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x00, 0x00 }));
            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x07, 0x17, 0x27 }));
            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x03, 0x00 }));

            Assert.AreEqual(0, unframedCnt);
            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x00, 0x00 }));
            Assert.AreEqual(1, unframedCnt);
        }
        public void unframe_record_when_provided_exactly_enough_data_in_one_call()
        {
            int unframedCnt = 0;
            var framer = new LengthPrefixSuffixFramer(r =>
            {
                unframedCnt += 1;
                Assert.AreEqual(new byte[] { 0x07, 0x17, 0x27 }, ReadAll(r));
            });

            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x03, 0x00, 0x00, 0x00,
                                                                   0x07, 0x17, 0x27,
                                                                   0x03, 0x00, 0x00, 0x00}));

            Assert.AreEqual(1, unframedCnt);
        }
        public void unframe_two_consecutive_records()
        {
            int unframedCnt = 0;
            var framer = new LengthPrefixSuffixFramer(r =>
            {
                if (unframedCnt == 0)
                    Assert.AreEqual(new byte[] { 0x07, 0x17, 0x27 }, ReadAll(r));
                else if (unframedCnt == 1)
                    Assert.AreEqual(new byte[] { 0x05, 0x15 }, ReadAll(r));
                else
                    Assert.Fail();

                unframedCnt += 1;
            });

            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x03, 0x00, 0x00, 0x00, 
                                                                   0x07, 0x17, 0x27 }));

            Assert.AreEqual(0, unframedCnt);

            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x03, 0x00, 0x00, 0x00,
                                                                   0x02, 0x00, 0x00, 0x00,
                                                                   0x05, 0x15 }));

            Assert.AreEqual(1, unframedCnt);

            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x02, 0x00, 0x00, 0x00}));
            
            Assert.AreEqual(2, unframedCnt);
        }
        public void discard_data_when_reset_and_continue_unframing_from_blank_slate()
        {
            int unframedCnt = 0;
            var framer = new LengthPrefixSuffixFramer(r =>
            {
                if (unframedCnt == 0)
                    Assert.AreEqual(new byte[] { 0x07, 0x17, 0x27 }, ReadAll(r));
                else if (unframedCnt == 1)
                    Assert.AreEqual(new byte[] { 0x05, 0x15 }, ReadAll(r));
                else
                    Assert.Fail();

                unframedCnt += 1;
            });

            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x03, 0x00, 0x00, 0x00, 
                                                                   0x07, 0x17, 0x27,
                                                                   0x03, 0x00, 0x00, 0x00, 
                                                                   0xAA, 0xBB, 0xCC, 0x00, 
                                                                   0x01, 0x02, 0x03, 0x04, 
                                                                   0x05, 0x06, 0x07, 0x08 }));

            Assert.AreEqual(1, unframedCnt);

            framer.Reset();

            framer.UnFrameData(new ArraySegment<byte>(new byte[] { 0x02, 0x00, 0x00, 0x00,
                                                                   0x05, 0x15,
                                                                   0x02, 0x00, 0x00, 0x00 }));

            Assert.AreEqual(2, unframedCnt);
        }