/// <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(string resourceScope, MockContext context) { var handler = new RecordedDelegatingHandler() { StatusCodeToReturn = HttpStatusCode.OK }; var client = GetResourceManagementClient(context, handler); // using Tags.ResourceCreate to create two tags initially var tagsResource = new TagsResource(new Tags( new Dictionary <string, string> { { "tagKey1", "tagValue1" }, { "tagKey2", "tagValue2" } } )); client.Tags.ResourceCreate(resourceScope, tagsResource); Thread.Sleep(3000); var putTags = new Tags( new Dictionary <string, string> { { "tagKey1", "tagValue3" }, { "tagKey3", "tagValue3" } }); { // test for Merge operation var tagPatchRequest = new TagPatchRequest("Merge", putTags); var patchResponse = client.Tags.ResourceUpdate(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 TagPatchRequest("Replace", putTags); var patchResponse = client.Tags.ResourceUpdate(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 TagPatchRequest("Delete", putTags); var patchResponse = client.Tags.ResourceUpdate(resourceScope, tagPatchRequest); patchResponse.Properties.TagsProperty.Should().BeEmpty(); } }
/// <summary> /// Update multiple tags: if the tagKey exists, update tagValue with the new /// value; if not, insert the new record. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='scope'> /// The resource scope. /// </param> /// <param name='parameters'> /// Parameters for updating multiple tags. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <TagsResource> ResourceUpdateAsync(this ITagsOperations operations, string scope, TagPatchRequest parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.ResourceUpdateWithHttpMessagesAsync(scope, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Update multiple tags: if the tagKey exists, update tagValue with the new /// value; if not, insert the new record. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='scope'> /// The resource scope. /// </param> /// <param name='parameters'> /// Parameters for updating multiple tags. /// </param> public static TagsResource ResourceUpdate(this ITagsOperations operations, string scope, TagPatchRequest parameters) { return(operations.ResourceUpdateAsync(scope, parameters).GetAwaiter().GetResult()); }