示例#1
0
        public async Task CreateDeleteStorageAccount()
        {
            //create storage account
            string accountName = await CreateValidAccountNameAsync(namePrefix);

            _resourceGroup = await CreateResourceGroupAsync();

            StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts();
            StorageAccount          account1 = (await storageAccountContainer.CreateOrUpdateAsync(accountName, GetDefaultStorageAccountParameters())).Value;

            Assert.AreEqual(accountName, account1.Id.Name);
            VerifyAccountProperties(account1, true);
            AssertStorageAccountEqual(account1, await account1.GetAsync());

            //validate if created successfully
            StorageAccount account2 = await storageAccountContainer.GetAsync(accountName);

            VerifyAccountProperties(account2, true);
            AssertStorageAccountEqual(account1, account2);
            StorageAccount account3 = await storageAccountContainer.GetIfExistsAsync(accountName + "1");

            Assert.IsNull(account3);
            Assert.IsTrue(await storageAccountContainer.CheckIfExistsAsync(accountName));
            Assert.IsFalse(await storageAccountContainer.CheckIfExistsAsync(accountName + "1"));

            //delete storage account
            await account1.DeleteAsync();

            //validate if deleted successfully
            Assert.IsFalse(await storageAccountContainer.CheckIfExistsAsync(accountName));
            StorageAccount account4 = await storageAccountContainer.GetIfExistsAsync(accountName);

            Assert.IsNull(account4);
        }
        public async Task GetIfExist()
        {
            #region Snippet:Managing_StorageAccounts_GetStorageAccountIfExists
            StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts();
            StorageAccount          storageAccount   = await accountContainer.GetIfExistsAsync("foo");

            if (storageAccount != null)
            {
                Console.WriteLine(storageAccount.Id.Name);
            }
            if (await accountContainer.CheckIfExistsAsync("bar"))
            {
                Console.WriteLine("storage account 'bar' exists");
            }
            #endregion
        }