private void DoUploadFromByteArrayTest(CloudFile file, int bufferSize, int bufferOffset, int count, bool isAsync) { byte[] buffer = GetRandomBuffer(bufferSize); byte[] downloadedBuffer = new byte[bufferSize]; int downloadLength; if (isAsync) { IAsyncResult result; using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { result = file.BeginUploadFromByteArray(buffer, bufferOffset, count, ar => waitHandle.Set(), null); waitHandle.WaitOne(); file.EndUploadFromByteArray(result); result = file.BeginDownloadToByteArray(downloadedBuffer, 0, ar => waitHandle.Set(), null); waitHandle.WaitOne(); downloadLength = file.EndDownloadToByteArray(result); } } else { file.UploadFromByteArray(buffer, bufferOffset, count); downloadLength = file.DownloadToByteArray(downloadedBuffer, 0); } Assert.AreEqual(count, downloadLength); for (int i = 0; i < count; i++) { Assert.AreEqual(buffer[i + bufferOffset], downloadedBuffer[i]); } }