public async Task BlobOpenWriteTestAsync() { byte[] buffer = GetRandomBuffer(2 * 1024); CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); CloudPageBlob blob = container.GetPageBlobReference("blob1"); using (ICloudBlobStream blobStream = await blob.OpenWriteAsync(2048)) { Stream blobStreamForWrite = blobStream.AsStreamForWrite(); await blobStreamForWrite.WriteAsync(buffer, 0, 2048); await blobStreamForWrite.FlushAsync(); byte[] testBuffer = new byte[2048]; MemoryStream dstStream = new MemoryStream(testBuffer); await blob.DownloadRangeToStreamAsync(dstStream.AsOutputStream(), null, null); MemoryStream memStream = new MemoryStream(buffer); TestHelper.AssertStreamsAreEqual(memStream, dstStream); } } finally { container.DeleteIfExistsAsync().AsTask().Wait(); } }
public async Task BlobOpenReadWriteTestAsync() { byte[] buffer = GetRandomBuffer(2 * 1024); CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); CloudPageBlob blob = container.GetPageBlobReference("blob1"); using (ICloudBlobStream blobStream = await blob.OpenWriteAsync(2048)) { Stream blobStreamForWrite = blobStream.AsStreamForWrite(); await blobStreamForWrite.WriteAsync(buffer, 0, 2048); await blobStreamForWrite.FlushAsync(); } using (IInputStream dstStream = await blob.OpenReadAsync()) { Stream dstStreamForRead = dstStream.AsStreamForRead(); MemoryStream memoryStream = new MemoryStream(buffer); TestHelper.AssertStreamsAreEqual(memoryStream, dstStreamForRead); } } finally { container.DeleteIfExistsAsync().AsTask().Wait(); } }