Example #1
0
        public void CloudPageBlobCopyWithSourceAccessCondition()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                container.Create();

                CloudPageBlob source = container.GetPageBlobReference("source");
                string        data   = new string('a', 512);
                UploadText(source, data, Encoding.UTF8);
                string validLeaseId   = Guid.NewGuid().ToString();
                string leaseId        = source.AcquireLease(TimeSpan.FromSeconds(60), validLeaseId);
                string invalidLeaseId = Guid.NewGuid().ToString();

                source.FetchAttributes();
                AccessCondition sourceAccessCondition1 = AccessCondition.GenerateIfNotModifiedSinceCondition(source.Properties.LastModified.Value);
                CloudPageBlob   copy1 = container.GetPageBlobReference("copy1");
                copy1.StartCopyFromBlob(TestHelper.Defiddler(source), sourceAccessCondition1);
                WaitForCopy(copy1);
                Assert.AreEqual(CopyStatus.Success, copy1.CopyState.Status);

                AccessCondition sourceAccessCondition2 = AccessCondition.GenerateLeaseCondition(invalidLeaseId);
                CloudPageBlob   copy2 = container.GetPageBlobReference("copy2");
                TestHelper.ExpectedException <ArgumentException>(() => copy2.StartCopyFromBlob(TestHelper.Defiddler(source), sourceAccessCondition2), "A lease condition cannot be specified on the source of a copy.");
            }
            finally
            {
                container.DeleteIfExists();
            }
        }