Example #1
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));
        }
Example #2
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);
        }
Example #3
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));
        }
Example #4
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);
            }
        }