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); }