public async Task AddTag() { SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false); var rg1Op = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, Recording.GenerateAssetName("testrg"), new ResourceGroupData(AzureLocation.WestUS2)); ResourceGroupResource rg1 = rg1Op.Value; Assert.AreEqual(0, rg1.Data.Tags.Count); ResourceGroupResource rg2 = await rg1.AddTagAsync("key", "value"); Assert.AreEqual(1, rg2.Data.Tags.Count); Assert.IsTrue(rg2.Data.Tags.Contains(new KeyValuePair <string, string>("key", "value"))); Assert.AreEqual(rg1.Data.Name, rg2.Data.Name); Assert.AreEqual(rg1.Data.Id, rg2.Data.Id); Assert.AreEqual(rg1.Data.ResourceType, rg2.Data.ResourceType); Assert.AreEqual(rg1.Data.Properties.ProvisioningState, rg2.Data.Properties.ProvisioningState); Assert.AreEqual(rg1.Data.Location, rg2.Data.Location); Assert.AreEqual(rg1.Data.ManagedBy, rg2.Data.ManagedBy); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg1.AddTagAsync(null, "value")); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => _ = await rg1.AddTagAsync(" ", "value")); Assert.AreEqual(400, ex.Status); }
public async Task TestAddTags(string key, string value, IDictionary <string, string> tags) { if (key is null || value is null) { var ex = Assert.ThrowsAsync <ArgumentNullException>(async() => await _rg.AddTagAsync(key, value)); Assert.That(ex.Message.Contains("Value cannot be null")); }
public async Task SetUpAsync() { var rgOp = await(await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName(_rgPrefix)); _rg = rgOp.Value; _rg = await _rg.AddTagAsync("key1", "value1"); _rg = await _rg.AddTagAsync("key2", "value2"); }
public async Task UpdateAResourceGroup() { #region Snippet:Managing_Resource_Groups_UpdateAResourceGroup // Note: Resource group named 'myRgName' should exist for this example to work. ArmClient client = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync(); ResourceGroupCollection resourceGroups = subscription.GetResourceGroups(); string resourceGroupName = "myRgName"; ResourceGroupResource resourceGroup = await resourceGroups.GetAsync(resourceGroupName); resourceGroup = await resourceGroup.AddTagAsync("key", "value"); #endregion Snippet:Managing_Resource_Groups_UpdateAResourceGroup }