/// <summary>
        /// Utility method to test Get request for Tags Operation within tracked resources and proxy resources
        /// </summary>
        private void GetTagsTest(string resourceScope, MockContext context)
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var client = GetResourceManagementClient(context, handler);

            // using Tags.CreateOrUpdateAtScope to create two tags initially
            var tagsResource = new TagsResource(new Tags(
                                                    new Dictionary <string, string> {
                { "tagKey1", "tagValue1" },
                { "tagKey2", "tagValue2" }
            }
                                                    ));

            client.Tags.CreateOrUpdateAtScope(resourceScope, tagsResource);
            Thread.Sleep(3000);

            // get request should return created TagsResource
            var getResponse = client.Tags.GetAtScope(resourceScope);

            getResponse.Properties.TagsProperty.Should().HaveCount(tagsResource.Properties.TagsProperty.Count);
            this.CompareTagsResource(tagsResource, getResponse).Should().BeTrue();
        }
        /// <summary>
        /// Utility method to test Delete request for Tags Operation within tracked resources and proxy resources
        /// </summary>
        private TagsResource DeleteTagsTest(string resourceScope, MockContext context)
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = GetResourceManagementClient(context, handler);

            // using Tags.CreateOrUpdateAtScope to create two tags initially
            var tagsResource = new TagsResource(new Tags(
                                                    new Dictionary <string, string> {
                { "tagKey1", "tagValue1" },
                { "tagKey2", "tagValue2" }
            }
                                                    ));

            client.Tags.CreateOrUpdateAtScope(resourceScope, tagsResource);
            Thread.Sleep(3000);

            // try to delete existing tags
            client.Tags.DeleteAtScope(resourceScope);
            Thread.Sleep(3000);

            // after deletion, Get request should get 0 tags back
            return(client.Tags.GetAtScope(resourceScope));
        }
Beispiel #3
0
        /// <summary>
        /// Utility method to test Get request for Tags Operation within tracked resources and proxy resources
        /// </summary>
        private async void GetTagsTest(string resourceScope = "")
        {
            var subscriptionScope = "/subscriptions/" + TestEnvironment.SubscriptionId;

            resourceScope = subscriptionScope + resourceScope;

            // using Tags.CreateOrUpdateAtScope to create two tags initially
            var tagsResource = new TagsResource(new Tags()
            {
                TagsValue = new Dictionary <string, string> {
                    { "tagKey1", "tagValue1" },
                    { "tagKey2", "tagValue2" }
                }
            });
            await TagsOperations.CreateOrUpdateAtScopeAsync(resourceScope, tagsResource);

            if (Mode == RecordedTestMode.Record)
            {
                Thread.Sleep(3 * 1000);
            }

            // get request should return created TagsResource
            var getResponse = (await TagsOperations.GetAtScopeAsync(resourceScope)).Value;

            Assert.AreEqual(getResponse.Properties.TagsValue.Count(), tagsResource.Properties.TagsValue.Count());
            Assert.IsTrue(this.CompareTagsResource(tagsResource, getResponse));
        }
Beispiel #4
0
        /// <summary>
        /// Utility method to test Delete request for Tags Operation within tracked resources and proxy resources
        /// </summary>
        private async Task <TagsResource> DeleteTagsTest(string resourceScope = "")
        {
            var subscriptionScope = "//subscriptions/" + TestEnvironment.SubscriptionId;

            resourceScope = subscriptionScope + resourceScope;

            // using Tags.CreateOrUpdateAtScope to create two tags initially
            var tagsResource = new TagsResource(new Tags()
            {
                TagsValue = new Dictionary <string, string> {
                    { "tagKey1", "tagValue1" },
                    { "tagKey2", "tagValue2" }
                }
            });
            await TagsOperations.CreateOrUpdateAtScopeAsync(resourceScope, tagsResource);

            if (Mode == RecordedTestMode.Record)
            {
                Thread.Sleep(3 * 1000);
            }

            // try to delete existing tags
            await TagsOperations.DeleteAtScopeAsync(resourceScope);

            if (Mode == RecordedTestMode.Record)
            {
                Thread.Sleep(15 * 1000);
            }

            // after deletion, Get request should get 0 tags back
            var result = (await TagsOperations.GetAtScopeAsync(resourceScope)).Value;;

            return(result);
        }
        /// <summary>
        /// Utility method to test Patch request for Tags Operation within tracked resources and proxy resources, including Replace|Merge|Delete operations
        /// </summary>
        private void UpdateTagsTest(MockContext context, string resourceScope = "")
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var client            = GetResourceManagementClient(context, handler);
            var subscriptionScope = "/subscriptions/" + client.SubscriptionId;

            resourceScope = subscriptionScope + resourceScope;

            // using Tags.CreateOrUpdateAtScope to create two tags initially
            var tagsResource = new TagsResource(new Tags(
                                                    new Dictionary <string, string> {
                { "tagKey1", "tagValue1" },
                { "tagKey2", "tagValue2" }
            }
                                                    ));

            client.Tags.CreateOrUpdateAtScope(resourceScope, tagsResource);
            Thread.Sleep(3000);

            var putTags = new Tags(
                new Dictionary <string, string> {
                { "tagKey1", "tagValue3" },
                { "tagKey3", "tagValue3" }
            });

            { // test for Merge operation
                var tagPatchRequest = new TagsPatchResource("Merge", putTags);
                var patchResponse   = client.Tags.UpdateAtScope(resourceScope, tagPatchRequest);

                var expectedResponse = new TagsResource(new Tags(
                                                            new Dictionary <string, string> {
                    { "tagKey1", "tagValue3" },
                    { "tagKey2", "tagValue2" },
                    { "tagKey3", "tagValue3" }
                }
                                                            ));
                patchResponse.Properties.TagsProperty.Should().HaveCount(expectedResponse.Properties.TagsProperty.Count);
                this.CompareTagsResource(expectedResponse, patchResponse).Should().BeTrue();
            }

            { // test for Replace operation
                var tagPatchRequest = new TagsPatchResource("Replace", putTags);
                var patchResponse   = client.Tags.UpdateAtScope(resourceScope, tagPatchRequest);

                var expectedResponse = new TagsResource(putTags);
                patchResponse.Properties.TagsProperty.Should().HaveCount(expectedResponse.Properties.TagsProperty.Count);
                this.CompareTagsResource(expectedResponse, patchResponse).Should().BeTrue();
            }

            { // test for Delete operation
                var tagPatchRequest = new TagsPatchResource("Delete", putTags);
                var patchResponse   = client.Tags.UpdateAtScope(resourceScope, tagPatchRequest);
                patchResponse.Properties.TagsProperty.Should().BeEmpty();
            }
        }
Beispiel #6
0
        static async Task Main(string[] args)
        {
            var resourceId = $"/subscriptions/{DefaultSubscription}/resourceGroups/XXX";

            var credentials = await ApplicationTokenProvider.LoginSilentAsync(
                TenantDomain,
                ClientId,
                ClientSecret);

            using (var client = new ResourceManagementClient(credentials))
            {
                client.SubscriptionId = DefaultSubscription;

                try
                {
                    // Create Predefined Tag name and value. Predefined Tags are not automatically
                    // applied to existing or newly created sub resources.
                    // Requires contributor permission at subscription level
                    //var t = await client.Tags.CreateOrUpdateAsync("PredefinedTag1");
                    //await client.Tags.CreateOrUpdateValueAsync("PredefinedTag1", "DefaultValue");

                    // Tags operations, only require Tags Contributor
                    // 1. Create/Update Tags on subscription,
                    var tags = new TagsResource(
                        new Tags(
                            new Dictionary <string, string>
                    {
                        { "environment", DateTimeOffset.Now.ToString() },
                        { "department", DateTimeOffset.Now.ToString() },
                        { "PredefinedTag1", "override" }
                    }));
                    var result = await client.Tags.CreateOrUpdateAtScopeAsync(resourceId, tags);

                    // 2. Update Tags on resource
                    var patchTags = new TagsPatchResource(
                        "Merge", // Replace, Delete
                        new Tags(
                            new Dictionary <string, string>
                    {
                        { "environment", DateTimeOffset.Now.ToString() },
                        { "department", DateTimeOffset.Now.ToString() },
                        { "newTag", DateTimeOffset.Now.ToString() },
                    }));

                    result = await client.Tags.UpdateAtScopeAsync(resourceId, patchTags);

                    // 3. Delete all Tags on the resource
                    await client.Tags.DeleteAtScopeAsync(resourceId);
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                }
            }
        }
 /// <summary>
 /// Convert a SDK TagsResource object to PS PSTagResource
 /// </summary>
 /// <param name="tagsResource">SDK TagsResource extension method</param>
 /// <returns>PS object PSTagResource</returns>
 public static PSTagResource ToPSTagResource(this TagsResource tagsResource)
 {
     return(new PSTagResource
     {
         Id = tagsResource?.Id,
         Name = tagsResource?.Name,
         Type = tagsResource?.Type,
         Properties = new PSTagsObject(tagsResource?.Properties?.TagsProperty),
         PropertiesTable = ResourcesExtensions.ConstructTagsTable(TagsConversionHelper.CreateTagHashtable(tagsResource?.Properties?.TagsProperty))
     });
 }
Beispiel #8
0
 public virtual Response <TagsResource> CreateOrUpdateAtScope(string scope, TagsResource parameters, CancellationToken cancellationToken = default)
 {
     using var scope0 = _clientDiagnostics.CreateScope("TagsClient.CreateOrUpdateAtScope");
     scope0.Start();
     try
     {
         return(RestClient.CreateOrUpdateAtScope(scope, parameters, cancellationToken));
     }
     catch (Exception e)
     {
         scope0.Failed(e);
         throw;
     }
 }
Beispiel #9
0
        public AgileZenClient(string apiKey, string apiUrl = "https://agilezen.com/api/v1/")
        {
            var client = new RestClient(apiUrl);

            client.AddDefaultHeader("X-Zen-ApiKey", apiKey);
            client.AddDefaultHeader("Content-Type", "application/json");
            client.AddDefaultHeader("Accept", "application/json");

            Me       = new MeResource(client);
            Phases   = new PhasesResource(client);
            Projects = new ProjectsResource(client);
            Stories  = new StoriesResource(client);
            Tags     = new TagsResource(client);
        }
Beispiel #10
0
 /// <summary>
 /// utility method to compare two TagsResource object to see if they are the same
 /// </summary>
 /// <param name="tag1">first TagsResource object</param>
 /// <param name="tag2">second TagsResource object</param>
 /// <returns> boolean to show whether two objects are the same</returns>
 private bool CompareTagsResource(TagsResource tag1, TagsResource tag2)
 {
     if ((tag1 == null && tag2 == null) || (tag1.Properties.TagsValue.Count == 0 && tag2.Properties.TagsValue.Count == 0))
     {
         return(true);
     }
     if ((tag1 == null || tag2 == null) || (tag1.Properties.TagsValue.Count == 0 || tag2.Properties.TagsValue.Count == 0))
     {
         return(false);
     }
     foreach (var pair in tag1.Properties.TagsValue)
     {
         if (!tag2.Properties.TagsValue.ContainsKey(pair.Key) || tag2.Properties.TagsValue[pair.Key] != pair.Value)
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #11
0
        /// <summary>
        /// Utility method to test Put request for Tags Operation within tracked resources and proxy resources
        /// </summary>
        private async void CreateOrUpdateTagsTest(string resourceScope = "")
        {
            var tagsResource = new TagsResource(new Tags()
            {
                TagsValue = new Dictionary <string, string> {
                    { "tagKey1", "tagValue1" },
                    { "tagKey2", "tagValue2" }
                }
            }
                                                );
            string subscriptionScope = "/subscriptions/" + TestEnvironment.SubscriptionId;

            resourceScope = subscriptionScope + resourceScope;

            // test creating tags for resources
            var putResponse = (await TagsOperations.CreateOrUpdateAtScopeAsync(resourceScope, tagsResource)).Value;

            Assert.AreEqual(putResponse.Properties.TagsValue.Count(), tagsResource.Properties.TagsValue.Count());
            Assert.IsTrue(CompareTagsResource(tagsResource, putResponse));
        }
        /// <summary>
        /// Utility method to test Put request for Tags Operation within tracked resources and proxy resources
        /// </summary>
        private void CreateOrUpdateTagsTest(string resourceScope, MockContext context)
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var tagsResource = new TagsResource(new Tags(
                                                    new Dictionary <string, string> {
                { "tagKey1", "tagValue1" },
                { "tagKey2", "tagValue2" }
            }
                                                    ));
            var client = GetResourceManagementClient(context, handler);

            // test creating tags for resources
            var putResponse = client.Tags.CreateOrUpdateAtScope(resourceScope, tagsResource);

            putResponse.Properties.TagsProperty.Should().HaveCount(tagsResource.Properties.TagsProperty.Count);
            this.CompareTagsResource(tagsResource, putResponse).Should().BeTrue();
        }
Beispiel #13
0
        public void TestIotHubCreateLifeCycle()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                this.Initialize(context);

                // Create Resource Group
                var resourceGroup = this.CreateResourceGroup(IotHubTestUtilities.DefaultResourceGroupName);

                // Check if Hub Exists and Delete
                var operationInputs = new OperationInputs()
                {
                    Name = IotHubTestUtilities.DefaultIotHubName
                };

                var iotHubNameAvailabilityInfo = this.iotHubClient.IotHubResource.CheckNameAvailability(operationInputs);

                if (!(bool)iotHubNameAvailabilityInfo.NameAvailable)
                {
                    this.iotHubClient.IotHubResource.Delete(
                        IotHubTestUtilities.DefaultResourceGroupName,
                        IotHubTestUtilities.DefaultIotHubName);

                    iotHubNameAvailabilityInfo = this.iotHubClient.IotHubResource.CheckNameAvailability(operationInputs);
                    Assert.True(iotHubNameAvailabilityInfo.NameAvailable);
                }

                //CreateEH and AuthRule
                var properties = new IotHubProperties();
                properties.Routing = this.GetIotHubRoutingProperties(resourceGroup);
                var iotHub = this.CreateIotHub(resourceGroup, IotHubTestUtilities.DefaultLocation, IotHubTestUtilities.DefaultIotHubName, properties);

                Assert.NotNull(iotHub);
                Assert.Equal(IotHubSku.S1, iotHub.Sku.Name);
                Assert.Equal(IotHubTestUtilities.DefaultIotHubName, iotHub.Name);

                // Add and Get Tags
                IDictionary <string, string> tags = new Dictionary <string, string>();
                tags.Add("key1", "value1");
                tags.Add("key2", "value2");
                var tag = new TagsResource(tags);
                iotHub = this.iotHubClient.IotHubResource.Update(IotHubTestUtilities.DefaultResourceGroupName, IotHubTestUtilities.DefaultIotHubName, tag);

                Assert.NotNull(iotHub);
                Assert.True(iotHub.Tags.Count().Equals(2));
                Assert.Equal("value2", iotHub.Tags["key2"]);

                var subscriptionQuota = this.iotHubClient.ResourceProviderCommon.GetSubscriptionQuota();

                Assert.Equal(2, subscriptionQuota.Value.Count);
                Assert.Equal(1, subscriptionQuota.Value.FirstOrDefault(x => x.Name.Value.Equals("freeIotHubCount")).Limit);
                Assert.Equal(100, subscriptionQuota.Value.FirstOrDefault(x => x.Name.Value.Equals("paidIotHubCount")).Limit);

                var endpointHealth = this.iotHubClient.IotHubResource.GetEndpointHealth(IotHubTestUtilities.DefaultResourceGroupName, IotHubTestUtilities.DefaultIotHubName);
                Assert.Equal(4, endpointHealth.Count());
                Assert.Contains(endpointHealth, q => q.EndpointId.Equals("events", StringComparison.OrdinalIgnoreCase));

                TestAllRoutesInput  testAllRoutesInput  = new TestAllRoutesInput(RoutingSource.DeviceMessages, new RoutingMessage(), new RoutingTwin());
                TestAllRoutesResult testAllRoutesResult = this.iotHubClient.IotHubResource.TestAllRoutes(testAllRoutesInput, IotHubTestUtilities.DefaultIotHubName, IotHubTestUtilities.DefaultResourceGroupName);
                Assert.Equal(4, testAllRoutesResult.Routes.Count);

                TestRouteInput  testRouteInput  = new TestRouteInput(properties.Routing.Routes[0], new RoutingMessage(), new RoutingTwin());
                TestRouteResult testRouteResult = this.iotHubClient.IotHubResource.TestRoute(testRouteInput, IotHubTestUtilities.DefaultIotHubName, IotHubTestUtilities.DefaultResourceGroupName);
                Assert.Equal("true", testRouteResult.Result);

                // Get quota metrics
                var quotaMetrics = this.iotHubClient.IotHubResource.GetQuotaMetrics(
                    IotHubTestUtilities.DefaultResourceGroupName,
                    IotHubTestUtilities.DefaultIotHubName);

                Assert.True(quotaMetrics.Count() > 0);
                Assert.Contains(quotaMetrics, q => q.Name.Equals("TotalMessages", StringComparison.OrdinalIgnoreCase) &&
                                q.CurrentValue == 0 &&
                                q.MaxValue == 400000);

                Assert.Contains(quotaMetrics, q => q.Name.Equals("TotalDeviceCount", StringComparison.OrdinalIgnoreCase) &&
                                q.CurrentValue == 0 &&
                                q.MaxValue == 500000);

                // Get all Iot Hubs in a resource group
                var iotHubs = this.iotHubClient.IotHubResource.ListByResourceGroup(IotHubTestUtilities.DefaultResourceGroupName);
                Assert.True(iotHubs.Count() > 0);

                // Get all Iot Hubs in a subscription
                var iotHubBySubscription = this.iotHubClient.IotHubResource.ListBySubscription();
                Assert.True(iotHubBySubscription.Count() > 0);

                // Get Registry Stats
                var regStats = this.iotHubClient.IotHubResource.GetStats(IotHubTestUtilities.DefaultResourceGroupName, IotHubTestUtilities.DefaultIotHubName);
                Assert.True(regStats.TotalDeviceCount.Value.Equals(0));
                Assert.True(regStats.EnabledDeviceCount.Value.Equals(0));
                Assert.True(regStats.DisabledDeviceCount.Value.Equals(0));

                // Get Valid Skus
                var skus = this.iotHubClient.IotHubResource.GetValidSkus(
                    IotHubTestUtilities.DefaultResourceGroupName,
                    IotHubTestUtilities.DefaultIotHubName);
                Assert.Equal(3, skus.Count());


                // Get All Iothub Keys
                var keys = this.iotHubClient.IotHubResource.ListKeys(
                    IotHubTestUtilities.DefaultResourceGroupName,
                    IotHubTestUtilities.DefaultIotHubName);
                Assert.True(keys.Count() > 0);
                Assert.Contains(keys, k => k.KeyName.Equals("iothubowner", StringComparison.OrdinalIgnoreCase));

                // Get specific IotHub Key
                var key = this.iotHubClient.IotHubResource.GetKeysForKeyName(
                    IotHubTestUtilities.DefaultResourceGroupName,
                    IotHubTestUtilities.DefaultIotHubName,
                    "iothubowner");
                Assert.Equal("iothubowner", key.KeyName);

                // Get All EH consumer groups
                var ehConsumerGroups = this.iotHubClient.IotHubResource.ListEventHubConsumerGroups(
                    IotHubTestUtilities.DefaultResourceGroupName,
                    IotHubTestUtilities.DefaultIotHubName,
                    IotHubTestUtilities.EventsEndpointName);
                Assert.True(ehConsumerGroups.Count() > 0);
                Assert.Contains(ehConsumerGroups, e => e.Name.Equals("$Default", StringComparison.OrdinalIgnoreCase));

                // Add EH consumer group
                var ehConsumerGroup = this.iotHubClient.IotHubResource.CreateEventHubConsumerGroup(
                    IotHubTestUtilities.DefaultResourceGroupName,
                    IotHubTestUtilities.DefaultIotHubName,
                    IotHubTestUtilities.EventsEndpointName,
                    "testConsumerGroup");

                Assert.Equal("testConsumerGroup", ehConsumerGroup.Name);


                // Get EH consumer group
                ehConsumerGroup = this.iotHubClient.IotHubResource.GetEventHubConsumerGroup(
                    IotHubTestUtilities.DefaultResourceGroupName,
                    IotHubTestUtilities.DefaultIotHubName,
                    IotHubTestUtilities.EventsEndpointName,
                    "testConsumerGroup");

                Assert.Equal("testConsumerGroup", ehConsumerGroup.Name);

                // Delete EH consumer group
                this.iotHubClient.IotHubResource.DeleteEventHubConsumerGroup(
                    IotHubTestUtilities.DefaultResourceGroupName,
                    IotHubTestUtilities.DefaultIotHubName,
                    IotHubTestUtilities.EventsEndpointName,
                    "testConsumerGroup");

                // Get all of the available IoT Hub REST API operations
                var operationList = this.iotHubClient.Operations.List();
                Assert.True(operationList.Count() > 0);
                Assert.Contains(operationList, e => e.Name.Equals("Microsoft.Devices/iotHubs/Read", StringComparison.OrdinalIgnoreCase));

                // Get IoT Hub REST API read operation
                var hubReadOperation = operationList.Where(e => e.Name.Equals("Microsoft.Devices/iotHubs/Read", StringComparison.OrdinalIgnoreCase));
                Assert.True(hubReadOperation.Count().Equals(1));
                Assert.Equal("Microsoft Devices", hubReadOperation.First().Display.Provider, ignoreCase: true);
                Assert.Equal("Get IotHub(s)", hubReadOperation.First().Display.Operation, ignoreCase: true);
            }
        }
Beispiel #14
0
 /// <summary>
 /// Update an existing provisioning service's tags.
 /// </summary>
 /// <remarks>
 /// Update an existing provisioning service's tags. to update other fields use
 /// the CreateOrUpdate method
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Resource group identifier.
 /// </param>
 /// <param name='provisioningServiceName'>
 /// Name of provisioning service to create or update.
 /// </param>
 /// <param name='provisioningServiceTags'>
 /// Updated tag information to set into the provisioning service instance.
 /// </param>
 public static ProvisioningServiceDescription BeginUpdate(this IIotDpsResourceOperations operations, string resourceGroupName, string provisioningServiceName, TagsResource provisioningServiceTags)
 {
     return(operations.BeginUpdateAsync(resourceGroupName, provisioningServiceName, provisioningServiceTags).GetAwaiter().GetResult());
 }
Beispiel #15
0
 /// <summary>
 /// Update an existing provisioning service's tags.
 /// </summary>
 /// <remarks>
 /// Update an existing provisioning service's tags. to update other fields use
 /// the CreateOrUpdate method
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Resource group identifier.
 /// </param>
 /// <param name='provisioningServiceName'>
 /// Name of provisioning service to create or update.
 /// </param>
 /// <param name='provisioningServiceTags'>
 /// Updated tag information to set into the provisioning service instance.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ProvisioningServiceDescription> BeginUpdateAsync(this IIotDpsResourceOperations operations, string resourceGroupName, string provisioningServiceName, TagsResource provisioningServiceTags, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(resourceGroupName, provisioningServiceName, provisioningServiceTags, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Beispiel #16
0
        /// <summary>
        /// Utility method to test Patch request for Tags Operation within tracked resources and proxy resources, including Replace|Merge|Delete operations
        /// </summary>
        private async void UpdateTagsTest(string resourceScope = "")
        {
            var subscriptionScope = "/subscriptions/" + TestEnvironment.SubscriptionId;

            resourceScope = subscriptionScope + resourceScope;

            // using Tags.CreateOrUpdateAtScope to create two tags initially
            var tagsResource = new TagsResource(new Tags()
            {
                TagsValue = new Dictionary <string, string> {
                    { "tagKey1", "tagValue1" },
                    { "tagKey2", "tagValue2" }
                }
            }
                                                );
            await TagsOperations.CreateOrUpdateAtScopeAsync(resourceScope, tagsResource);

            SleepInTest(3 * 1000);

            var putTags = new Tags()
            {
                TagsValue = new Dictionary <string, string> {
                    { "tagKey1", "tagValue3" },
                    { "tagKey3", "tagValue3" }
                }
            };

            { // test for Merge operation
                var tagPatchRequest = new TagsPatchResource()
                {
                    Operation = TagsPatchResourceOperation.Merge, Properties = putTags
                };
                var patchResponse = (await TagsOperations.UpdateAtScopeAsync(resourceScope, tagPatchRequest)).Value;

                var expectedResponse = new TagsResource(new Tags()
                {
                    TagsValue = new Dictionary <string, string> {
                        { "tagKey1", "tagValue3" },
                        { "tagKey2", "tagValue2" },
                        { "tagKey3", "tagValue3" }
                    }
                }
                                                        );
                Assert.AreEqual(patchResponse.Properties.TagsValue.Count(), expectedResponse.Properties.TagsValue.Count());
                Assert.IsTrue(this.CompareTagsResource(expectedResponse, patchResponse));
            }

            { // test for Replace operation
                var tagPatchRequest = new TagsPatchResource()
                {
                    Operation = TagsPatchResourceOperation.Replace, Properties = putTags
                };
                var patchResponse = (await TagsOperations.UpdateAtScopeAsync(resourceScope, tagPatchRequest)).Value;

                var expectedResponse = new TagsResource(putTags);
                Assert.AreEqual(patchResponse.Properties.TagsValue.Count(), expectedResponse.Properties.TagsValue.Count());
                Assert.IsTrue(this.CompareTagsResource(expectedResponse, patchResponse));
            }

            { // test for Delete operation
                var tagPatchRequest = new TagsPatchResource()
                {
                    Operation = TagsPatchResourceOperation.Delete, Properties = putTags
                };
                var patchResponse = (await TagsOperations.UpdateAtScopeAsync(resourceScope, tagPatchRequest)).Value;
                Assert.IsEmpty(patchResponse.Properties.TagsValue);
            }
        }
 /// <summary>
 /// Creates or updates the entire set of tags on a resource or subscription.
 /// </summary>
 /// <remarks>
 /// This operation allows adding or replacing the entire set of tags on the
 /// specified resource or subscription. The specified entity can have a maximum
 /// of 50 tags.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='scope'>
 /// The resource scope.
 /// </param>
 /// <param name='parameters'>
 /// </param>
 public static TagsResource CreateOrUpdateAtScope(this ITagsOperations operations, string scope, TagsResource parameters)
 {
     return(operations.CreateOrUpdateAtScopeAsync(scope, parameters).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Creates or updates the entire set of tags on a resource or subscription.
 /// </summary>
 /// <remarks>
 /// This operation allows adding or replacing the entire set of tags on the
 /// specified resource or subscription. The specified entity can have a maximum
 /// of 50 tags.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='scope'>
 /// The resource scope.
 /// </param>
 /// <param name='parameters'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <TagsResource> CreateOrUpdateAtScopeAsync(this ITagsOperations operations, string scope, TagsResource parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateAtScopeWithHttpMessagesAsync(scope, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        /// <summary>
        /// Creates or updates the entire set of tags on a resource or subscription.
        /// </summary>
        /// <remarks>
        /// This operation allows adding or replacing the entire set of tags on the
        /// specified resource or subscription. The specified entity can have a maximum
        /// of 50 tags.
        /// </remarks>
        /// <param name="scope">scope could be a resource or subscription</param>
        /// <param name="parameters">dictionary of tags need to be created or updated</param>
        /// <returns>PS object PSTagResource</returns>
        public PSTagResource CreateOrUpdateTagAtScope(string scope, IDictionary <string, string> parameters)
        {
            var tagResource = new TagsResource(properties: new SDKTagsObject(parameters));

            return(ResourceManagementClient.Tags.CreateOrUpdateAtScope(scope: scope, parameters: tagResource)?.ToPSTagResource());
        }
Beispiel #20
0
 public virtual async Task <Response <TagsResource> > CreateOrUpdateAtScopeAsync(string scope, TagsResource parameters, CancellationToken cancellationToken = default)
 {
     using var scope0 = _clientDiagnostics.CreateScope("TagsClient.CreateOrUpdateAtScope");
     scope0.Start();
     try
     {
         return(await RestClient.CreateOrUpdateAtScopeAsync(scope, parameters, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope0.Failed(e);
         throw;
     }
 }