/// <summary> /// Create/Update tag description in scope of the Api. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='apiId'> /// API revision identifier. Must be unique in the current API Management /// service instance. Non-current revision has ;rev=n as a suffix where n is /// the revision number. /// </param> /// <param name='tagId'> /// Tag identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Create parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. Not required when creating an entity, but required when /// updating an entity. /// </param> public static TagDescriptionContract CreateOrUpdate(this ITagDescriptionOperations operations, string resourceGroupName, string serviceName, string apiId, string tagId, TagDescriptionCreateParameters parameters, string ifMatch = default(string)) { return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, apiId, tagId, parameters, ifMatch).GetAwaiter().GetResult()); }
/// <summary> /// Create/Update tag description in scope of the Api. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='apiId'> /// API revision identifier. Must be unique in the current API Management /// service instance. Non-current revision has ;rev=n as a suffix where n is /// the revision number. /// </param> /// <param name='tagId'> /// Tag identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Create parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. Not required when creating an entity, but required when /// updating an entity. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <TagDescriptionContract> CreateOrUpdateAsync(this ITagDescriptionOperations operations, string resourceGroupName, string serviceName, string apiId, string tagId, TagDescriptionCreateParameters parameters, string ifMatch = default(string), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serviceName, apiId, tagId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public async Task CreateListUpdateDelete() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType().FullName)) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); // list all the APIs var listResponse = testBase.client.Api.ListByService( testBase.rgName, testBase.serviceName, null); Assert.NotNull(listResponse); Assert.Single(listResponse); Assert.Null(listResponse.NextPageLink); var echoApi = listResponse.First(); string tagId = TestUtilities.GenerateName("apiTag"); try { string tagDisplayName = TestUtilities.GenerateName("apiTag"); var createParameters = new TagCreateUpdateParameters(); createParameters.DisplayName = tagDisplayName; // create a tag var tagContract = testBase.client.Tag.CreateOrUpdate( testBase.rgName, testBase.serviceName, tagId, createParameters); Assert.NotNull(tagContract); Assert.Equal(tagDisplayName, tagContract.DisplayName); // associate the tag with the API tagContract = await testBase.client.Tag.AssignToApiAsync( testBase.rgName, testBase.serviceName, echoApi.Name, tagId); Assert.NotNull(tagContract); // list tag description var tagDescriptionList = await testBase.client.TagDescription.ListByApiAsync( testBase.rgName, testBase.serviceName, echoApi.Name); Assert.NotNull(tagDescriptionList); Assert.Empty(tagDescriptionList); // create a tag description var tagDescriptionCreateParams = new TagDescriptionCreateParameters() { Description = TestUtilities.GenerateName("somedescription"), ExternalDocsUrl = "http://somelog.content" }; var tagDescriptionContract = await testBase.client.TagDescription.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, echoApi.Name, tagId, tagDescriptionCreateParams); Assert.NotNull(tagDescriptionContract); Assert.Equal(tagDisplayName, tagDescriptionContract.DisplayName); Assert.Equal(tagDescriptionCreateParams.Description, tagDescriptionContract.Description); // get the tagdescription etag var tagDescriptionTag = await testBase.client.TagDescription.GetEntityStateAsync( testBase.rgName, testBase.serviceName, echoApi.Name, tagId); Assert.NotNull(tagDescriptionTag); Assert.NotNull(tagDescriptionTag.ETag); // update the tag description tagDescriptionCreateParams.Description = TestUtilities.GenerateName("tag_update"); tagDescriptionContract = await testBase.client.TagDescription.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, echoApi.Name, tagId, tagDescriptionCreateParams, tagDescriptionTag.ETag); Assert.NotNull(tagDescriptionContract); Assert.Equal(tagDisplayName, tagDescriptionContract.DisplayName); Assert.Equal(tagDescriptionCreateParams.Description, tagDescriptionContract.Description); // get the entity tagDescriptionTag = await testBase.client.TagDescription.GetEntityStateAsync( testBase.rgName, testBase.serviceName, echoApi.Name, tagId); Assert.NotNull(tagDescriptionTag); Assert.NotNull(tagDescriptionTag.ETag); // delete the tag description await testBase.client.TagDescription.DeleteAsync( testBase.rgName, testBase.serviceName, echoApi.Name, tagId, tagDescriptionTag.ETag); // get the entity tag var tagTag = await testBase.client.Tag.GetEntityStateAsync( testBase.rgName, testBase.serviceName, tagId); Assert.NotNull(tagTag); Assert.NotNull(tagTag.ETag); // detach from Api await testBase.client.Tag.DetachFromApiAsync( testBase.rgName, testBase.serviceName, echoApi.Name, tagId, tagTag.ETag); // get the entity tag tagTag = await testBase.client.Tag.GetEntityStateAsync( testBase.rgName, testBase.serviceName, tagId); Assert.NotNull(tagTag); Assert.NotNull(tagTag.ETag); // delete the tag await testBase.client.Tag.DeleteAsync( testBase.rgName, testBase.serviceName, tagId, tagTag.ETag); // delete the tag description Assert.Throws <ErrorResponseException>(() => testBase.client.Tag.Get( testBase.rgName, testBase.serviceName, tagId)); } finally { // detach from api testBase.client.Tag.DetachFromApi( testBase.rgName, testBase.serviceName, echoApi.Name, tagId, "*"); // delete the tag description testBase.client.TagDescription.Delete( testBase.rgName, testBase.serviceName, echoApi.Name, tagId, "*"); // delete the tag testBase.client.Tag.Delete( testBase.rgName, testBase.serviceName, tagId, "*"); } } }