public async Task AddTag()
        {
            Subscription subscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false);

            var rg1Op = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, Recording.GenerateAssetName("testrg"), new ResourceGroupData(AzureLocation.WestUS2));

            ResourceGroup rg1 = rg1Op.Value;

            Assert.AreEqual(0, rg1.Data.Tags.Count);
            ResourceGroup 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.Type, rg2.Data.Type);
            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 SetUpAsync()
 {
     var rgOp = await (await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName(_rgPrefix));
     _rg = rgOp.Value;
     _rg = await _rg.AddTagAsync("key1", "value1");
     _rg = await _rg.AddTagAsync("key2", "value2");
 }
Example #3
0
        public async Task UpdateAResourceGroup()
        {
            #region Snippet:Managing_Resource_Groups_UpdateAResourceGroup
            // Note: Resource group named 'myRgName' should exist for this example to work.
            ArmClient    armClient    = new ArmClient(new DefaultAzureCredential());
            Subscription subscription = await armClient.GetDefaultSubscriptionAsync();

            string rgName = "myRgName";
#if !SNIPPET
            //Check if 'myRgName' exists, if not, create it first or run CreateResourceGroup()
            ResourceGroup rg = await subscription.GetResourceGroups().GetIfExistsAsync(rgName);

            if (rg == null)
            {
                AzureLocation           location     = AzureLocation.WestUS2;
                ResourceGroupCollection rgCollection = subscription.GetResourceGroups();
                ResourceGroupData       rgData       = new ResourceGroupData(location);
                _ = await rgCollection.CreateOrUpdateAsync(true, rgName, rgData);
            }
#endif
            ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);

            resourceGroup = await resourceGroup.AddTagAsync("key", "value");

            #endregion Snippet:Managing_Resource_Groups_UpdateAResourceGroup
        }
 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"));
     }
Example #5
0
        public async Task SetUpAsync()
        {
            _rg = await Client.DefaultSubscription.GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName(_rgPrefix));

            _rg = await _rg.AddTagAsync("key1", "value1");

            _rg = await _rg.AddTagAsync("key2", "value2");
        }
 public async Task TestAddTags(string key, string value, IDictionary<string, string> tags)
 {
     if (key is null)
     {
         var ex = Assert.ThrowsAsync<ArgumentException>(async () => await _rg.AddTagAsync(key, value));
         Assert.That(ex.Message.Contains("key provided cannot be null or a whitespace"));
     }
     else if (value is null)
     {
         var ex = Assert.ThrowsAsync<Azure.RequestFailedException>(async () => await _rg.AddTagAsync(key, value));
         Assert.That(ex.Message.Contains("Invalid tag value. The following tags 'nullKey' have a null value. Tag value cannot be null."));
     }
     else
     {
         var result = await _rg.AddTagAsync(key, value);
         Assert.AreEqual(result.Value.Data.Tags, tags);
     }
 }
Example #7
0
        public async Task AddTag()
        {
            ResourceGroup rg1 = await Client.DefaultSubscription.GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));

            Assert.AreEqual(0, rg1.Data.Tags.Count);
            ResourceGroup 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.Type, rg2.Data.Type);
            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 <ArgumentException>(async() => _ = await rg1.AddTagAsync(null, "value"));
            Assert.ThrowsAsync <ArgumentException>(async() => _ = await rg1.AddTagAsync(" ", "value"));
        }
Example #8
0
        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());
            Subscription subscription = await client.GetDefaultSubscriptionAsync();

            ResourceGroupCollection resourceGroups = subscription.GetResourceGroups();
            string        resourceGroupName        = "myRgName";
            ResourceGroup resourceGroup            = await resourceGroups.GetAsync(resourceGroupName);

            resourceGroup = await resourceGroup.AddTagAsync("key", "value");

            #endregion Snippet:Managing_Resource_Groups_UpdateAResourceGroup
        }
Example #9
0
        public async Task UpdateAResourceGroup()
        {
            #region Snippet:Managing_Resource_Groups_UpdateAResourceGroup
            // Note: Resource group named 'myRgName' should exist for this example to work.
            var          armClient    = new ArmClient(new DefaultAzureCredential());
            Subscription subscription = armClient.DefaultSubscription;
            string       rgName       = "myRgName";
#if !SNIPPET
            //Check if 'myRgName' exists, if not, create it first or run CreateResourceGroup()
            var rg = await subscription.GetResourceGroups().TryGetAsync(rgName);

            if (rg == null)
            {
                Location location    = Location.WestUS2;
                var      rgContainer = subscription.GetResourceGroups();
                _ = await rgContainer.Construct(location).CreateOrUpdateAsync(rgName);
            }
#endif
            ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);

            resourceGroup = await resourceGroup.AddTagAsync("key", "value");

            #endregion Snippet:Managing_Resource_Groups_UpdateAResourceGroup
        }