public void TestClearChunk()
        {
            ByteArrayBuilder builder     = new ByteArrayBuilder();
            string           firstChunk  = "123";
            string           secondChunk = "ab";

            byte[] firstChunkBytes  = GetBytesFromString(firstChunk);
            byte[] secondChunkBytes = GetBytesFromString(secondChunk);


            builder.AddChunkReference(firstChunkBytes, 3);
            builder.AddChunkReference(secondChunkBytes, 2);


            byte[] returnedBytes       = builder.ToArray();
            string returnedBytesString = Encoding.UTF8.GetString(returnedBytes);

            Assert.AreEqual("123ab", returnedBytesString);

            //now clear
            builder.ClearChunks();

            Assert.AreEqual("", Encoding.UTF8.GetString(builder.ToArray()));

            //check that the index gets reset after clear
            builder.AddChunkReference(firstChunkBytes, 3);

            returnedBytes       = builder.ReadChunk();
            returnedBytesString = Encoding.UTF8.GetString(returnedBytes);

            Assert.AreEqual(firstChunk, returnedBytesString);
        }
        public void TestReadChunk()
        {
            ByteArrayBuilder builder     = new ByteArrayBuilder();
            string           firstChunk  = "123";
            string           secondChunk = "ab";
            string           thirdChunk  = "--+";

            byte[] firstChunkBytes  = GetBytesFromString(firstChunk);
            byte[] secondChunkBytes = GetBytesFromString(secondChunk);
            byte[] thirdChunkBytes  = GetBytesFromString(thirdChunk);

            builder.AddChunkReference(firstChunkBytes, 3);
            builder.AddChunkReference(secondChunkBytes, 2);
            builder.AddChunkReference(thirdChunkBytes, 3);

            byte[] returnedBytes       = builder.ReadChunk();
            string returnedBytesString = Encoding.UTF8.GetString(returnedBytes);

            Assert.AreEqual(firstChunk, returnedBytesString);
            returnedBytes       = builder.ReadChunk();
            returnedBytesString = Encoding.UTF8.GetString(returnedBytes);
            Assert.AreEqual(secondChunk, returnedBytesString);
            //reset the current chunk
            builder.ResetChunkPosition();
            returnedBytes       = builder.ReadChunk();
            returnedBytesString = Encoding.UTF8.GetString(returnedBytes);
            Assert.AreEqual(firstChunk, returnedBytesString);
            //read to end
            returnedBytes = builder.ReadChunk();
            returnedBytes = builder.ReadChunk();
            returnedBytes = builder.ReadChunk();
            Assert.IsNull(returnedBytes);
            //test that the builder resets to the beggining now
            returnedBytes       = builder.ReadChunk();
            returnedBytesString = Encoding.UTF8.GetString(returnedBytes);
            Assert.AreEqual(firstChunk, returnedBytesString);
        }