public void WadlTest() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType().FullName)) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); const string wadlPath = "./Resources/WADLYahoo.xml"; const string path = "yahooWadl"; string wadlApi = TestUtilities.GenerateName("aid"); try { // import API string wadlApiContent; using (StreamReader reader = File.OpenText(wadlPath)) { wadlApiContent = reader.ReadToEnd(); } var apiCreateOrUpdate = new ApiCreateOrUpdateParameter() { Path = path, ContentFormat = ContentFormat.WadlXml, ContentValue = wadlApiContent }; var wadlApiResponse = testBase.client.Api.CreateOrUpdate( testBase.rgName, testBase.serviceName, wadlApi, apiCreateOrUpdate); Assert.NotNull(wadlApiResponse); // get the api to check it was created var getResponse = testBase.client.Api.Get(testBase.rgName, testBase.serviceName, wadlApi); Assert.NotNull(getResponse); Assert.Equal(wadlApi, getResponse.Name); Assert.Equal(path, getResponse.Path); Assert.Equal("Yahoo News Search", getResponse.DisplayName); Assert.Equal("http://api.search.yahoo.com/NewsSearchService/V1/", getResponse.ServiceUrl); Assert.True(getResponse.IsCurrent); Assert.True(getResponse.Protocols.Contains(Protocol.Https)); Assert.Equal("1", getResponse.ApiRevision); ApiExportResult wadlExport = testBase.client.ApiExport.Get(testBase.rgName, testBase.serviceName, wadlApi, ExportFormat.Wadl); Assert.NotNull(wadlExport); Assert.NotNull(wadlExport.Link); } finally { // remove the API testBase.client.Api.Delete(testBase.rgName, testBase.serviceName, wadlApi, "*"); } } }
public void OpenApiTest() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); const string openapiFilePath = "./Resources/petstore.yaml"; const string path = "openapi3"; string openApiId = TestUtilities.GenerateName("aid"); try { // import API string openApiContent; using (StreamReader reader = File.OpenText(openapiFilePath)) { openApiContent = reader.ReadToEnd(); } var apiCreateOrUpdate = new ApiCreateOrUpdateParameter() { Path = path, Format = ContentFormat.Openapi, Value = openApiContent }; var swaggerApiResponse = testBase.client.Api.CreateOrUpdate( testBase.rgName, testBase.serviceName, openApiId, apiCreateOrUpdate); Assert.NotNull(swaggerApiResponse); // get the api to check it was created var getResponse = testBase.client.Api.Get(testBase.rgName, testBase.serviceName, openApiId); Assert.NotNull(getResponse); Assert.Equal(openApiId, getResponse.Name); Assert.Equal(path, getResponse.Path); Assert.Equal("Swagger Petstore", getResponse.DisplayName); Assert.Equal("http://petstore.swagger.io/v1", getResponse.ServiceUrl); ApiExportResult openApiExport = testBase.client.ApiExport.Get(testBase.rgName, testBase.serviceName, openApiId, ExportFormat.Openapi); Assert.NotNull(openApiExport); Assert.NotNull(openApiExport.Value.Link); Assert.Equal("openapi-link", openApiExport.ExportResultFormat); } finally { // remove the API testBase.client.Api.Delete(testBase.rgName, testBase.serviceName, openApiId, "*"); } } }
public void SwaggerTest() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); const string swaggerPath = "./Resources/SwaggerPetStoreV2.json"; const string path = "swaggerApi"; string swaggerApi = TestUtilities.GenerateName("aid"); try { // import API string swaggerApiContent; using (StreamReader reader = File.OpenText(swaggerPath)) { swaggerApiContent = reader.ReadToEnd(); } var apiCreateOrUpdate = new ApiCreateOrUpdateParameter() { Path = path, Format = ContentFormat.SwaggerJson, Value = swaggerApiContent }; var swaggerApiResponse = testBase.client.Api.CreateOrUpdate( testBase.rgName, testBase.serviceName, swaggerApi, apiCreateOrUpdate); Assert.NotNull(swaggerApiResponse); // get the api to check it was created var getResponse = testBase.client.Api.Get(testBase.rgName, testBase.serviceName, swaggerApi); Assert.NotNull(getResponse); Assert.Equal(swaggerApi, getResponse.Name); Assert.Equal(path, getResponse.Path); Assert.Equal("Swagger Petstore Extensive", getResponse.DisplayName); Assert.Equal("http://petstore.swagger.wordnik.com/api", getResponse.ServiceUrl); ApiExportResult swaggerExport = testBase.client.ApiExport.Get(testBase.rgName, testBase.serviceName, swaggerApi, ExportFormat.Swagger); Assert.NotNull(swaggerExport); Assert.NotNull(swaggerExport.Value.Link); Assert.Equal("swagger-link-json", swaggerExport.ExportResultFormat); } finally { // remove the API testBase.client.Api.Delete(testBase.rgName, testBase.serviceName, swaggerApi, "*"); } } }
public static void UseAzureApiMangement(this ITunnelBuilderThatHasAnOpenApiDocumentEndpoint builder, AzureApiManagementCreateApiOptions options = null) { options ??= new AzureApiManagementCreateApiOptions(); var publicSwaggerUrl = $"{builder.RootUrl}/{builder.OpenApiDocumentEndpoint}"; var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID"); var clientId = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID"); var clientSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET"); var tenantId = Environment.GetEnvironmentVariable("AZURE_TENANT_ID"); var credentials = SdkContext.AzureCredentialsFactory .FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud) .WithDefaultSubscription(subscriptionId); ApiManagementClient = new ApiManagementClient(credentials); ApiManagementClient.SubscriptionId = subscriptionId; ApiCreateOrUpdateParameter parms = new ApiCreateOrUpdateParameter { Path = $"{options.ApiId}/{CleanVersion(builder.Version)}", Format = ContentFormat.OpenapijsonLink, Value = publicSwaggerUrl, ServiceUrl = builder.RootUrl }; // wait for the host to start to try to hit it builder.Host.Services.GetService <IHostApplicationLifetime>().ApplicationStarted.Register(() => { ApiManagementClient.Api.CreateOrUpdate( options.ResourceGroupName, options.ApiManagementServiceName, $"{options.ApiId}-{CleanVersion(builder.Version)}", parms ); }); }
/// <summary> /// Creates new or updates existing specified API of the API Management service /// instance. /// </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='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 <ApiContract> CreateOrUpdateAsync(this IApiOperations operations, string resourceGroupName, string serviceName, string apiId, ApiCreateOrUpdateParameter parameters, string ifMatch = default(string), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serviceName, apiId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates new or updates existing specified API of the API Management service /// instance. /// </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='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 ApiContract CreateOrUpdate(this IApiOperations operations, string resourceGroupName, string serviceName, string apiId, ApiCreateOrUpdateParameter parameters, string ifMatch = default(string)) { return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, apiId, parameters, ifMatch).GetAwaiter().GetResult()); }
public async Task CloneApiUsingSourceApiId() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType().FullName)) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); // add new api const string swaggerPath = "./Resources/SwaggerPetStoreV2.json"; const string path = "swaggerApi"; string newApiAuthorizationServerId = TestUtilities.GenerateName("authorizationServerId"); string newApiId = TestUtilities.GenerateName("apiid"); string swaggerApiId = TestUtilities.GenerateName("swaggerApiId"); try { // import API string swaggerApiContent; using (StreamReader reader = File.OpenText(swaggerPath)) { swaggerApiContent = reader.ReadToEnd(); } var apiCreateOrUpdate = new ApiCreateOrUpdateParameter() { Path = path, Format = ContentFormat.SwaggerJson, Value = swaggerApiContent }; var swaggerApiResponse = testBase.client.Api.CreateOrUpdate( testBase.rgName, testBase.serviceName, swaggerApiId, apiCreateOrUpdate); Assert.NotNull(swaggerApiResponse); Assert.Null(swaggerApiResponse.SubscriptionRequired); Assert.Equal(path, swaggerApiResponse.Path); var swagerApiOperations = await testBase.client.ApiOperation.ListByApiAsync( testBase.rgName, testBase.serviceName, swaggerApiResponse.Name); var createAuthServerParams = new AuthorizationServerContract { DisplayName = TestUtilities.GenerateName("authName"), DefaultScope = TestUtilities.GenerateName("oauth2scope"), AuthorizationEndpoint = "https://contoso.com/auth", TokenEndpoint = "https://contoso.com/token", ClientRegistrationEndpoint = "https://contoso.com/clients/reg", GrantTypes = new List <string> { GrantType.AuthorizationCode, GrantType.Implicit }, AuthorizationMethods = new List <AuthorizationMethod?> { AuthorizationMethod.POST, AuthorizationMethod.GET }, BearerTokenSendingMethods = new List <string> { BearerTokenSendingMethod.AuthorizationHeader, BearerTokenSendingMethod.Query }, ClientId = TestUtilities.GenerateName("clientid") }; await testBase.client.AuthorizationServer.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, newApiAuthorizationServerId, createAuthServerParams); string newApiName = TestUtilities.GenerateName("apiname"); string newApiDescription = TestUtilities.GenerateName("apidescription"); string newApiPath = "newapiPath"; string newApiServiceUrl = "http://newechoapi.cloudapp.net/api"; string subscriptionKeyParametersHeader = TestUtilities.GenerateName("header"); string subscriptionKeyQueryStringParamName = TestUtilities.GenerateName("query"); string newApiAuthorizationScope = TestUtilities.GenerateName("oauth2scope"); var newApiAuthenticationSettings = new AuthenticationSettingsContract { OAuth2 = new OAuth2AuthenticationSettingsContract { AuthorizationServerId = newApiAuthorizationServerId, Scope = newApiAuthorizationScope } }; var createdApiContract = testBase.client.Api.CreateOrUpdate( testBase.rgName, testBase.serviceName, newApiId, new ApiCreateOrUpdateParameter { SourceApiId = swaggerApiResponse.Id, // create a clone of the Swagger API created above and override the following parameters DisplayName = newApiName, Description = newApiDescription, Path = newApiPath, ServiceUrl = newApiServiceUrl, Protocols = new List <Protocol?> { Protocol.Https, Protocol.Http }, SubscriptionKeyParameterNames = new SubscriptionKeyParameterNamesContract { Header = subscriptionKeyParametersHeader, Query = subscriptionKeyQueryStringParamName }, AuthenticationSettings = newApiAuthenticationSettings, SubscriptionRequired = true, }); // get new api to check it was added var apiGetResponse = testBase.client.Api.Get(testBase.rgName, testBase.serviceName, newApiId); Assert.NotNull(apiGetResponse); Assert.Equal(newApiId, apiGetResponse.Name); Assert.Equal(newApiName, apiGetResponse.DisplayName); Assert.Equal(newApiDescription, apiGetResponse.Description); Assert.Equal(newApiPath, apiGetResponse.Path); Assert.Equal(newApiServiceUrl, apiGetResponse.ServiceUrl); Assert.Equal(subscriptionKeyParametersHeader, apiGetResponse.SubscriptionKeyParameterNames.Header); Assert.Equal(subscriptionKeyQueryStringParamName, apiGetResponse.SubscriptionKeyParameterNames.Query); Assert.Equal(2, apiGetResponse.Protocols.Count); Assert.True(apiGetResponse.Protocols.Contains(Protocol.Http)); Assert.True(apiGetResponse.Protocols.Contains(Protocol.Https)); Assert.NotNull(apiGetResponse.AuthenticationSettings); Assert.NotNull(apiGetResponse.AuthenticationSettings.OAuth2); Assert.Equal(newApiAuthorizationServerId, apiGetResponse.AuthenticationSettings.OAuth2.AuthorizationServerId); Assert.True(apiGetResponse.SubscriptionRequired); var newApiOperations = await testBase.client.ApiOperation.ListByApiAsync( testBase.rgName, testBase.serviceName, newApiId); Assert.NotNull(newApiOperations); // make sure all operations got copied Assert.Equal(swagerApiOperations.Count(), newApiOperations.Count()); } finally { // delete api server testBase.client.Api.Delete( testBase.rgName, testBase.serviceName, swaggerApiId, "*"); // delete api server testBase.client.Api.Delete( testBase.rgName, testBase.serviceName, newApiId, "*"); testBase.client.AuthorizationServer.Delete( testBase.rgName, testBase.serviceName, newApiAuthorizationServerId, "*"); } } }
public void WsdlTest() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); const string wsdlPath = "./Resources/Weather.wsdl"; const string path = "weatherapi"; string wsdlApi = TestUtilities.GenerateName("aid"); try { // import API string wsdlApiContent; using (StreamReader reader = File.OpenText(wsdlPath)) { wsdlApiContent = reader.ReadToEnd(); } // Exporting WSDL is only supported for Soap PassThrough APIs (Apis of Type:soap) // Creating one. var apiCreateOrUpdate = new ApiCreateOrUpdateParameter() { Path = path, Format = ContentFormat.Wsdl, Value = wsdlApiContent, SoapApiType = SoapApiType.SoapPassThrough, // create Soap Pass through API WsdlSelector = new ApiCreateOrUpdatePropertiesWsdlSelector() { WsdlServiceName = "Weather", WsdlEndpointName = "WeatherSoap" } }; var wsdlApiResponse = testBase.client.Api.CreateOrUpdate( testBase.rgName, testBase.serviceName, wsdlApi, apiCreateOrUpdate); Assert.NotNull(wsdlApiResponse); Assert.Equal(SoapApiType.SoapPassThrough, wsdlApiResponse.ApiType); // get the api to check it was created var apiContract = testBase.client.Api.Get( testBase.rgName, testBase.serviceName, wsdlApi); Assert.NotNull(apiContract); Assert.Equal(wsdlApi, apiContract.Name); Assert.Equal(path, apiContract.Path); Assert.Equal("Weather", apiContract.DisplayName); Assert.Equal("http://wsf.cdyne.com/WeatherWS/Weather.asmx", apiContract.ServiceUrl); Assert.True(apiContract.IsCurrent); Assert.True(apiContract.Protocols.Contains(Protocol.Https)); Assert.Equal("1", apiContract.ApiRevision); /* WSDL Export spits our broken Json * ApiExportResult wsdlExport = testBase.client.ApiExport.Get( * testBase.rgName, * testBase.serviceName, * wsdlApi, * ExportFormat.Wsdl); * * Assert.NotNull(wsdlExport); * Assert.NotNull(wsdlExport.Value.Link); * Assert.Equal("wsdl-link+xml", wsdlExport.ExportResultFormat); */ } finally { // remove the API testBase.client.Api.Delete( testBase.rgName, testBase.serviceName, wsdlApi, "*"); } } }
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(); // add new api const string swaggerPath = "./Resources/SwaggerPetStoreV2.json"; const string path = "swaggerApi"; string newApiId = TestUtilities.GenerateName("apiid"); string newReleaseId = TestUtilities.GenerateName("apireleaseid"); try { // import API string swaggerApiContent; using (StreamReader reader = File.OpenText(swaggerPath)) { swaggerApiContent = reader.ReadToEnd(); } var apiCreateOrUpdate = new ApiCreateOrUpdateParameter() { Path = path, Format = ContentFormat.SwaggerJson, Value = swaggerApiContent }; var swaggerApiResponse = testBase.client.Api.CreateOrUpdate( testBase.rgName, testBase.serviceName, newApiId, apiCreateOrUpdate); Assert.NotNull(swaggerApiResponse); // get new api to check it was added var petstoreApiContract = testBase.client.Api.Get(testBase.rgName, testBase.serviceName, newApiId); Assert.NotNull(petstoreApiContract); Assert.Equal(path, petstoreApiContract.Path); Assert.Equal("Swagger Petstore Extensive", petstoreApiContract.DisplayName); Assert.Equal("http://petstore.swagger.wordnik.com/api", petstoreApiContract.ServiceUrl); // test the number of operations it has var petstoreApiOperations = testBase.client.ApiOperation.ListByApi( testBase.rgName, testBase.serviceName, newApiId); Assert.NotNull(petstoreApiOperations); Assert.NotEmpty(petstoreApiOperations); // get the API Entity Tag ApiGetEntityTagHeaders apiTag = testBase.client.Api.GetEntityTag( testBase.rgName, testBase.serviceName, newApiId); Assert.NotNull(apiTag); Assert.NotNull(apiTag.ETag); // add an api revision string revisionNumber = "2"; // create a revision of Petstore. // Please note we can change the following properties when creating a revision // DisplayName, Description, Path, Protocols, ApiVersion, ApiVersionDescription and ApiVersionSetId var revisionDescription = "Petstore second revision"; var petstoreRevisionContract = new ApiCreateOrUpdateParameter() { Path = petstoreApiContract.Path, DisplayName = petstoreApiContract.DisplayName, ServiceUrl = petstoreApiContract.ServiceUrl + revisionNumber, Protocols = petstoreApiContract.Protocols, SubscriptionKeyParameterNames = petstoreApiContract.SubscriptionKeyParameterNames, AuthenticationSettings = petstoreApiContract.AuthenticationSettings, Description = petstoreApiContract.Description, ApiRevisionDescription = revisionDescription, IsCurrent = false, SourceApiId = petstoreApiContract.Id // with this we ensure to copy all operations, tags, product association. }; var petStoreSecondRevision = await testBase.client.Api.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, newApiId.ApiRevisionIdentifier(revisionNumber), petstoreRevisionContract); Assert.NotNull(petStoreSecondRevision); Assert.Equal(petstoreApiContract.Path, petStoreSecondRevision.Path); Assert.Equal(petstoreRevisionContract.ServiceUrl, petStoreSecondRevision.ServiceUrl); Assert.Equal(revisionNumber, petStoreSecondRevision.ApiRevision); Assert.Equal(petstoreApiContract.DisplayName, petStoreSecondRevision.DisplayName); Assert.Equal(petstoreApiContract.Description, petStoreSecondRevision.Description); Assert.Equal(revisionDescription, petStoreSecondRevision.ApiRevisionDescription); // add an operation to this revision var newOperationId = TestUtilities.GenerateName("firstOpRev"); var firstOperationContract = testBase.CreateOperationContract("POST"); var firstOperation = await testBase.client.ApiOperation.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, newApiId.ApiRevisionIdentifier(revisionNumber), newOperationId, firstOperationContract); Assert.NotNull(firstOperation); Assert.Equal("POST", firstOperation.Method); // now test out list operation on the revision api var allRevisionOperations = await testBase.client.ApiOperation.ListByApiAsync( testBase.rgName, testBase.serviceName, newApiId.ApiRevisionIdentifier(revisionNumber)); Assert.NotNull(allRevisionOperations); // we copied the revision and added an extra "POST" operation to second revision Assert.Equal(allRevisionOperations.Count(), petstoreApiOperations.Count() + 1); // now test out list operation on the revision api var firstOperationOfSecondRevision = await testBase.client.ApiOperation.ListByApiAsync( testBase.rgName, testBase.serviceName, newApiId.ApiRevisionIdentifier(revisionNumber), new Microsoft.Rest.Azure.OData.ODataQuery <OperationContract> { Top = 1 }); Assert.NotNull(firstOperationOfSecondRevision); Assert.Single(firstOperationOfSecondRevision); Assert.NotEmpty(firstOperationOfSecondRevision.NextPageLink); // now test whether the next page link works var secondOperationOfSecondRevision = await testBase.client.ApiOperation.ListByApiNextAsync( firstOperationOfSecondRevision.NextPageLink); Assert.NotNull(secondOperationOfSecondRevision); Assert.Single(secondOperationOfSecondRevision); Assert.NotEmpty(secondOperationOfSecondRevision.NextPageLink); // list apiRevision IPage <ApiRevisionContract> apiRevisions = await testBase.client.ApiRevision.ListByServiceAsync( testBase.rgName, testBase.serviceName, newApiId); Assert.NotNull(apiRevisions); Assert.Equal(2, apiRevisions.GetEnumerator().ToIEnumerable <ApiRevisionContract>().Count()); Assert.NotEmpty(apiRevisions.GetEnumerator().ToIEnumerable().Single(d => d.ApiRevision.Equals(revisionNumber)).ApiRevision); Assert.Single(apiRevisions.GetEnumerator().ToIEnumerable().Where(a => a.IsCurrent.HasValue && a.IsCurrent.Value)); // there is only one revision which is current // get the etag of the revision var apiSecondRevisionTag = await testBase.client.Api.GetEntityTagAsync( testBase.rgName, testBase.serviceName, newApiId.ApiRevisionIdentifier(revisionNumber)); var apiOnlineRevisionTag = await testBase.client.Api.GetEntityTagAsync( testBase.rgName, testBase.serviceName, newApiId); Assert.NotNull(apiSecondRevisionTag); Assert.NotNull(apiOnlineRevisionTag); Assert.NotEqual(apiOnlineRevisionTag.ETag, apiSecondRevisionTag.ETag); //there should be no release intially var apiReleases = await testBase.client.ApiRelease.ListByServiceAsync( testBase.rgName, testBase.serviceName, newApiId); Assert.Empty(apiReleases); // lets create a release now and make the second revision as current var apiReleaseContract = new ApiReleaseContract() { ApiId = newApiId.ApiRevisionIdentifierFullPath(revisionNumber), Notes = TestUtilities.GenerateName("revision_description") }; var newapiBackendRelease = await testBase.client.ApiRelease.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, newApiId, newReleaseId, apiReleaseContract); Assert.NotNull(newapiBackendRelease); Assert.Equal(newReleaseId, newapiBackendRelease.Name); Assert.Equal(apiReleaseContract.Notes, newapiBackendRelease.Notes); // get the release eta var releaseTag = await testBase.client.ApiRelease.GetEntityTagAsync( testBase.rgName, testBase.serviceName, newApiId, newReleaseId); Assert.NotNull(releaseTag); // update the release details apiReleaseContract.Notes = TestUtilities.GenerateName("update_desc"); await testBase.client.ApiRelease.UpdateAsync( testBase.rgName, testBase.serviceName, newApiId, newReleaseId, apiReleaseContract, releaseTag.ETag); // get the release detaild newapiBackendRelease = await testBase.client.ApiRelease.GetAsync( testBase.rgName, testBase.serviceName, newApiId, newReleaseId); Assert.NotNull(newapiBackendRelease); Assert.Equal(newapiBackendRelease.Notes, apiReleaseContract.Notes); // list the revision apiReleases = await testBase.client.ApiRelease.ListByServiceAsync( testBase.rgName, testBase.serviceName, newApiId); Assert.NotNull(apiReleases); Assert.Single(apiReleases); // find the revision which is not online var revisions = await testBase.client.ApiRevision.ListByServiceAsync( testBase.rgName, testBase.serviceName, newApiId, new Microsoft.Rest.Azure.OData.ODataQuery <ApiRevisionContract> { Top = 1 }); Assert.NotNull(revisions); Assert.Single(revisions); // delete the api await testBase.client.Api.DeleteAsync( testBase.rgName, testBase.serviceName, newApiId, "*", deleteRevisions : true); // get the deleted api to make sure it was deleted try { testBase.client.Api.Get(testBase.rgName, testBase.serviceName, newApiId); throw new Exception("This code should not have been executed."); } catch (ErrorResponseException ex) { Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode); } } finally { // delete authorization server testBase.client.Api.Delete( testBase.rgName, testBase.serviceName, newApiId, "*", deleteRevisions: true); testBase.client.ApiRelease.Delete( testBase.rgName, testBase.serviceName, newApiId, newReleaseId, "*"); } } }
public void OpenApi2ImportsInfoTest() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); const string swaggerPath = "./Resources/SwaggerInfoTos.json"; const string path = "swaggerApi"; string swaggerApi = TestUtilities.GenerateName("aid"); try { // import API string swaggerApiContent; using (StreamReader reader = File.OpenText(swaggerPath)) { swaggerApiContent = reader.ReadToEnd(); } var apiCreateOrUpdate = new ApiCreateOrUpdateParameter() { Path = path, Format = ContentFormat.SwaggerJson, Value = swaggerApiContent }; var swaggerApiResponse = testBase.client.Api.CreateOrUpdate( testBase.rgName, testBase.serviceName, swaggerApi, apiCreateOrUpdate); Assert.NotNull(swaggerApiResponse); // get the api to check it was created var getResponse = testBase.client.Api.Get(testBase.rgName, testBase.serviceName, swaggerApi); Assert.NotNull(getResponse); Assert.Equal(swaggerApi, getResponse.Name); Assert.Equal(path, getResponse.Path); Assert.Equal("https://contoso.com/tos", getResponse.TermsOfServiceUrl); Assert.Equal("Bob", getResponse.Contact?.Name); Assert.Equal("https://contoso.com/bob", getResponse.Contact?.Url); Assert.Equal("*****@*****.**", getResponse.Contact?.Email); Assert.Equal("Contoso license", getResponse.License?.Name); Assert.Equal("https://contoso.com/license", getResponse.License?.Url); ApiExportResult swaggerExport = testBase.client.ApiExport.Get(testBase.rgName, testBase.serviceName, swaggerApi, ExportFormat.Swagger); Assert.NotNull(swaggerExport); Assert.NotNull(swaggerExport.Value.Link); Assert.Equal("swagger-link-json", swaggerExport.ExportResultFormat); } finally { // remove the API testBase.client.Api.Delete(testBase.rgName, testBase.serviceName, swaggerApi, "*"); // clean up all tags var listOfTags = testBase.client.Tag.ListByService( testBase.rgName, testBase.serviceName); foreach (var tag in listOfTags) { testBase.client.Tag.Delete( testBase.rgName, testBase.serviceName, tag.Name, "*"); } } } }