Exemplo n.º 1
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);
        }
Exemplo n.º 2
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));
        }
        public int saveTags(Tags tag)
        {
            TagsOperations tagOperations = new TagsOperations();
            var            output        = tagOperations.addTags(tag);

            return(output);
        }
Exemplo n.º 4
0
        public async Task CreateListAndDeleteSubscriptionTag()
        {
            string tagName      = Recording.GenerateAssetName("csmtg");
            var    createResult = (await TagsOperations.CreateOrUpdateAsync(tagName)).Value;

            Assert.AreEqual(tagName, createResult.TagName);

            var listResult = await TagsOperations.ListAsync().ToEnumerableAsync();

            Assert.True(listResult.Count() > 0);

            await TagsOperations.DeleteAsync(tagName);
        }
Exemplo n.º 5
0
        public async Task CreateTagValueWithoutCreatingTag()
        {
            string tagName  = Recording.GenerateAssetName("csmtg");
            string tagValue = Recording.GenerateAssetName("csmtgv");

            try
            {
                await TagsOperations.CreateOrUpdateValueAsync(tagName, tagValue);
            }
            catch (Exception ex)
            {
                Assert.NotNull(ex);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 protected override void Initialize()
 {
     Operations            = new Operations(this);
     Deployments           = new DeploymentsOperations(this);
     Providers             = new ProvidersOperations(this);
     ProviderResourceTypes = new ProviderResourceTypesOperations(this);
     Resources             = new ResourcesOperations(this);
     ResourceGroups        = new ResourceGroupsOperations(this);
     Tags = new TagsOperations(this);
     DeploymentOperations             = new DeploymentOperations(this);
     this.BaseUri                     = new System.Uri("https://management.azure.com");
     ApiVersion                       = "2021-01-01";
     AcceptLanguage                   = "en-US";
     LongRunningOperationRetryTimeout = 30;
     GenerateClientRequestId          = true;
     SerializationSettings            = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     SerializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
     DeserializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
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);
            }
        }