public unsafe void BytesWrite() { Random rng = new Random(); byte[] src = new byte[1024]; byte[] chk; rng.NextBytes(src); ManagedBinaryMemoryWriter writer = new ManagedBinaryMemoryWriter(); for (int count = 1; count < 1024; count++) { writer.WriteBytes(src, 0, 1024 - count); } using (MemoryStream ms = new MemoryStream(writer.ToArray())) { using (BinaryReader reader = new BinaryReader(ms)) for (int count = 1; count < 1024; count++) { chk = reader.ReadBytes(1024 - count); for (int position = 0; position < 1024 - count; position++) { Assert.AreEqual(chk[position], src[position], $"Invalid content at position {position}."); } } } }