public async Task CloudAppendBlobCreateCPKTask() { // Arrange CloudBlobContainer container = GetRandomContainerReference(); await container.CreateAsync(); var customerProvidedKey = BuildCustomerProvidedKey(); var options = new BlobRequestOptions { CustomerProvidedKey = customerProvidedKey }; var appendBlob = container.GetAppendBlobReference(GetRandomBlobName()); try { var context = new OperationContext(); // Act await appendBlob.CreateOrReplaceAsync(null, options, context); // Assert Assert.IsTrue(context.RequestResults.First().IsRequestServerEncrypted); Assert.AreEqual(options.CustomerProvidedKey.KeySHA256, context.RequestResults.First().EncryptionKeySHA256); } finally { await container.DeleteAsync(); } }
public async Task AppendBlobReadStreamBasicTestAsync() { byte[] buffer = GetRandomBuffer(4 * 1024 * 1024); CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); CloudAppendBlob blob = container.GetAppendBlobReference("blob1"); await blob.CreateOrReplaceAsync(); using (MemoryStream wholeBlob = new MemoryStream(buffer)) { #if !FACADE_NETCORE await blob.AppendBlockAsync(wholeBlob); #else await blob.AppendBlockAsync(wholeBlob, null, null, null, null, CancellationToken.None); #endif } using (MemoryStream wholeBlob = new MemoryStream(buffer)) { using (Stream blobStream = (await blob.OpenReadAsync())) { TestHelper.AssertStreamsAreEqual(wholeBlob, blobStream); } } } finally { container.DeleteIfExistsAsync().Wait(); } }
public void CloudBlobClientObjects() { CloudBlobClient blobClient = GenerateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("container"); Assert.AreEqual(blobClient, container.ServiceClient); CloudBlockBlob blockBlob = container.GetBlockBlobReference("blockblob"); Assert.AreEqual(blobClient, blockBlob.ServiceClient); CloudPageBlob pageBlob = container.GetPageBlobReference("pageblob"); Assert.AreEqual(blobClient, pageBlob.ServiceClient); CloudAppendBlob appendBlob = container.GetAppendBlobReference("appendblob"); Assert.AreEqual(blobClient, appendBlob.ServiceClient); CloudBlobContainer container2 = GetRandomContainerReference(); Assert.AreNotEqual(blobClient, container2.ServiceClient); CloudBlockBlob blockBlob2 = container2.GetBlockBlobReference("blockblob"); Assert.AreEqual(container2.ServiceClient, blockBlob2.ServiceClient); CloudPageBlob pageBlob2 = container2.GetPageBlobReference("pageblob"); Assert.AreEqual(container2.ServiceClient, pageBlob2.ServiceClient); CloudAppendBlob appendBlob2 = container2.GetAppendBlobReference("appendblob"); Assert.AreEqual(container2.ServiceClient, appendBlob2.ServiceClient); }
public async Task AppendBlobReadStreamSeekTestAsync() { byte[] buffer = GetRandomBuffer(3 * 1024 * 1024); CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); CloudAppendBlob blob = container.GetAppendBlobReference("blob1"); await blob.CreateOrReplaceAsync(); blob.StreamMinimumReadSizeInBytes = 2 * 1024 * 1024; using (MemoryStream wholeBlob = new MemoryStream(buffer)) { await blob.AppendBlockAsync(wholeBlob); } OperationContext opContext = new OperationContext(); using (Stream blobStream = await blob.OpenReadAsync(null, null, opContext)) { #if WINDOWS_RT int attempts = await BlobReadStreamSeekTestAsync(blobStream.AsRandomAccessStream(), blob.StreamMinimumReadSizeInBytes, buffer); #else int attempts = await BlobReadStreamSeekTestAsync(blobStream, blob.StreamMinimumReadSizeInBytes, buffer); #endif TestHelper.AssertNAttempts(opContext, attempts); } } finally { container.DeleteIfExistsAsync().Wait(); } }
public static List <string> CreateBlobsTask(CloudBlobContainer container, int count, BlobType type) { string name; List <string> blobs = new List <string>(); for (int i = 0; i < count; i++) { switch (type) { case BlobType.BlockBlob: name = "bb" + Guid.NewGuid().ToString(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(name); blockBlob.PutBlockListAsync(new string[] { }).Wait(); blobs.Add(name); break; case BlobType.PageBlob: name = "pb" + Guid.NewGuid().ToString(); CloudPageBlob pageBlob = container.GetPageBlobReference(name); pageBlob.CreateAsync(0).Wait(); blobs.Add(name); break; case BlobType.AppendBlob: name = "ab" + Guid.NewGuid().ToString(); CloudAppendBlob appendBlob = container.GetAppendBlobReference(name); appendBlob.CreateOrReplaceAsync().Wait(); blobs.Add(name); break; } } return(blobs); }
public async Task CloudAppendBlobCreateEncryptionScopeTask() { // Arrange CloudBlobContainer container = GetRandomContainerReference(); await container.CreateAsync(); var encryptionScope = TestBase.TargetTenantConfig.EncryptionScope; var options = new BlobRequestOptions { EncryptionScope = encryptionScope }; var appendBlob = container.GetAppendBlobReference(GetRandomBlobName()); try { var context = new OperationContext(); // Act await appendBlob.CreateOrReplaceAsync(null, options, context); await appendBlob.FetchAttributesAsync(); // Assert Assert.AreEqual(options.EncryptionScope, appendBlob.Properties.EncryptionScope); } finally { await container.DeleteAsync(); } }
public async Task CloudAppendBlobAppendBlockFromUrlCPKTask() { // Arrange CloudBlobContainer container = GetRandomContainerReference(); await container.CreateAsync(); var containerPermissions = await container.GetPermissionsAsync(); containerPermissions.PublicAccess = BlobContainerPublicAccessType.Container; await container.SetPermissionsAsync(containerPermissions); var customerProvidedKey = BuildCustomerProvidedKey(); var options = new BlobRequestOptions { CustomerProvidedKey = customerProvidedKey, }; var sourceAppendBlob = container.GetAppendBlobReference(GetRandomBlobName()); await sourceAppendBlob.CreateOrReplaceAsync(); var destAppendBlob = container.GetAppendBlobReference(GetRandomBlobName()); await destAppendBlob.CreateOrReplaceAsync(null, options, null); try { byte[] buffer = GetRandomBuffer(1024); using (MemoryStream sourceStream = new MemoryStream(buffer)) { await sourceAppendBlob.AppendBlockAsync(sourceStream); } var context = new OperationContext(); // Act await destAppendBlob.AppendBlockAsync(sourceAppendBlob.Uri, 0, 1024, null, null, null, options, context, CancellationToken.None); // Assert Assert.IsTrue(context.RequestResults.First().IsRequestServerEncrypted); Assert.AreEqual(options.CustomerProvidedKey.KeySHA256, context.RequestResults.First().EncryptionKeySHA256); } finally { await container.DeleteAsync(); } }
public async Task CloudAppendBlobAppendBlockFromUrlEncryptionScopeTask() { // Arrange CloudBlobContainer container = GetRandomContainerReference(); await container.CreateAsync(); var containerPermissions = await container.GetPermissionsAsync(); containerPermissions.PublicAccess = BlobContainerPublicAccessType.Container; await container.SetPermissionsAsync(containerPermissions); var encryptionScope = TestBase.TargetTenantConfig.EncryptionScope; var options = new BlobRequestOptions { EncryptionScope = encryptionScope }; var sourceAppendBlob = container.GetAppendBlobReference(GetRandomBlobName()); await sourceAppendBlob.CreateOrReplaceAsync(); var destAppendBlob = container.GetAppendBlobReference(GetRandomBlobName()); await destAppendBlob.CreateOrReplaceAsync(null, options, null); try { byte[] buffer = GetRandomBuffer(1024); using (MemoryStream sourceStream = new MemoryStream(buffer)) { await sourceAppendBlob.AppendBlockAsync(sourceStream); } var context = new OperationContext(); // Act await destAppendBlob.AppendBlockAsync(sourceAppendBlob.Uri, 0, 1024, null, null, null, options, context, CancellationToken.None); // Assert Assert.AreEqual(options.EncryptionScope, context.RequestResults.First().EncryptionScope); } finally { await container.DeleteAsync(); } }
public void CloudBlobSnapshotMetadataAPM() { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); var blobName = GetRandomBlobName(); CloudAppendBlob appendBlob = container.GetAppendBlobReference(blobName); appendBlob.CreateOrReplace(); CloudBlob blob = container.GetBlobReference(blobName); blob.Metadata["Hello"] = "World"; blob.Metadata["Marco"] = "Polo"; blob.SetMetadata(); IDictionary <string, string> snapshotMetadata = new Dictionary <string, string>(); snapshotMetadata["Hello"] = "Dolly"; snapshotMetadata["Yoyo"] = "Ma"; IAsyncResult result; using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { result = blob.BeginSnapshot(snapshotMetadata, null, null, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); CloudBlob snapshot = blob.EndSnapshot(result); // Test the client view against the expected metadata // Metadata keys should be case-insensitive // None of the original metadata should be present Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]); Assert.AreEqual("Dolly", snapshot.Metadata["HELLO"]); Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]); Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco")); // Test the server view against the expected metadata snapshot.FetchAttributes(); Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]); Assert.AreEqual("Dolly", snapshot.Metadata["HELLO"]); Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]); Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco")); } } finally { container.DeleteIfExists(); } }
public async Task CloudBlobSnapshotMetadataTask() { CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); var blobName = GetRandomBlobName(); CloudAppendBlob appendBlob = container.GetAppendBlobReference(blobName); await appendBlob.CreateOrReplaceAsync(null, null, new OperationContext()); CloudBlob blob = container.GetBlobReference(blobName); blob.Metadata["Hello"] = "World"; blob.Metadata["Marco"] = "Polo"; await blob.SetMetadataAsync(); IDictionary <string, string> snapshotMetadata = new Dictionary <string, string>(); snapshotMetadata["Hello"] = "Dolly"; snapshotMetadata["Yoyo"] = "Ma"; CloudBlob snapshot = await blob.SnapshotAsync(snapshotMetadata, null, null, null); // Test the client view against the expected metadata // Metadata keys should be case-insensitive // None of the original metadata should be present Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]); Assert.AreEqual("Dolly", snapshot.Metadata["HELLO"]); Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]); Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco")); // Test the server view against the expected metadata await snapshot.FetchAttributesAsync(); Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]); Assert.AreEqual("Dolly", snapshot.Metadata["HELLO"]); Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]); Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco")); } finally { await container.DeleteIfExistsAsync(); } }
public void CloudBlobContainerReference() { CloudBlobClient client = GenerateCloudBlobClient(); CloudBlobContainer container = client.GetContainerReference("container"); CloudBlockBlob blockBlob = container.GetBlockBlobReference("directory1/blob1"); CloudPageBlob pageBlob = container.GetPageBlobReference("directory2/blob2"); CloudAppendBlob appendBlob = container.GetAppendBlobReference("directory3/blob3"); CloudBlobDirectory directory = container.GetDirectoryReference("directory4"); CloudBlobDirectory directory2 = directory.GetDirectoryReference("directory5"); Assert.AreEqual(container, blockBlob.Container); Assert.AreEqual(container, pageBlob.Container); Assert.AreEqual(container, appendBlob.Container); Assert.AreEqual(container, directory.Container); Assert.AreEqual(container, directory2.Container); Assert.AreEqual(container, directory2.Parent.Container); Assert.AreEqual(container, blockBlob.Parent.Container); Assert.AreEqual(container, blockBlob.Parent.Container); }
public void CloudBlobSnapshotMetadata() { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); CloudAppendBlob appendBlob = container.GetAppendBlobReference(BlobName); appendBlob.CreateOrReplace(); CloudBlob blob = container.GetBlobReference(BlobName); blob.Metadata["Hello"] = "World"; blob.Metadata["Marco"] = "Polo"; blob.SetMetadata(); IDictionary <string, string> snapshotMetadata = new Dictionary <string, string>(); snapshotMetadata["Hello"] = "Dolly"; snapshotMetadata["Yoyo"] = "Ma"; CloudBlob snapshot = blob.Snapshot(snapshotMetadata); // Test the client view against the expected metadata // Metadata keys should be case-insensitive // None of the original metadata should be present Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]); Assert.AreEqual("Dolly", snapshot.Metadata["HELLO"]); Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]); Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco")); // Test the server view against the expected metadata snapshot.FetchAttributes(); Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]); Assert.AreEqual("Dolly", snapshot.Metadata["HELLO"]); Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]); Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco")); } finally { container.DeleteIfExists(); } }
public async Task CloudBlobGetPropertiesSetMetadataCPKTask() { // Arrange CloudBlobContainer container = GetRandomContainerReference(); await container.CreateAsync(); var customerProvidedKey = BuildCustomerProvidedKey(); var options = new BlobRequestOptions { CustomerProvidedKey = customerProvidedKey }; var appendBlob = container.GetAppendBlobReference(GetRandomBlobName()); await appendBlob.CreateOrReplaceAsync(null, options, null); try { // Act var context = new OperationContext(); await appendBlob.FetchAttributesAsync(null, options, context); // Assert Assert.IsTrue(context.RequestResults.First().IsServiceEncrypted); Assert.AreEqual(options.CustomerProvidedKey.KeySHA256, context.RequestResults.First().EncryptionKeySHA256); // Arrange appendBlob.Metadata.Add("foo", "bar"); context = new OperationContext(); // Act await appendBlob.SetMetadataAsync(null, options, context); // Assert Assert.IsTrue(context.RequestResults.First().IsRequestServerEncrypted); Assert.AreEqual(options.CustomerProvidedKey.KeySHA256, context.RequestResults.First().EncryptionKeySHA256); } finally { await container.DeleteAsync(); } }
public async Task CloudBlobGetPropertiesSetMetadataEncryptionScopeTask() { // Arrange CloudBlobContainer container = GetRandomContainerReference(); await container.CreateAsync(); var encryptionScope = TestBase.TargetTenantConfig.EncryptionScope; var options = new BlobRequestOptions { EncryptionScope = encryptionScope }; var appendBlob = container.GetAppendBlobReference(GetRandomBlobName()); await appendBlob.CreateOrReplaceAsync(null, options, null); try { // Act var context = new OperationContext(); await appendBlob.FetchAttributesAsync(null, options, context); // Assert Assert.AreEqual(options.EncryptionScope, context.RequestResults.First().EncryptionScope); Assert.AreEqual(options.EncryptionScope, appendBlob.Properties.EncryptionScope); // Arrange appendBlob.Metadata.Add("foo", "bar"); context = new OperationContext(); // Act await appendBlob.SetMetadataAsync(null, options, context); // Assert Assert.AreEqual(options.EncryptionScope, context.RequestResults.First().EncryptionScope); } finally { await container.DeleteAsync(); } }
public async Task CloudBlobListBlobSegmentEncryptionScopeTask() { // Arrange CloudBlobContainer container = GetRandomContainerReference(); await container.CreateAsync(); var encryptionScope = TestBase.TargetTenantConfig.EncryptionScope; var options = new BlobRequestOptions { EncryptionScope = encryptionScope }; var appendBlob = container.GetAppendBlobReference(GetRandomBlobName()); await appendBlob.CreateOrReplaceAsync(null, options, null, CancellationToken.None); try { BlobContinuationToken token = null; do { BlobResultSegment results = await container.ListBlobsSegmentedAsync(token); foreach (IListBlobItem blobItem in results.Results) { CloudBlob blob = blobItem as CloudBlob; // Assert Assert.AreEqual(options.EncryptionScope, blob.Properties.EncryptionScope); } token = results.ContinuationToken; }while (token != null); } finally { await container.DeleteAsync(); } }
public static async Task <List <string> > CreateBlobs(CloudBlobContainer container, int count, BlobType type) { string name; List <string> blobs = new List <string>(); List <Task> tasks = new List <Task>(); for (int i = 0; i < count; i++) { switch (type) { case BlobType.BlockBlob: name = "bb" + Guid.NewGuid().ToString(); CloudBlockBlob blockBlob = container.GetBlockBlobReference(name); tasks.Add(Task.Run(() => blockBlob.PutBlockList(new string[] { }))); blobs.Add(name); break; case BlobType.PageBlob: name = "pb" + Guid.NewGuid().ToString(); CloudPageBlob pageBlob = container.GetPageBlobReference(name); tasks.Add(Task.Run(() => pageBlob.Create(0))); blobs.Add(name); break; case BlobType.AppendBlob: name = "ab" + Guid.NewGuid().ToString(); CloudAppendBlob appendBlob = container.GetAppendBlobReference(name); tasks.Add(Task.Run(() => appendBlob.CreateOrReplace())); blobs.Add(name); break; } } await Task.WhenAll(tasks); return(blobs); }
public void CloudBlobSoftDeleteSnapshot() { CloudBlobContainer container = GetRandomContainerReference(); try { //Enables a delete retention policy on the blob with 1 day of default retention days container.ServiceClient.EnableSoftDelete(); container.Create(); // Upload some data to the blob. var blobName = GetRandomBlobName(); MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024)); CloudAppendBlob appendBlob = container.GetAppendBlobReference(blobName); appendBlob.UploadFromStream(originalData); CloudBlob blob = container.GetBlobReference(blobName); //create snapshot via api CloudBlob snapshot = blob.Snapshot(); //create snapshot via write protection appendBlob.UploadFromStream(originalData); //we should have 2 snapshots 1 regular and 1 deleted: there is no way to get only the deleted snapshots but the below listing will get both snapshot types int blobCount = 0; int deletedSnapshotCount = 0; int snapShotCount = 0; foreach (IListBlobItem item in container.ListBlobs(null, true, BlobListingDetails.Snapshots | BlobListingDetails.Deleted)) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, blobName); if (blobItem.IsSnapshot) { snapShotCount++; } if (blobItem.IsDeleted) { Assert.IsNotNull(blobItem.Properties.DeletedTime); Assert.AreEqual(blobItem.Properties.RemainingDaysBeforePermanentDelete, 0); deletedSnapshotCount++; } blobCount++; } Assert.AreEqual(blobCount, 3); Assert.AreEqual(deletedSnapshotCount, 1); Assert.AreEqual(snapShotCount, 2); blobCount = 0; foreach (IListBlobItem item in container.ListBlobs(null, true, BlobListingDetails.Snapshots)) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, blobName); Assert.IsFalse(blobItem.IsDeleted); Assert.IsNull(blobItem.Properties.DeletedTime); Assert.IsNull(blobItem.Properties.RemainingDaysBeforePermanentDelete); blobCount++; } Assert.AreEqual(blobCount, 2); //Delete Blob and snapshots blob.Delete(DeleteSnapshotsOption.IncludeSnapshots); Assert.IsFalse(blob.Exists()); Assert.IsFalse(snapshot.Exists()); blobCount = 0; foreach (IListBlobItem item in container.ListBlobs(null, true, BlobListingDetails.All)) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, blobName); Assert.IsTrue(blobItem.IsDeleted); Assert.IsNotNull(blobItem.Properties.DeletedTime); Assert.AreEqual(blobItem.Properties.RemainingDaysBeforePermanentDelete, 0); blobCount++; } Assert.AreEqual(blobCount, 3); blob.Undelete(); blob.FetchAttributes(); Assert.IsFalse(blob.IsDeleted); Assert.IsNull(blob.Properties.DeletedTime); Assert.IsNull(blob.Properties.RemainingDaysBeforePermanentDelete); blobCount = 0; foreach (IListBlobItem item in container.ListBlobs(null, true, BlobListingDetails.All)) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, blobName); Assert.IsFalse(blobItem.IsDeleted); Assert.IsNull(blobItem.Properties.DeletedTime); Assert.IsNull(blobItem.Properties.RemainingDaysBeforePermanentDelete); blobCount++; } Assert.AreEqual(blobCount, 3); } finally { container.ServiceClient.DisableSoftDelete(); container.DeleteIfExists(); } }
public async Task CloudBlobContainerGetBlobReferenceFromServerAsync() { CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), }; CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb"); await blockBlob.PutBlockListAsync(new List <string>()); CloudPageBlob pageBlob = container.GetPageBlobReference("pb"); await pageBlob.CreateAsync(0); CloudAppendBlob appendBlob = container.GetAppendBlobReference("ab"); await appendBlob.CreateOrReplaceAsync(); CloudBlobClient client; ICloudBlob blob; blob = await container.GetBlobReferenceFromServerAsync("bb"); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); CloudBlockBlob blockBlobSnapshot = await((CloudBlockBlob)blob).CreateSnapshotAsync(); await blob.SetPropertiesAsync(); Uri blockBlobSnapshotUri = new Uri(blockBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + blockBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o")); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlobSnapshotUri); AssertAreEqual(blockBlobSnapshot.Properties, blob.Properties); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlobSnapshot.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.GetBlobReferenceFromServerAsync("pb"); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri)); CloudPageBlob pageBlobSnapshot = await((CloudPageBlob)blob).CreateSnapshotAsync(); await blob.SetPropertiesAsync(); Uri pageBlobSnapshotUri = new Uri(pageBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + pageBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o")); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlobSnapshotUri); AssertAreEqual(pageBlobSnapshot.Properties, blob.Properties); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlobSnapshot.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.GetBlobReferenceFromServerAsync("ab"); Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob)); Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri)); CloudAppendBlob appendBlobSnapshot = await((CloudAppendBlob)blob).CreateSnapshotAsync(); await blob.SetPropertiesAsync(); Uri appendBlobSnapshotUri = new Uri(appendBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + appendBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o")); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(appendBlobSnapshotUri); AssertAreEqual(appendBlobSnapshot.Properties, blob.Properties); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlobSnapshot.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlob.Uri); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlob.Uri); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(appendBlob.Uri); Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlob.StorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlob.StorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri)); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(appendBlob.StorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob)); Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri)); string blockBlobToken = blockBlob.GetSharedAccessSignature(policy); StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken); Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri); StorageUri blockBlobSASStorageUri = blockBlobSAS.TransformUri(blockBlob.StorageUri); string appendBlobToken = appendBlob.GetSharedAccessSignature(policy); StorageCredentials appendBlobSAS = new StorageCredentials(appendBlobToken); Uri appendBlobSASUri = appendBlobSAS.TransformUri(appendBlob.Uri); StorageUri appendBlobSASStorageUri = appendBlobSAS.TransformUri(appendBlob.StorageUri); string pageBlobToken = pageBlob.GetSharedAccessSignature(policy); StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken); Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri); StorageUri pageBlobSASStorageUri = pageBlobSAS.TransformUri(pageBlob.StorageUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(appendBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri)); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(appendBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob)); Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri)); client = new CloudBlobClient(container.ServiceClient.BaseUri, blockBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(blockBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); client = new CloudBlobClient(container.ServiceClient.BaseUri, pageBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(pageBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); client = new CloudBlobClient(container.ServiceClient.BaseUri, appendBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(appendBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); client = new CloudBlobClient(container.ServiceClient.StorageUri, blockBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(blockBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); client = new CloudBlobClient(container.ServiceClient.StorageUri, pageBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(pageBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri)); client = new CloudBlobClient(container.ServiceClient.StorageUri, appendBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(appendBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob)); Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri)); } finally { container.DeleteIfExistsAsync().Wait(); } }
public async Task CloudAppendBlobAppendBlockSnapshotEncryptionScopeTask() { // Arrange CloudBlobContainer container = GetRandomContainerReference(); await container.CreateAsync(); var encryptionScope = TestBase.TargetTenantConfig.EncryptionScope; var options = new BlobRequestOptions { EncryptionScope = encryptionScope }; var appendBlob = container.GetAppendBlobReference(GetRandomBlobName()); await appendBlob.CreateOrReplaceAsync(null, options, null); try { byte[] buffer = GetRandomBuffer(1024); using (MemoryStream sourceStream = new MemoryStream(buffer)) { var context = new OperationContext(); // Act await appendBlob.AppendBlockAsync(sourceStream, null, null, options, context); // Assert Assert.AreEqual(options.EncryptionScope, context.RequestResults.First().EncryptionScope); // Arrange context = new OperationContext(); using (MemoryStream downloadedBlob = new MemoryStream()) { // Act await appendBlob.DownloadRangeToStreamAsync(downloadedBlob, 0, 1024, null, options, context); // Assert TestHelper.AssertStreamsAreEqual(sourceStream, downloadedBlob); Assert.AreEqual(options.EncryptionScope, context.RequestResults.First().EncryptionScope); Assert.AreEqual(options.EncryptionScope, appendBlob.Properties.EncryptionScope); } // Arrange context = new OperationContext(); var metadata = new Dictionary <string, string> { { "foo", "bar" } }; // Act await appendBlob.SnapshotAsync(metadata, null, options, context); // Assert Assert.AreEqual(options.EncryptionScope, context.RequestResults.First().EncryptionScope); Assert.AreEqual(options.EncryptionScope, appendBlob.Properties.EncryptionScope); } } finally { await container.DeleteAsync(); } }
public async Task AppendBlobReadLockToETagTestAsync() { byte[] outBuffer = new byte[1 * 1024 * 1024]; byte[] buffer = GetRandomBuffer(2 * outBuffer.Length); CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); CloudAppendBlob blob = container.GetAppendBlobReference("blob1"); await blob.CreateOrReplaceAsync(); blob.StreamMinimumReadSizeInBytes = outBuffer.Length; using (MemoryStream wholeBlob = new MemoryStream(buffer)) { #if !FACADE_NETCORE await blob.AppendBlockAsync(wholeBlob); #else await blob.AppendBlockAsync(wholeBlob, string.Empty, null, null, null, CancellationToken.None); #endif } OperationContext opContext = new OperationContext(); using (Stream blobStream = await blob.OpenReadAsync(null, null, opContext)) { Stream blobStreamForRead = blobStream; await blobStreamForRead.ReadAsync(outBuffer, 0, outBuffer.Length); await blob.SetMetadataAsync(); await TestHelper.ExpectedExceptionAsync( async() => await blobStreamForRead.ReadAsync(outBuffer, 0, outBuffer.Length), opContext, "Blob read stream should fail if blob is modified during read", HttpStatusCode.PreconditionFailed); } opContext = new OperationContext(); using (Stream blobStream = await blob.OpenReadAsync(null, null, opContext)) { Stream blobStreamForRead = blobStream; long length = blobStreamForRead.Length; await blob.SetMetadataAsync(); await TestHelper.ExpectedExceptionAsync( async() => await blobStreamForRead.ReadAsync(outBuffer, 0, outBuffer.Length), opContext, "Blob read stream should fail if blob is modified during read", HttpStatusCode.PreconditionFailed); } opContext = new OperationContext(); AccessCondition accessCondition = AccessCondition.GenerateIfNotModifiedSinceCondition(DateTimeOffset.Now.Subtract(TimeSpan.FromHours(1))); await blob.SetMetadataAsync(); await TestHelper.ExpectedExceptionAsync( async() => await blob.OpenReadAsync(accessCondition, null, opContext), opContext, "Blob read stream should fail if blob is modified during read", HttpStatusCode.PreconditionFailed); } finally { container.DeleteIfExistsAsync().Wait(); } }
public void CloudBlobSnapshotAPM() { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); var blobName = GetRandomBlobName(); MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024)); CloudAppendBlob appendBlob = container.GetAppendBlobReference(blobName); appendBlob.CreateOrReplace(); appendBlob.AppendBlock(originalData, null); CloudBlob blob = container.GetBlobReference(blobName); blob.FetchAttributes(); IAsyncResult result; using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { result = blob.BeginSnapshot(ar => waitHandle.Set(), null); waitHandle.WaitOne(); CloudBlob snapshot1 = blob.EndSnapshot(result); Assert.AreEqual(blob.Properties.ETag, snapshot1.Properties.ETag); Assert.AreEqual(blob.Properties.LastModified, snapshot1.Properties.LastModified); Assert.IsTrue(snapshot1.IsSnapshot); Assert.IsNotNull(snapshot1.SnapshotTime, "Snapshot does not have SnapshotTime set"); Assert.AreEqual(blob.Uri, snapshot1.Uri); Assert.AreNotEqual(blob.SnapshotQualifiedUri, snapshot1.SnapshotQualifiedUri); Assert.AreNotEqual(snapshot1.Uri, snapshot1.SnapshotQualifiedUri); Assert.IsTrue(snapshot1.SnapshotQualifiedUri.Query.Contains("snapshot")); result = blob.BeginSnapshot(ar => waitHandle.Set(), null); waitHandle.WaitOne(); CloudBlob snapshot2 = blob.EndSnapshot(result); Assert.IsTrue(snapshot2.SnapshotTime.Value > snapshot1.SnapshotTime.Value); snapshot1.FetchAttributes(); snapshot2.FetchAttributes(); blob.FetchAttributes(); AssertAreEqual(snapshot1.Properties, blob.Properties); CloudBlob snapshotCopy = container.GetBlobReference("blob2"); result = snapshotCopy.BeginStartCopy(snapshot1.Uri, null, null, null, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); snapshotCopy.EndStartCopy(result); WaitForCopy(snapshotCopy); Assert.AreEqual(CopyStatus.Success, snapshotCopy.CopyState.Status); result = snapshot1.BeginOpenRead(ar => waitHandle.Set(), null); waitHandle.WaitOne(); using (Stream snapshotStream = snapshot1.EndOpenRead(result)) { snapshotStream.Seek(0, SeekOrigin.End); TestHelper.AssertStreamsAreEqual(originalData, snapshotStream); } result = appendBlob.BeginCreateOrReplace(ar => waitHandle.Set(), null); waitHandle.WaitOne(); appendBlob.EndCreateOrReplace(result); result = blob.BeginFetchAttributes(ar => waitHandle.Set(), null); waitHandle.WaitOne(); blob.EndFetchAttributes(result); result = snapshot1.BeginOpenRead(ar => waitHandle.Set(), null); waitHandle.WaitOne(); using (Stream snapshotStream = snapshot1.EndOpenRead(result)) { snapshotStream.Seek(0, SeekOrigin.End); TestHelper.AssertStreamsAreEqual(originalData, snapshotStream); } List <IListBlobItem> blobs = container.ListBlobs(null, true, BlobListingDetails.All, null, null).ToList(); Assert.AreEqual(4, blobs.Count); AssertAreEqual(snapshotCopy, (CloudBlob)blobs[0]); AssertAreEqual(snapshot1, (CloudBlob)blobs[1]); AssertAreEqual(snapshot2, (CloudBlob)blobs[2]); AssertAreEqual(blob, (CloudBlob)blobs[3]); } } finally { container.DeleteIfExists(); } }
public async Task CloudAppendBlobAppendBlockSnapshotCPKTask() { // Arrange CloudBlobContainer container = GetRandomContainerReference(); await container.CreateAsync(); var customerProvidedKey = BuildCustomerProvidedKey(); var options = new BlobRequestOptions { CustomerProvidedKey = customerProvidedKey }; var appendBlob = container.GetAppendBlobReference(GetRandomBlobName()); await appendBlob.CreateOrReplaceAsync(null, options, null); try { byte[] buffer = GetRandomBuffer(1024); using (MemoryStream sourceStream = new MemoryStream(buffer)) { var context = new OperationContext(); // Act await appendBlob.AppendBlockAsync(sourceStream, null, null, options, context); // Assert Assert.IsTrue(context.RequestResults.First().IsRequestServerEncrypted); Assert.AreEqual(options.CustomerProvidedKey.KeySHA256, context.RequestResults.First().EncryptionKeySHA256); // Arrange context = new OperationContext(); using (MemoryStream downloadedBlob = new MemoryStream()) { // Act await appendBlob.DownloadRangeToStreamAsync(downloadedBlob, 0, 1024, null, options, context); // Assert TestHelper.AssertStreamsAreEqual(sourceStream, downloadedBlob); Assert.IsTrue(context.RequestResults.First().IsServiceEncrypted); Assert.AreEqual(options.CustomerProvidedKey.KeySHA256, context.RequestResults.First().EncryptionKeySHA256); } // Arrange context = new OperationContext(); var metadata = new Dictionary <string, string> { { "foo", "bar" } }; // Act await appendBlob.SnapshotAsync(metadata, null, options, context); // Assert Assert.IsTrue(context.RequestResults.First().IsRequestServerEncrypted); Assert.AreEqual(options.CustomerProvidedKey.KeySHA256, context.RequestResults.First().EncryptionKeySHA256); } } finally { await container.DeleteAsync(); } }
public async Task CloudBlobSnapshotTask() { CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); var blobName = GetRandomBlobName(); MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024)); CloudAppendBlob appendBlob = container.GetAppendBlobReference(blobName); await appendBlob.CreateOrReplaceAsync(); await appendBlob.AppendBlockAsync(originalData, null); CloudBlob blob = container.GetBlobReference(blobName); await blob.FetchAttributesAsync(); CloudBlob snapshot1 = await blob.SnapshotAsync(); Assert.AreEqual(blob.Properties.ETag, snapshot1.Properties.ETag); Assert.AreEqual(blob.Properties.LastModified, snapshot1.Properties.LastModified); Assert.IsTrue(snapshot1.IsSnapshot); Assert.IsNotNull(snapshot1.SnapshotTime, "Snapshot does not have SnapshotTime set"); Assert.AreEqual(blob.Uri, snapshot1.Uri); Assert.AreNotEqual(blob.SnapshotQualifiedUri, snapshot1.SnapshotQualifiedUri); Assert.AreNotEqual(snapshot1.Uri, snapshot1.SnapshotQualifiedUri); Assert.IsTrue(snapshot1.SnapshotQualifiedUri.Query.Contains("snapshot")); CloudBlob snapshot2 = await blob.SnapshotAsync(); Assert.IsTrue(snapshot2.SnapshotTime.Value > snapshot1.SnapshotTime.Value); await snapshot1.FetchAttributesAsync(); await snapshot2.FetchAttributesAsync(); await blob.FetchAttributesAsync(); AssertAreEqual(snapshot1.Properties, blob.Properties); CloudBlob snapshot1Clone = new CloudBlob(new Uri(blob.Uri + "?snapshot=" + snapshot1.SnapshotTime.Value.ToString("O")), blob.ServiceClient.Credentials); Assert.IsNotNull(snapshot1Clone.SnapshotTime, "Snapshot clone does not have SnapshotTime set"); Assert.AreEqual(snapshot1.SnapshotTime.Value, snapshot1Clone.SnapshotTime.Value); await snapshot1Clone.FetchAttributesAsync(); AssertAreEqual(snapshot1.Properties, snapshot1Clone.Properties); CloudBlob snapshotCopy = container.GetBlobReference("blob2"); await snapshotCopy.StartCopyAsync(snapshot1.Uri, null, null, null, null); await WaitForCopyAsync(snapshotCopy); Assert.AreEqual(CopyStatus.Success, snapshotCopy.CopyState.Status); using (Stream snapshotStream = await snapshot1.OpenReadAsync()) { snapshotStream.Seek(0, SeekOrigin.End); TestHelper.AssertStreamsAreEqual(originalData, snapshotStream); } //overwriting will create another snapshot await appendBlob.CreateOrReplaceAsync(); await blob.FetchAttributesAsync(); using (Stream snapshotStream = await snapshot1.OpenReadAsync()) { snapshotStream.Seek(0, SeekOrigin.End); TestHelper.AssertStreamsAreEqual(originalData, snapshotStream); } await Task.Delay(500); List <IListBlobItem> blobs = (await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, null, null)) .Results .ToList(); Assert.AreEqual(4, blobs.Count); AssertAreEqual(snapshotCopy, (CloudBlob)blobs[0]); AssertAreEqual(snapshot1, (CloudBlob)blobs[1]); AssertAreEqual(snapshot2, (CloudBlob)blobs[2]); AssertAreEqual(blob, (CloudBlob)blobs[3]); } finally { await container.DeleteIfExistsAsync(); } }
public void CloudBlobSoftDeleteNoSnapshot() { CloudBlobContainer container = GetRandomContainerReference(); try { //Enables a delete retention policy on the blob with 1 day of default retention days container.ServiceClient.EnableSoftDelete(); Shared.Protocol.ServiceProperties props = container.ServiceClient.GetServiceProperties(); container.Create(); // Upload some data to the blob. var blobName = GetRandomBlobName(); MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024)); CloudAppendBlob appendBlob = container.GetAppendBlobReference(blobName); appendBlob.CreateOrReplace(); appendBlob.AppendBlock(originalData, null); CloudBlob blob = container.GetBlobReference(blobName); Assert.IsTrue(blob.Exists()); Assert.IsFalse(blob.IsDeleted); blob.Delete(); Assert.IsFalse(blob.Exists()); int blobCount = 0; foreach (IListBlobItem item in container.ListBlobs(null, true, BlobListingDetails.Snapshots | BlobListingDetails.Deleted)) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, blobName); Assert.IsTrue(blobItem.IsDeleted); Assert.IsNotNull(blobItem.Properties.DeletedTime); Assert.AreEqual(blobItem.Properties.RemainingDaysBeforePermanentDelete, 0); blobCount++; } Assert.AreEqual(blobCount, 1); blob.Undelete(); blob.FetchAttributes(); Assert.IsFalse(blob.IsDeleted); Assert.IsNull(blob.Properties.DeletedTime); Assert.IsNull(blob.Properties.RemainingDaysBeforePermanentDelete); blobCount = 0; foreach (IListBlobItem item in container.ListBlobs(null, true, BlobListingDetails.All)) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, blobName); Assert.IsFalse(blobItem.IsDeleted); Assert.IsNull(blobItem.Properties.DeletedTime); Assert.IsNull(blobItem.Properties.RemainingDaysBeforePermanentDelete); blobCount++; } Assert.AreEqual(blobCount, 1); } finally { container.ServiceClient.DisableSoftDelete(); container.DeleteIfExists(); } }
public void CloudBlobSnapshot() { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); // Upload some data to the blob. var blobName = GetRandomBlobName(); MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024)); CloudAppendBlob appendBlob = container.GetAppendBlobReference(blobName); appendBlob.CreateOrReplace(); appendBlob.AppendBlock(originalData, null); CloudBlob blob = container.GetBlobReference(blobName); blob.FetchAttributes(); Assert.IsFalse(blob.IsSnapshot); Assert.IsNull(blob.SnapshotTime, "Root blob has SnapshotTime set"); Assert.IsFalse(blob.SnapshotQualifiedUri.Query.Contains("snapshot")); Assert.AreEqual(blob.Uri, blob.SnapshotQualifiedUri); CloudBlob snapshot1 = blob.Snapshot(); Assert.AreEqual(blob.Properties.ETag, snapshot1.Properties.ETag); Assert.AreEqual(blob.Properties.LastModified, snapshot1.Properties.LastModified); Assert.IsTrue(snapshot1.IsSnapshot); Assert.IsNotNull(snapshot1.SnapshotTime, "Snapshot does not have SnapshotTime set"); Assert.AreEqual(blob.Uri, snapshot1.Uri); Assert.AreNotEqual(blob.SnapshotQualifiedUri, snapshot1.SnapshotQualifiedUri); Assert.AreNotEqual(snapshot1.Uri, snapshot1.SnapshotQualifiedUri); Assert.IsTrue(snapshot1.SnapshotQualifiedUri.Query.Contains("snapshot")); CloudBlob snapshot2 = blob.Snapshot(); Assert.IsTrue(snapshot2.SnapshotTime.Value > snapshot1.SnapshotTime.Value); snapshot1.FetchAttributes(); snapshot2.FetchAttributes(); blob.FetchAttributes(); AssertAreEqual(snapshot1.Properties, blob.Properties, false); CloudBlob snapshot1Clone = new CloudBlob(new Uri(blob.Uri + "?snapshot=" + snapshot1.SnapshotTime.Value.ToString("O")), blob.ServiceClient.Credentials); Assert.IsNotNull(snapshot1Clone.SnapshotTime, "Snapshot clone does not have SnapshotTime set"); Assert.AreEqual(snapshot1.SnapshotTime.Value, snapshot1Clone.SnapshotTime.Value); snapshot1Clone.FetchAttributes(); AssertAreEqual(snapshot1.Properties, snapshot1Clone.Properties, false); // The query parser should not be case sensitive in detecting a snapshot in the query string CloudBlob snapshotParseVerifier = new CloudBlob(new Uri(blob.Uri + "?sNapshOt=" + snapshot1.SnapshotTime.Value.ToString("O")), blob.ServiceClient.Credentials); Assert.IsNotNull(snapshotParseVerifier.SnapshotTime, "Snapshot parse verifier did not successfully detect the snapshot time"); Assert.AreEqual(snapshot1.SnapshotTime.Value, snapshotParseVerifier.SnapshotTime.Value); CloudBlob snapshotCopy = container.GetBlobReference("blob2"); snapshotCopy.StartCopy(TestHelper.Defiddler(snapshot1.Uri)); WaitForCopy(snapshotCopy); Assert.AreEqual(CopyStatus.Success, snapshotCopy.CopyState.Status); using (Stream snapshotStream = snapshot1.OpenRead()) { snapshotStream.Seek(0, SeekOrigin.End); TestHelper.AssertStreamsAreEqual(originalData, snapshotStream); } //overwriting the blob and creating the 5th snapshot appendBlob.CreateOrReplace(); blob.FetchAttributes(); using (Stream snapshotStream = snapshot1.OpenRead()) { snapshotStream.Seek(0, SeekOrigin.End); TestHelper.AssertStreamsAreEqual(originalData, snapshotStream); } List <IListBlobItem> blobs = container.ListBlobs(null, true, BlobListingDetails.All, null, null).ToList(); Assert.AreEqual(4, blobs.Count); AssertAreEqual(snapshotCopy, (CloudBlob)blobs[0]); AssertAreEqual(snapshot1, (CloudBlob)blobs[1]); AssertAreEqual(snapshot2, (CloudBlob)blobs[2]); AssertAreEqual(blob, (CloudBlob)blobs[3]); } finally { container.DeleteIfExists(); } }
public async Task UseTransactionalMD5PutTestAsync() { BlobRequestOptions optionsWithNoMD5 = new BlobRequestOptions() { UseTransactionalMD5 = false, }; BlobRequestOptions optionsWithMD5 = new BlobRequestOptions() { UseTransactionalMD5 = true, }; byte[] buffer = GetRandomBuffer(1024); MD5 hasher = MD5.Create(); string md5 = Convert.ToBase64String(hasher.ComputeHash(buffer)); string lastCheckMD5 = null; int checkCount = 0; OperationContext opContextWithMD5Check = new OperationContext(); opContextWithMD5Check.SendingRequest += (_, args) => { if (HttpRequestParsers.GetContentLength(args.Request) >= buffer.Length) { lastCheckMD5 = HttpRequestParsers.GetContentMD5(args.Request); checkCount++; } }; CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1"); List <string> blockIds = GetBlockIdList(3); checkCount = 0; using (Stream blockData = new MemoryStream(buffer)) { lastCheckMD5 = "invalid_md5"; await blockBlob.PutBlockAsync(blockIds[0], blockData, null, null, optionsWithNoMD5, opContextWithMD5Check); Assert.IsNull(lastCheckMD5); lastCheckMD5 = "invalid_md5"; blockData.Seek(0, SeekOrigin.Begin); await blockBlob.PutBlockAsync(blockIds[1], blockData, null, null, optionsWithMD5, opContextWithMD5Check); Assert.AreEqual(md5, lastCheckMD5); lastCheckMD5 = "invalid_md5"; blockData.Seek(0, SeekOrigin.Begin); await blockBlob.PutBlockAsync(blockIds[2], blockData, md5, null, optionsWithNoMD5, opContextWithMD5Check); Assert.AreEqual(md5, lastCheckMD5); } Assert.AreEqual(3, checkCount); checkCount = 0; CloudAppendBlob appendBlob = container.GetAppendBlobReference("blob2"); await appendBlob.CreateOrReplaceAsync(); checkCount = 0; using (Stream blockData = new MemoryStream(buffer)) { lastCheckMD5 = "invalid_md5"; await appendBlob.AppendBlockAsync(blockData, null, null, optionsWithNoMD5, opContextWithMD5Check); Assert.IsNull(lastCheckMD5); lastCheckMD5 = "invalid_md5"; blockData.Seek(0, SeekOrigin.Begin); await appendBlob.AppendBlockAsync(blockData, null, null, optionsWithMD5, opContextWithMD5Check); Assert.AreEqual(md5, lastCheckMD5); lastCheckMD5 = "invalid_md5"; blockData.Seek(0, SeekOrigin.Begin); await appendBlob.AppendBlockAsync(blockData, md5, null, optionsWithNoMD5, opContextWithMD5Check); Assert.AreEqual(md5, lastCheckMD5); } Assert.AreEqual(3, checkCount); CloudPageBlob pageBlob = container.GetPageBlobReference("blob3"); await pageBlob.CreateAsync(buffer.Length); checkCount = 0; using (Stream pageData = new MemoryStream(buffer)) { lastCheckMD5 = "invalid_md5"; await pageBlob.WritePagesAsync(pageData, 0, null, null, optionsWithNoMD5, opContextWithMD5Check); Assert.IsNull(lastCheckMD5); lastCheckMD5 = "invalid_md5"; pageData.Seek(0, SeekOrigin.Begin); await pageBlob.WritePagesAsync(pageData, 0, null, null, optionsWithMD5, opContextWithMD5Check); Assert.AreEqual(md5, lastCheckMD5); lastCheckMD5 = "invalid_md5"; pageData.Seek(0, SeekOrigin.Begin); await pageBlob.WritePagesAsync(pageData, 0, md5, null, optionsWithNoMD5, opContextWithMD5Check); Assert.AreEqual(md5, lastCheckMD5); } Assert.AreEqual(3, checkCount); lastCheckMD5 = null; blockBlob = container.GetBlockBlobReference("blob4"); checkCount = 0; using (Stream blobStream = await blockBlob.OpenWriteAsync(null, optionsWithMD5, opContextWithMD5Check)) { blobStream.Write(buffer, 0, buffer.Length); blobStream.Write(buffer, 0, buffer.Length); } Assert.IsNotNull(lastCheckMD5); Assert.AreEqual(1, checkCount); lastCheckMD5 = "invalid_md5"; blockBlob = container.GetBlockBlobReference("blob5"); checkCount = 0; using (Stream blobStream = await blockBlob.OpenWriteAsync(null, optionsWithNoMD5, opContextWithMD5Check)) { blobStream.Write(buffer, 0, buffer.Length); blobStream.Write(buffer, 0, buffer.Length); } Assert.IsNull(lastCheckMD5); Assert.AreEqual(1, checkCount); lastCheckMD5 = null; pageBlob = container.GetPageBlobReference("blob6"); checkCount = 0; using (Stream blobStream = await pageBlob.OpenWriteAsync(buffer.Length * 3, null, optionsWithMD5, opContextWithMD5Check)) { blobStream.Write(buffer, 0, buffer.Length); blobStream.Write(buffer, 0, buffer.Length); } Assert.IsNotNull(lastCheckMD5); Assert.AreEqual(1, checkCount); lastCheckMD5 = "invalid_md5"; pageBlob = container.GetPageBlobReference("blob7"); checkCount = 0; using (Stream blobStream = await pageBlob.OpenWriteAsync(buffer.Length * 3, null, optionsWithNoMD5, opContextWithMD5Check)) { blobStream.Write(buffer, 0, buffer.Length); blobStream.Write(buffer, 0, buffer.Length); } Assert.IsNull(lastCheckMD5); Assert.AreEqual(1, checkCount); } finally { await container.DeleteIfExistsAsync(); } }
public async Task CloudBlobSoftDeleteSnapshotTask() { CloudBlobContainer container = GetRandomContainerReference(); try { //Enables a delete retention policy on the blob with 1 day of default retention days container.ServiceClient.EnableSoftDelete(); await container.CreateAsync(); // Upload some data to the blob. MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024)); CloudAppendBlob appendBlob = container.GetAppendBlobReference(BlobName); await appendBlob.UploadFromStreamAsync(originalData); CloudBlob blob = container.GetBlobReference(BlobName); //create snapshot via api CloudBlob snapshot = await blob.SnapshotAsync(); //create snapshot via write protection await appendBlob.UploadFromStreamAsync(originalData); //we should have 2 snapshots 1 regular and 1 deleted: there is no way to get only the deleted snapshots but the below listing will get both snapshot types int blobCount = 0; int deletedSnapshotCount = 0; int snapShotCount = 0; BlobContinuationToken ct = null; do { foreach (IListBlobItem item in (await container.ListBlobsSegmentedAsync (null, true, BlobListingDetails.Snapshots | BlobListingDetails.Deleted, null, ct, null, null)) .Results .ToList()) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, BlobName); if (blobItem.IsSnapshot) { snapShotCount++; } if (blobItem.IsDeleted) { Assert.IsNotNull(blobItem.Properties.DeletedTime); Assert.AreEqual(blobItem.Properties.RemainingDaysBeforePermanentDelete, 0); deletedSnapshotCount++; } blobCount++; } } while (ct != null); Assert.AreEqual(blobCount, 3); Assert.AreEqual(deletedSnapshotCount, 1); Assert.AreEqual(snapShotCount, 2); blobCount = 0; ct = null; do { foreach (IListBlobItem item in (await container.ListBlobsSegmentedAsync (null, true, BlobListingDetails.Snapshots, null, ct, null, null)) .Results .ToList()) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, BlobName); Assert.IsFalse(blobItem.IsDeleted); Assert.IsNull(blobItem.Properties.DeletedTime); Assert.IsNull(blobItem.Properties.RemainingDaysBeforePermanentDelete); blobCount++; } } while (ct != null); Assert.AreEqual(blobCount, 2); //Delete Blob and snapshots await blob.DeleteAsync(DeleteSnapshotsOption.IncludeSnapshots, null, null, null); Assert.IsFalse(await blob.ExistsAsync()); Assert.IsFalse(await snapshot.ExistsAsync()); blobCount = 0; ct = null; do { foreach (IListBlobItem item in (await container.ListBlobsSegmentedAsync (null, true, BlobListingDetails.All, null, ct, null, null)) .Results .ToList()) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, BlobName); Assert.IsTrue(blobItem.IsDeleted); Assert.IsNotNull(blobItem.Properties.DeletedTime); Assert.AreEqual(blobItem.Properties.RemainingDaysBeforePermanentDelete, 0); blobCount++; } } while (ct != null); Assert.AreEqual(blobCount, 3); await blob.UndeleteAsync(); await blob.FetchAttributesAsync(); Assert.IsFalse(blob.IsDeleted); Assert.IsNull(blob.Properties.DeletedTime); Assert.IsNull(blob.Properties.RemainingDaysBeforePermanentDelete); blobCount = 0; ct = null; do { foreach (IListBlobItem item in (await container.ListBlobsSegmentedAsync (null, true, BlobListingDetails.All, null, ct, null, null)) .Results .ToList()) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, BlobName); Assert.IsFalse(blobItem.IsDeleted); Assert.IsNull(blobItem.Properties.DeletedTime); Assert.IsNull(blobItem.Properties.RemainingDaysBeforePermanentDelete); blobCount++; } } while (ct != null); Assert.AreEqual(blobCount, 3); } finally { container.ServiceClient.DisableSoftDelete(); await container.DeleteAsync(); } }
public async Task CloudBlobSoftDeleteNoSnapshotTask() { CloudBlobContainer container = GetRandomContainerReference(); try { //Enables a delete retention policy on the blob with 1 day of default retention days container.ServiceClient.EnableSoftDelete(); await container.CreateAsync(); // Upload some data to the blob. MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024)); CloudAppendBlob appendBlob = container.GetAppendBlobReference(BlobName); await appendBlob.CreateOrReplaceAsync(); await appendBlob.AppendBlockAsync(originalData, null); CloudBlob blob = container.GetBlobReference(BlobName); Assert.IsTrue(await blob.ExistsAsync()); Assert.IsFalse(blob.IsDeleted); await blob.DeleteAsync(); Assert.IsFalse(await blob.ExistsAsync()); int blobCount = 0; BlobContinuationToken ct = null; do { foreach (IListBlobItem item in (await container.ListBlobsSegmentedAsync (null, true, BlobListingDetails.All, null, ct, null, null)) .Results .ToList()) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, BlobName); Assert.IsTrue(blobItem.IsDeleted); Assert.IsNotNull(blobItem.Properties.DeletedTime); Assert.AreEqual(blobItem.Properties.RemainingDaysBeforePermanentDelete, 0); blobCount++; } } while (ct != null); Assert.AreEqual(blobCount, 1); await blob.UndeleteAsync(); await blob.FetchAttributesAsync(); Assert.IsFalse(blob.IsDeleted); Assert.IsNull(blob.Properties.DeletedTime); Assert.IsNull(blob.Properties.RemainingDaysBeforePermanentDelete); blobCount = 0; ct = null; do { foreach (IListBlobItem item in (await container.ListBlobsSegmentedAsync (null, true, BlobListingDetails.All, null, ct, null, null)) .Results .ToList()) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, BlobName); Assert.IsFalse(blobItem.IsDeleted); Assert.IsNull(blobItem.Properties.DeletedTime); Assert.IsNull(blobItem.Properties.RemainingDaysBeforePermanentDelete); blobCount++; } } while (ct != null); Assert.AreEqual(blobCount, 1); } finally { container.ServiceClient.DisableSoftDelete(); await container.DeleteAsync(); } }
public async Task UseTransactionalCRC64PutTestAsync() { BlobRequestOptions optionsWithNoCRC64 = new BlobRequestOptions() { ChecksumOptions = new ChecksumOptions { UseTransactionalCRC64 = false } }; BlobRequestOptions optionsWithCRC64 = new BlobRequestOptions() { ChecksumOptions = new ChecksumOptions { UseTransactionalCRC64 = true } }; byte[] buffer = GetRandomBuffer(1024); Crc64Wrapper hasher = new Crc64Wrapper(); hasher.UpdateHash(buffer, 0, buffer.Length); string crc64 = hasher.ComputeHash(); string lastCheckCRC64 = null; int checkCount = 0; OperationContext opContextWithCRC64Check = new OperationContext(); opContextWithCRC64Check.SendingRequest += (_, args) => { if (HttpRequestParsers.GetContentLength(args.Request) >= buffer.Length) { lastCheckCRC64 = HttpRequestParsers.GetContentCRC64(args.Request); checkCount++; } }; OperationContext opContextWithCRC64CheckAndInjectedFailure = new OperationContext(); opContextWithCRC64CheckAndInjectedFailure.SendingRequest += (_, args) => { args.Response.Headers.Remove(Constants.HeaderConstants.ContentCrc64Header); args.Request.Headers.TryAddWithoutValidation(Constants.HeaderConstants.ContentCrc64Header, "dummy"); if (HttpRequestParsers.GetContentLength(args.Request) >= buffer.Length) { lastCheckCRC64 = HttpRequestParsers.GetContentCRC64(args.Request); checkCount++; } }; CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob1"); List <string> blockIds = GetBlockIdList(3); checkCount = 0; using (Stream blockData = new MemoryStream(buffer)) { lastCheckCRC64 = "invalid_CRC64"; await blockBlob.PutBlockAsync(blockIds[0], blockData, null, null, optionsWithNoCRC64, opContextWithCRC64Check); Assert.IsNull(lastCheckCRC64); lastCheckCRC64 = "invalid_CRC64"; blockData.Seek(0, SeekOrigin.Begin); await blockBlob.PutBlockAsync(blockIds[1], blockData, null, null, optionsWithCRC64, opContextWithCRC64Check); Assert.AreEqual(crc64, lastCheckCRC64); blockData.Seek(0, SeekOrigin.Begin); await TestHelper.ExpectedExceptionAsync <StorageException>( () => blockBlob.PutBlockAsync(blockIds[1], blockData, null, null, optionsWithCRC64, opContextWithCRC64CheckAndInjectedFailure), "Calculated CRC64 does not match existing property" ); lastCheckCRC64 = "invalid_CRC64"; blockData.Seek(0, SeekOrigin.Begin); await blockBlob.PutBlockAsync(blockIds[2], blockData, new Checksum(crc64 : crc64), null, optionsWithNoCRC64, opContextWithCRC64Check); Assert.AreEqual(crc64, lastCheckCRC64); } Assert.AreEqual(3, checkCount); checkCount = 0; CloudAppendBlob appendBlob = container.GetAppendBlobReference("blob2"); await appendBlob.CreateOrReplaceAsync(); checkCount = 0; using (Stream blockData = new MemoryStream(buffer)) { lastCheckCRC64 = "invalid_CRC64"; await appendBlob.AppendBlockAsync(blockData, null, null, optionsWithNoCRC64, opContextWithCRC64Check); Assert.IsNull(lastCheckCRC64); lastCheckCRC64 = "invalid_CRC64"; blockData.Seek(0, SeekOrigin.Begin); await appendBlob.AppendBlockAsync(blockData, null, null, optionsWithCRC64, opContextWithCRC64Check); Assert.AreEqual(crc64, lastCheckCRC64); blockData.Seek(0, SeekOrigin.Begin); await TestHelper.ExpectedExceptionAsync <StorageException>( () => appendBlob.AppendBlockAsync(blockData, null, null, optionsWithCRC64, opContextWithCRC64CheckAndInjectedFailure), "Calculated CRC64 does not match existing property" ); lastCheckCRC64 = "invalid_CRC64"; blockData.Seek(0, SeekOrigin.Begin); await appendBlob.AppendBlockAsync(blockData, new Checksum(crc64 : crc64), null, optionsWithNoCRC64, opContextWithCRC64Check); Assert.AreEqual(crc64, lastCheckCRC64); } Assert.AreEqual(3, checkCount); CloudPageBlob pageBlob = container.GetPageBlobReference("blob3"); await pageBlob.CreateAsync(buffer.Length); checkCount = 0; using (Stream pageData = new MemoryStream(buffer)) { lastCheckCRC64 = "invalid_CRC64"; await pageBlob.WritePagesAsync(pageData, 0, null, null, optionsWithNoCRC64, opContextWithCRC64Check); Assert.IsNull(lastCheckCRC64); lastCheckCRC64 = "invalid_CRC64"; pageData.Seek(0, SeekOrigin.Begin); await pageBlob.WritePagesAsync(pageData, 0, null, null, optionsWithCRC64, opContextWithCRC64Check); Assert.AreEqual(crc64, lastCheckCRC64); pageData.Seek(0, SeekOrigin.Begin); await TestHelper.ExpectedExceptionAsync <StorageException>( () => pageBlob.WritePagesAsync(pageData, 0, null, null, optionsWithCRC64, opContextWithCRC64CheckAndInjectedFailure), "Calculated CRC64 does not match existing property" ); lastCheckCRC64 = "invalid_CRC64"; pageData.Seek(0, SeekOrigin.Begin); await pageBlob.WritePagesAsync(pageData, 0, new Checksum(crc64 : crc64), null, optionsWithNoCRC64, opContextWithCRC64Check); Assert.AreEqual(crc64, lastCheckCRC64); } Assert.AreEqual(3, checkCount); lastCheckCRC64 = null; blockBlob = container.GetBlockBlobReference("blob4"); checkCount = 0; using (Stream blobStream = await blockBlob.OpenWriteAsync(null, optionsWithCRC64, opContextWithCRC64Check)) { blobStream.Write(buffer, 0, buffer.Length); blobStream.Write(buffer, 0, buffer.Length); } Assert.IsNotNull(lastCheckCRC64); Assert.AreEqual(1, checkCount); lastCheckCRC64 = "invalid_CRC64"; blockBlob = container.GetBlockBlobReference("blob5"); checkCount = 0; using (Stream blobStream = await blockBlob.OpenWriteAsync(null, optionsWithNoCRC64, opContextWithCRC64Check)) { blobStream.Write(buffer, 0, buffer.Length); blobStream.Write(buffer, 0, buffer.Length); } Assert.IsNull(lastCheckCRC64); Assert.AreEqual(1, checkCount); lastCheckCRC64 = null; pageBlob = container.GetPageBlobReference("blob6"); checkCount = 0; using (Stream blobStream = await pageBlob.OpenWriteAsync(buffer.Length * 3, null, optionsWithCRC64, opContextWithCRC64Check)) { blobStream.Write(buffer, 0, buffer.Length); blobStream.Write(buffer, 0, buffer.Length); } Assert.IsNotNull(lastCheckCRC64); Assert.AreEqual(1, checkCount); lastCheckCRC64 = "invalid_CRC64"; pageBlob = container.GetPageBlobReference("blob7"); checkCount = 0; using (Stream blobStream = await pageBlob.OpenWriteAsync(buffer.Length * 3, null, optionsWithNoCRC64, opContextWithCRC64Check)) { blobStream.Write(buffer, 0, buffer.Length); blobStream.Write(buffer, 0, buffer.Length); } Assert.IsNull(lastCheckCRC64); Assert.AreEqual(1, checkCount); } finally { await container.DeleteIfExistsAsync(); } }
public void CloudBlobSoftDeleteNoSnapshotAPM() { CloudBlobContainer container = GetRandomContainerReference(); try { //Enables a delete retention policy on the blob with 1 day of default retention days container.ServiceClient.EnableSoftDelete(); container.Create(); // Upload some data to the blob. var blobName = GetRandomBlobName(); MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024)); CloudAppendBlob appendBlob = container.GetAppendBlobReference(blobName); appendBlob.CreateOrReplace(); appendBlob.AppendBlock(originalData, null); CloudBlob blob = container.GetBlobReference(blobName); Assert.IsFalse(blob.IsDeleted); IAsyncResult result; using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { result = blob.BeginDelete(DeleteSnapshotsOption.None, null, null, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); blob.EndDelete(result); } Assert.IsFalse(blob.Exists()); int blobCount = 0; foreach (IListBlobItem item in container.ListBlobs(null, true, BlobListingDetails.All)) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, blobName); Assert.IsTrue(blobItem.IsDeleted); Assert.IsNotNull(blobItem.Properties.DeletedTime); Assert.AreEqual(blobItem.Properties.RemainingDaysBeforePermanentDelete, 0); blobCount++; } Assert.AreEqual(1, blobCount); using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { result = blob.BeginUndelete(ar => waitHandle.Set(), null); waitHandle.WaitOne(); blob.EndUndelete(result); } blob.FetchAttributes(); Assert.IsFalse(blob.IsDeleted); Assert.IsNull(blob.Properties.DeletedTime); Assert.IsNull(blob.Properties.RemainingDaysBeforePermanentDelete); blobCount = 0; foreach (IListBlobItem item in container.ListBlobs(null, true, BlobListingDetails.All)) { CloudAppendBlob blobItem = (CloudAppendBlob)item; Assert.AreEqual(blobItem.Name, blobName); Assert.IsFalse(blobItem.IsDeleted); Assert.IsNull(blobItem.Properties.DeletedTime); Assert.IsNull(blobItem.Properties.RemainingDaysBeforePermanentDelete); blobCount++; } Assert.AreEqual(blobCount, 1); } finally { container.ServiceClient.DisableSoftDelete(); container.DeleteIfExists(); } }