/// <summary> /// Creates or Updates a Api Version Set. /// </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='versionSetId'> /// Api Version Set identifier. Must be unique in the current API Management /// service instance. /// </param> /// <param name='parameters'> /// Create or update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. Not required when creating an entity, but required when /// updating an entity. /// </param> public static ApiVersionSetContract CreateOrUpdate(this IApiVersionSetOperations operations, string resourceGroupName, string serviceName, string versionSetId, ApiVersionSetContract parameters, string ifMatch = default(string)) { return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, versionSetId, parameters, ifMatch).GetAwaiter().GetResult()); }
/// <summary> /// Creates or Updates a Api Version Set. /// </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='versionSetId'> /// Api Version Set identifier. Must be unique in the current API Management /// service instance. /// </param> /// <param name='parameters'> /// Create or update 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 <ApiVersionSetContract> CreateOrUpdateAsync(this IApiVersionSetOperations operations, string resourceGroupName, string serviceName, string versionSetId, ApiVersionSetContract parameters, string ifMatch = default(string), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serviceName, versionSetId, 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())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); // there is no api-version-set initially var versionSetlistResponse = await testBase.client.ApiVersionSet.ListByServiceAsync( testBase.rgName, testBase.serviceName); Assert.NotNull(versionSetlistResponse); Assert.Empty(versionSetlistResponse); Assert.Null(versionSetlistResponse.NextPageLink); string newversionsetid = TestUtilities.GenerateName("apiversionsetid"); const string paramName = "x-ms-sdk-version"; try { var createVersionSetContract = new ApiVersionSetContract() { DisplayName = TestUtilities.GenerateName("versionset"), Description = TestUtilities.GenerateName("versionsetdescript"), VersioningScheme = VersioningScheme.Header, VersionHeaderName = paramName }; var versionSetContract = await testBase.client.ApiVersionSet.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, newversionsetid, createVersionSetContract); Assert.NotNull(versionSetContract); Assert.Equal(createVersionSetContract.DisplayName, versionSetContract.DisplayName); Assert.Equal(createVersionSetContract.Description, versionSetContract.Description); Assert.Equal(createVersionSetContract.VersioningScheme, VersioningScheme.Header); Assert.Equal(createVersionSetContract.VersionHeaderName, versionSetContract.VersionHeaderName); Assert.Null(versionSetContract.VersionQueryName); // get the etag var versionSetTag = await testBase.client.ApiVersionSet.GetEntityTagAsync( testBase.rgName, testBase.serviceName, newversionsetid); Assert.NotNull(versionSetTag); Assert.NotNull(versionSetTag.ETag); // update the version set contract to change versioning scheme var versionSetUpdateParams = new ApiVersionSetUpdateParameters() { VersioningScheme = VersioningScheme.Query, VersionQueryName = paramName, VersionHeaderName = null }; await testBase.client.ApiVersionSet.UpdateAsync( testBase.rgName, testBase.serviceName, newversionsetid, versionSetUpdateParams, versionSetTag.ETag); // do a get on the contract versionSetContract = await testBase.client.ApiVersionSet.GetAsync( testBase.rgName, testBase.serviceName, newversionsetid); Assert.NotNull(versionSetContract); Assert.Equal(VersioningScheme.Query, versionSetContract.VersioningScheme); Assert.Equal(paramName, versionSetContract.VersionQueryName); // get the etag again versionSetTag = await testBase.client.ApiVersionSet.GetEntityTagAsync( testBase.rgName, testBase.serviceName, newversionsetid); Assert.NotNull(versionSetTag); Assert.NotNull(versionSetTag.ETag); // now delete it await testBase.client.ApiVersionSet.DeleteAsync( testBase.rgName, testBase.serviceName, newversionsetid, versionSetTag.ETag); // get the deleted apiversionset to make sure it was deleted try { testBase.client.ApiVersionSet.Get(testBase.rgName, testBase.serviceName, newversionsetid); throw new Exception("This code should not have been executed."); } catch (ErrorResponseException ex) { Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode); } } finally { await testBase.client.ApiVersionSet.DeleteAsync( testBase.rgName, testBase.serviceName, newversionsetid, "*"); } } }