public void BlobOpenWriteTest()
        {
            byte[]             buffer    = GetRandomBuffer(2 * 1024);
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                container.Create();

                CloudPageBlob blob = container.GetPageBlobReference("blob1");
                using (CloudBlobStream blobStream = blob.OpenWrite(2048))
                {
                    blobStream.Write(buffer, 0, 2048);
                    blobStream.Flush();

                    byte[]       testBuffer = new byte[2048];
                    MemoryStream dstStream  = new MemoryStream(testBuffer);
                    blob.DownloadRangeToStream(dstStream, null, null);

                    MemoryStream memStream = new MemoryStream(buffer);
                    TestHelper.AssertStreamsAreEqual(memStream, dstStream);
                }
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
        public void BlobOpenWriteSeekReadTest()
        {
            byte[]             buffer    = GetRandomBuffer(2 * 1024);
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                container.Create();
                CloudPageBlob blob         = container.GetPageBlobReference("blob1");
                MemoryStream  memoryStream = new MemoryStream(buffer);
                Stream        blobStream   = blob.OpenWrite(2048);
                blobStream.Write(buffer, 0, 2048);

                Assert.AreEqual(blobStream.Position, 2048);

                blobStream.Seek(1024, 0);
                memoryStream.Seek(1024, 0);
                Assert.AreEqual(blobStream.Position, 1024);

                byte[] testBuffer = GetRandomBuffer(1024);

                memoryStream.Write(testBuffer, 0, 1024);
                blobStream.Write(testBuffer, 0, 1024);
                Assert.AreEqual(blobStream.Position, memoryStream.Position);

                blobStream.Close();

                Stream dstStream = blob.OpenRead();
                TestHelper.AssertStreamsAreEqual(memoryStream, dstStream);
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
        public void BlobReadWhenOpenWrite()
        {
            byte[]             buffer    = GetRandomBuffer(2 * 1024);
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                container.Create();
                CloudPageBlob blob         = container.GetPageBlobReference("blob1");
                MemoryStream  memoryStream = new MemoryStream(buffer);
                Stream        blobStream   = blob.OpenWrite(2048);
                blobStream.Write(buffer, 0, 2048);
                byte[] testBuffer = new byte[2048];
                TestHelper.ExpectedException <NotSupportedException>(() => blobStream.Read(testBuffer, 0, 2048),
                                                                     "Try reading from a stream opened for Write");
            }
            finally
            {
                container.DeleteIfExists();
            }
        }