public async Task CreateDeleteBlobContainer()
        {
            //create blob container
            string        containerName = Recording.GenerateAssetName("testblob");
            BlobContainer container1    = (await _blobContainerCollection.CreateOrUpdateAsync(containerName, new BlobContainerData())).Value;

            Assert.IsNotNull(container1);
            Assert.AreEqual(container1.Id.Name, containerName);

            //validate if created successfully
            BlobContainer container2 = await _blobContainerCollection.GetAsync(containerName);

            AssertBlobContainerEqual(container1, container2);
            Assert.IsTrue(await _blobContainerCollection.CheckIfExistsAsync(containerName));
            Assert.IsFalse(await _blobContainerCollection.CheckIfExistsAsync(containerName + "1"));
            BlobContainerData containerData = container1.Data;

            Assert.IsEmpty(containerData.Metadata);
            Assert.IsFalse(containerData.HasLegalHold);
            Assert.IsNull(containerData.PublicAccess);
            Assert.False(containerData.HasImmutabilityPolicy);

            //delete blob container
            BlobContainerDeleteOperation blobContainerDeleteOperation = await container1.DeleteAsync();

            await blobContainerDeleteOperation.WaitForCompletionResponseAsync();

            //validate if deleted successfully
            BlobContainer blobContainer3 = await _blobContainerCollection.GetIfExistsAsync(containerName);

            Assert.IsNull(blobContainer3);
            Assert.IsFalse(await _blobContainerCollection.CheckIfExistsAsync(containerName));
        }
Esempio n. 2
0
        public async virtual Task <BlobContainerDeleteOperation> DeleteAsync(bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            using var scope = _clientDiagnostics.CreateScope("BlobContainer.Delete");
            scope.Start();
            try
            {
                var response = await _restClient.DeleteAsync(Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, cancellationToken).ConfigureAwait(false);

                var operation = new BlobContainerDeleteOperation(response);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }