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 Get() { #region Snippet:Managing_StorageAccounts_GetStorageAccount StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); StorageAccount storageAccount = await accountContainer.GetAsync("myAccount"); Console.WriteLine(storageAccount.Id.Name); #endregion }
public async Task Delete() { #region Snippet:Managing_StorageAccounts_DeleteStorageAccount StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); StorageAccount storageAccount = await accountContainer.GetAsync("myAccount"); await storageAccount.DeleteAsync(); #endregion }
public async Task AddTag() { #region Snippet:Managing_StorageAccounts_AddTagStorageAccount StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); StorageAccount storageAccount = await accountContainer.GetAsync("myAccount"); // add a tag on this storage account await storageAccount.AddTagAsync("key", "value"); #endregion }
public async Task UpdateStorageAccount() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccount account1 = (await storageAccountContainer.CreateOrUpdateAsync(accountName, GetDefaultStorageAccountParameters())).Value; VerifyAccountProperties(account1, true); //update sku StorageAccountUpdateParameters parameters = new StorageAccountUpdateParameters() { Sku = new Sku(SkuName.StandardLRS), }; account1 = await account1.UpdateAsync(parameters); Assert.AreEqual(account1.Data.Sku.Name, SkuName.StandardLRS); // validate StorageAccount account2 = await storageAccountContainer.GetAsync(accountName); Assert.AreEqual(account2.Data.Sku.Name, SkuName.StandardLRS); //update tags parameters.Tags.Clear(); parameters.Tags.Add("key3", "value3"); parameters.Tags.Add("key4", "value4"); parameters.Tags.Add("key5", "value5"); account1 = await account1.UpdateAsync(parameters); Assert.AreEqual(account1.Data.Tags.Count, parameters.Tags.Count); //validate account2 = await storageAccountContainer.GetAsync(accountName); Assert.AreEqual(account2.Data.Tags.Count, parameters.Tags.Count); //update encryption parameters.Encryption = new Encryption(KeySource.MicrosoftStorage) { Services = new EncryptionServices { Blob = new EncryptionService { Enabled = true }, File = new EncryptionService { Enabled = true } } }; account1 = await account1.UpdateAsync(parameters); Assert.NotNull(account1.Data.Encryption); //validate account2 = await storageAccountContainer.GetAsync(accountName); Assert.NotNull(account2.Data.Encryption); Assert.NotNull(account2.Data.Encryption.Services.Blob); Assert.True(account2.Data.Encryption.Services.Blob.Enabled); Assert.NotNull(account2.Data.Encryption.Services.Blob.LastEnabledTime); Assert.NotNull(account2.Data.Encryption.Services.File); Assert.True(account2.Data.Encryption.Services.File.Enabled); Assert.NotNull(account2.Data.Encryption.Services.File.LastEnabledTime); //update http traffic only and validate parameters = new StorageAccountUpdateParameters() { EnableHttpsTrafficOnly = false }; account1 = await account1.UpdateAsync(parameters); Assert.AreEqual(account1.Data.EnableHttpsTrafficOnly, false); account2 = await storageAccountContainer.GetAsync(accountName); Assert.AreEqual(account2.Data.EnableHttpsTrafficOnly, false); parameters = new StorageAccountUpdateParameters() { EnableHttpsTrafficOnly = true }; account1 = await account1.UpdateAsync(parameters); Assert.AreEqual(account1.Data.EnableHttpsTrafficOnly, true); account2 = await storageAccountContainer.GetAsync(accountName); Assert.AreEqual(account2.Data.EnableHttpsTrafficOnly, true); }