public async Task TryUpdateQuota()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                try
                {
                    // try to update quota. should not be 400(bad contract) but 404(quota not found)
                    await testBase.client.QuotaByCounterKeys.UpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        "not_exist",
                        new QuotaCounterValueUpdateContract()
                    {
                        CallsCount = 0, KbTransferred = 0
                    });
                }
                catch (ErrorResponseException ex) when(ex.Body.Code == "ResourceNotFound")
                {
                    //expected, do not raise exception
                }
            }
        }
        public void GetOutboundNetworkDependencies()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);

                // create service
                var createdService = testBase.client.ApiManagementService.CreateOrUpdate(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName,
                    parameters: testBase.serviceProperties);
                var outboundDependencies = testBase.client.OutboundNetworkDependenciesEndpoints.ListByService(testBase.rgName, testBase.serviceName);

                Assert.NotNull(outboundDependencies);
                Assert.Equal(10, outboundDependencies.Value.Count);
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("Azure SMTP")));
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("Azure Storage")));
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("Azure Active Directory")));
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("Azure SQL")));
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("Azure Key Vault")));
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("Azure Event Hub")));
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("Portal Captcha")));
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("SSL Certificate Verification")));
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("Azure Monitor")));
                Assert.NotNull(outboundDependencies.Value.Single(d => d.Category.Equals("Windows Activation")));

                // Delete
                testBase.client.ApiManagementService.Delete(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName);
            }
        }
        protected async Task <HttpStatusCode> CallApiServiceEchoApi(ApiManagementTestBase testBase)
        {
            var subscriptionList = await testBase.client.Subscription.ListAsync(testBase.rgName, testBase.serviceName);

            var subscription    = subscriptionList.First();
            var subscriptionId  = subscription.Id.Split("/").Last();
            var subscriptionKey = await testBase.client.Subscription.ListSecretsAsync(testBase.rgName, testBase.serviceName, subscriptionId);

            var echoApi = await testBase.client.Api.GetAsync(testBase.rgName, testBase.serviceName, echoApiId);

            var apiService = await testBase.client.ApiManagementService.GetAsync(testBase.rgName, testBase.serviceName);

            var url = string.Format(CultureInfo.InvariantCulture, $"/{echoApi.Path}/resource");

            using (var handler = new HttpClientHandler())
            {
                using (var httpClient = new HttpClient(handler)
                {
                    BaseAddress = new Uri(apiService.GatewayUrl)
                })
                {
                    var message = new HttpRequestMessage(HttpMethod.Head, url);
                    message.Headers.Add("Ocp-Apim-Subscription-Key", subscriptionKey.PrimaryKey);
                    var response = await httpClient.SendAsync(message);

                    return(response.StatusCode);
                }
            }
        }
Example #4
0
 static void ValidateProperty(
     NamedValueContract contract,
     ApiManagementTestBase testBase,
     string propertyId,
     string propertyDisplayName,
     string propertyValue,
     bool isSecret,
     List <string> tags = null)
 {
     Assert.NotNull(contract);
     Assert.Equal(propertyDisplayName, contract.DisplayName);
     if (isSecret)
     {
         Assert.Null(contract.Value);
     }
     else
     {
         Assert.Equal(propertyValue, contract.Value);
     }
     Assert.Equal(isSecret, contract.Secret);
     Assert.Equal(propertyId, contract.Name);
     if (tags != null)
     {
         Assert.NotNull(contract.Tags);
         Assert.Equal(tags.Count, contract.Tags.Count);
     }
 }
        async Task <PublicIPAddress> SetupPublicIPAsync(ApiManagementTestBase testBase)
        {
            // put Public IP
            string publicIpName    = TestUtilities.GenerateName();
            string domainNameLabel = TestUtilities.GenerateName(testBase.rgName);

            var publicIp = new PublicIPAddress()
            {
                Location = testBase.location,
                Tags     = new Dictionary <string, string>()
                {
                    { "key", "value" }
                },
                PublicIPAllocationMethod = IPAllocationMethod.Static,
                PublicIPAddressVersion   = "IPv4",
                DnsSettings = new PublicIPAddressDnsSettings()
                {
                    DomainNameLabel = domainNameLabel
                },
                Sku = new PublicIPAddressSku()
                {
                    Name = "Standard"
                }
            };
            var putPublicIPResponse = await testBase.networkClient.PublicIPAddresses.CreateOrUpdateAsync(testBase.rgName, publicIpName, publicIp);

            Assert.Equal("Succeeded", putPublicIPResponse.ProvisioningState);

            return(putPublicIPResponse);
        }
Example #6
0
        public void DeletedServicesTest()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase        = new ApiManagementTestBase(context);
                var deletedServices = testBase.client.DeletedServices.ListBySubscription();
                Assert.NotNull(deletedServices);

                var firstService   = deletedServices.First();
                var serviceDetails = testBase.client.DeletedServices.GetByName(firstService.Name, firstService.Location);
                Assert.NotNull(serviceDetails);
                Assert.NotNull(serviceDetails.Location);
                Assert.NotNull(serviceDetails.ScheduledPurgeDate);
                Assert.NotNull(serviceDetails.ServiceId);
                Assert.Contains(firstService.Name, serviceDetails.ServiceId);
                Assert.NotNull(serviceDetails.DeletionDate);
                Assert.True(serviceDetails.DeletionDate < serviceDetails.ScheduledPurgeDate);

                // Purge the service
                testBase.client.DeletedServices.Purge(firstService.Name, firstService.Location);

                Assert.Throws <ErrorResponseException>(() =>
                {
                    testBase.client.DeletedServices.GetByName(
                        firstService.Name,
                        firstService.Location);
                });
            }
        }
        public async Task SubscriptionsList()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // get product
                var listProductsResponse = testBase.client.Product.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    new Microsoft.Rest.Azure.OData.ODataQuery <ProductContract>
                {
                    Filter = "name eq 'Starter'"
                });

                var product = listProductsResponse.Single();

                // list product's subscriptions
                var listSubscriptionsResponse = await testBase.client.ProductSubscriptions.ListAsync(
                    testBase.rgName,
                    testBase.serviceName,
                    product.Name,
                    null);

                Assert.NotNull(listSubscriptionsResponse);
                Assert.Single(listSubscriptionsResponse);
            }
        }
Example #8
0
        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 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 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 async Task CreateListUpdatePortalRevision()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();
                var revisionId             = TestUtilities.GenerateName("revisionId");
                var portalRevisionContract = new PortalRevisionContract
                {
                    Description = new string('a', 99),
                    IsCurrent   = true
                };

                // create portal revision
                var portalRevision = await testBase.client.PortalRevision.CreateOrUpdateAsync(
                    testBase.rgName,
                    testBase.serviceName,
                    revisionId,
                    portalRevisionContract);

                Assert.NotNull(portalRevision);
                Assert.True(portalRevision.IsCurrent);
                Assert.Equal("completed", portalRevision.Status);

                //get
                var getPortalRevision = testBase.client.PortalRevision.Get(
                    testBase.rgName,
                    testBase.serviceName,
                    revisionId);

                Assert.NotNull(getPortalRevision);
                Assert.True(portalRevision.IsCurrent);
                Assert.Equal("completed", portalRevision.Status);

                var updateDescription = "Updated " + portalRevisionContract.Description;

                var updatedResult = await testBase.client.PortalRevision.UpdateAsync(
                    testBase.rgName,
                    testBase.serviceName,
                    revisionId,
                    new PortalRevisionContract { Description = updateDescription },
                    "*");

                Assert.NotNull(updatedResult);
                Assert.True(portalRevision.IsCurrent);
                Assert.Equal("completed", updatedResult.Status);
                Assert.Equal(updateDescription, updatedResult.Description);

                //list
                var listPortalRevision = testBase.client.PortalRevision.ListByService(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(listPortalRevision);
            }
        }
Example #12
0
        public void InstallIntermediateCertificatesTest()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.serviceProperties.Sku.Name = SkuType.Basic;

                testBase.serviceProperties.Certificates = new List <CertificateConfiguration>();
                var certConfig = new CertificateConfiguration()
                {
                    StoreName           = StoreName.CertificateAuthority.ToString("G"),
                    EncodedCertificate  = testBase.base64EncodedTestCertificateData,
                    CertificatePassword = testBase.testCertificatePassword
                };
                testBase.serviceProperties.Certificates.Add(certConfig);

                var base64ArrayCertificate = Convert.FromBase64String(testBase.base64EncodedTestCertificateData);
                var cert = new X509Certificate2(base64ArrayCertificate, testBase.testCertificatePassword);

                var createdService = testBase.client.ApiManagementService.CreateOrUpdate(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName,
                    parameters: testBase.serviceProperties);

                ValidateService(createdService,
                                testBase.serviceName,
                                testBase.rgName,
                                testBase.subscriptionId,
                                testBase.location,
                                testBase.serviceProperties.PublisherEmail,
                                testBase.serviceProperties.PublisherName,
                                testBase.serviceProperties.Sku.Name,
                                testBase.tags,
                                PlatformVersion.Stv2);

                Assert.NotNull(createdService.Certificates);
                Assert.Single(createdService.Certificates);
                Assert.Equal(StoreName.CertificateAuthority.ToString("G"), createdService.Certificates.First().StoreName, ignoreCase: true);
                Assert.Equal(cert.Thumbprint, createdService.Certificates.First().Certificate.Thumbprint, ignoreCase: true);

                // Delete
                testBase.client.ApiManagementService.Delete(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName);

                Assert.Throws <ErrorResponseException>(() =>
                {
                    testBase.client.ApiManagementService.Get(
                        resourceGroupName: testBase.rgName,
                        serviceName: testBase.serviceName);
                });
            }
        }
        public void CreateMultiRegionService()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);

                var additionalLocation = new AdditionalLocation()
                {
                    Location = testBase.GetLocation("Europe"),
                    Sku      = new ApiManagementServiceSkuProperties(SkuType.Premium)
                };

                // only premium sku supports multi-region
                testBase.serviceProperties.Sku.Name            = SkuType.Premium;
                testBase.serviceProperties.AdditionalLocations = new List <AdditionalLocation>()
                {
                    additionalLocation
                };

                var createdService = testBase.client.ApiManagementService.CreateOrUpdate(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName,
                    parameters: testBase.serviceProperties);

                ValidateService(createdService,
                                testBase.serviceName,
                                testBase.rgName,
                                testBase.subscriptionId,
                                testBase.location,
                                testBase.serviceProperties.PublisherEmail,
                                testBase.serviceProperties.PublisherName,
                                testBase.serviceProperties.Sku.Name,
                                testBase.tags);

                Assert.NotNull(createdService.AdditionalLocations);
                Assert.Single(createdService.AdditionalLocations);
                Assert.Equal(additionalLocation.Location.ToLowerInvariant().Replace(" ", string.Empty),
                             createdService.AdditionalLocations.First().Location.ToLowerInvariant().Replace(" ", string.Empty));

                // Delete
                testBase.client.ApiManagementService.Delete(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName);

                Assert.Throws <CloudException>(() =>
                {
                    testBase.client.ApiManagementService.Get(
                        resourceGroupName: testBase.rgName,
                        serviceName: testBase.serviceName);
                });
            }
        }
        public async Task CreateUpdateReset()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // get the existing settings on the service
                PortalSignupSettings defaultSignupSettings = await testBase.client.SignUpSettings.GetAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(defaultSignupSettings);

                // check settings Etag
                var signUpTag = await testBase.client.SignUpSettings.GetEntityTagAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(signUpTag);
                Assert.NotNull(signUpTag.ETag);

                // disable portal signIn
                var portalSignUpSettingParams = new PortalSignupSettings()
                {
                    Enabled        = false,
                    TermsOfService = defaultSignupSettings.TermsOfService
                };
                var portalSignUpSettings = testBase.client.SignUpSettings.CreateOrUpdate(
                    testBase.rgName,
                    testBase.serviceName,
                    portalSignUpSettingParams);
                Assert.NotNull(portalSignUpSettings);
                Assert.False(portalSignUpSettings.Enabled);

                signUpTag = await testBase.client.SignUpSettings.GetEntityTagAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(signUpTag);
                Assert.NotNull(signUpTag.ETag);

                // reset the signIn settings
                portalSignUpSettings.Enabled        = defaultSignupSettings.Enabled;
                portalSignUpSettings.TermsOfService = defaultSignupSettings.TermsOfService;
                await testBase.client.SignUpSettings.UpdateAsync(
                    testBase.rgName,
                    testBase.serviceName,
                    portalSignUpSettings,
                    signUpTag.ETag);
            }
        }
Example #15
0
        public void SubscriptionsList()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                var usersResponse = testBase.client.User.ListByService(testBase.rgName, testBase.serviceName, null);
                var user          = usersResponse.First();

                // list subscriptions of a user: there should be two by default
                var listResponse = testBase.client.UserSubscription.List(
                    testBase.rgName,
                    testBase.serviceName,
                    user.Name,
                    null);

                Assert.NotNull(listResponse);
                Assert.True(listResponse.Count() >= 2);
                Assert.Null(listResponse.NextPageLink);

                var userSubscription = testBase.client.UserSubscription.Get(
                    testBase.rgName,
                    testBase.serviceName,
                    user.Name,
                    listResponse.First().Name);

                Assert.NotNull(userSubscription);
                Assert.NotNull(userSubscription.Name);

                // list paged
                listResponse = testBase.client.UserSubscription.List(
                    testBase.rgName,
                    testBase.serviceName,
                    user.Name,
                    new Microsoft.Rest.Azure.OData.ODataQuery <SubscriptionContract> {
                    Top = 1
                });

                Assert.NotNull(listResponse);
                Assert.Single(listResponse);
                Assert.NotNull(listResponse.NextPageLink);

                // list next page
                listResponse = testBase.client.UserSubscription.ListNext(listResponse.NextPageLink);

                Assert.NotNull(listResponse);
                Assert.Single(listResponse);
                Assert.Null(listResponse.NextPageLink);
            }
        }
        public async Task GetUpdateKeys()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // get settings
                var getResponse = testBase.client.TenantAccessGit.Get(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(getResponse);
                Assert.NotNull(getResponse);
                Assert.True(getResponse.Enabled); // git access is always enabled
                Assert.Null(getResponse.PrimaryKey);
                Assert.Null(getResponse.SecondaryKey);

                var secretsResponse = testBase.client.TenantAccessGit.ListSecrets(
                    testBase.rgName,
                    testBase.serviceName);
                Assert.NotNull(secretsResponse.PrimaryKey);
                Assert.NotNull(secretsResponse.SecondaryKey);

                testBase.client.TenantAccessGit.RegeneratePrimaryKey(
                    testBase.rgName,
                    testBase.serviceName);

                var secretsResponse2 = testBase.client.TenantAccessGit.ListSecrets(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(secretsResponse2);
                Assert.Equal(secretsResponse.SecondaryKey, secretsResponse2.SecondaryKey);
                Assert.NotEqual(secretsResponse.PrimaryKey, secretsResponse2.PrimaryKey);

                testBase.client.TenantAccessGit.RegenerateSecondaryKey(
                    testBase.rgName,
                    testBase.serviceName);

                var getSecretsHttpResponse = await testBase.client.TenantAccessGit.ListSecretsWithHttpMessagesAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(getSecretsHttpResponse);
                Assert.NotNull(getSecretsHttpResponse.Body);
                Assert.NotNull(getSecretsHttpResponse.Headers.ETag);
                Assert.NotEqual(secretsResponse.SecondaryKey, getSecretsHttpResponse.Body.SecondaryKey);
            }
        }
Example #17
0
        public async Task CreateUpdateReset()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();
                // get the existing settings on the service
                var portalSignInSettings = await testBase.client.SignInSettings.GetAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(portalSignInSettings);

                // disable portal signIn
                portalSignInSettings.Enabled = false;
                portalSignInSettings         = testBase.client.SignInSettings.CreateOrUpdate(
                    testBase.rgName,
                    testBase.serviceName,
                    portalSignInSettings);

                Assert.NotNull(portalSignInSettings);
                Assert.False(portalSignInSettings.Enabled);

                // check settings
                var signInTag = await testBase.client.SignInSettings.GetEntityTagAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(signInTag);
                Assert.NotNull(signInTag.ETag);

                // reset the signIn settings
                portalSignInSettings.Enabled = true;
                await testBase.client.SignInSettings.UpdateAsync(
                    testBase.rgName,
                    testBase.serviceName,
                    portalSignInSettings,
                    signInTag.ETag);

                // get the delegation settings
                portalSignInSettings = await testBase.client.SignInSettings.GetAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(portalSignInSettings);
                Assert.True(portalSignInSettings.Enabled);
            }
        }
        public void ListPortalSetting()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // get the existing settings on the service
                var portalSettings = testBase.client.PortalSettings.ListByService(
                    testBase.rgName,
                    testBase.serviceName);
                Assert.NotNull(portalSettings);
            }
        }
Example #19
0
        public void SetupSystemAssignedMsiTests()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var    testBase             = new ApiManagementTestBase(context);
                string consumptionSkuRegion = "West US";

                // setup MSI on Consumption SKU
                testBase.serviceProperties.Location = consumptionSkuRegion;
                testBase.serviceProperties.Sku      = new ApiManagementServiceSkuProperties(SkuType.Consumption, capacity: 0);
                testBase.serviceProperties.Identity = new ApiManagementServiceIdentity("SystemAssigned");
                var createdService = testBase.client.ApiManagementService.CreateOrUpdate(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName,
                    parameters: testBase.serviceProperties);

                ValidateService(createdService,
                                testBase.serviceName,
                                testBase.rgName,
                                testBase.subscriptionId,
                                consumptionSkuRegion,
                                testBase.serviceProperties.PublisherEmail,
                                testBase.serviceProperties.PublisherName,
                                testBase.serviceProperties.Sku.Name,
                                testBase.tags,
                                PlatformVersion.Mtv1);

                Assert.NotNull(createdService.Identity);
                Assert.Equal("SystemAssigned", createdService.Identity.Type);
                Assert.NotNull(createdService.Identity.PrincipalId);
                Assert.NotNull(createdService.Identity.TenantId);

                // Delete
                testBase.client.ApiManagementService.Delete(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName);

                Assert.Throws <ErrorResponseException>(() =>
                {
                    testBase.client.ApiManagementService.Get(
                        resourceGroupName: testBase.rgName,
                        serviceName: testBase.serviceName);
                });
            }
        }
        public async Task List()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                var regions = await testBase.client.Region.ListByServiceAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(regions);
                Assert.Single(regions);
                Assert.Equal(testBase.location.ToLowerInvariant().Replace(" ", ""), regions.First().Name.ToLowerInvariant().Replace(" ", ""));
                Assert.True(regions.First().IsMasterRegion);
            }
        }
Example #21
0
        public void SetupMsiTests()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var testBase = new ApiManagementTestBase(context);

                testBase.serviceProperties.Identity = new ApiManagementServiceIdentity();
                var createdService = testBase.client.ApiManagementService.CreateOrUpdate(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName,
                    parameters: testBase.serviceProperties);

                ValidateService(createdService,
                                testBase.serviceName,
                                testBase.rgName,
                                testBase.subscriptionId,
                                testBase.location,
                                testBase.serviceProperties.PublisherEmail,
                                testBase.serviceProperties.PublisherName,
                                testBase.serviceProperties.Sku.Name,
                                testBase.tags);

                Assert.NotNull(createdService.Identity);
                Assert.NotNull(createdService.Identity.PrincipalId);
                Assert.NotNull(createdService.Identity.TenantId);

                // Delete
                testBase.client.ApiManagementService.Delete(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName);

                Assert.Throws <CloudException>(() =>
                {
                    testBase.client.ApiManagementService.Get(
                        resourceGroupName: testBase.rgName,
                        serviceName: testBase.serviceName);
                });
            }
        }
        public async Task ListAndGetSetting()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // list tenant access
                var listSettings = testBase.client.TenantSettings.ListByService(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.NotNull(listSettings);

                // there is only one setting `public`
                var getSetting = await testBase.client.TenantSettings.GetAsync(testBase.rgName, testBase.serviceName);

                Assert.NotNull(getSetting.Settings);
                Assert.True(getSetting.Settings.Count > 1);
            }
        }
Example #23
0
        public void UserIdentities()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // there should be 'Echo API' which is created by default for every new instance of API Management and
                // 'Starter' product

                var listUsersResponse = testBase.client.User.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    new Microsoft.Rest.Azure.OData.ODataQuery <UserContract> {
                    Filter = "firstName eq 'Administrator'"
                });

                Assert.NotNull(listUsersResponse);
                Assert.Single(listUsersResponse);

                var user = listUsersResponse.Single();

                // list user identities
                var listResponse = testBase.client.UserIdentities.List(
                    testBase.rgName,
                    testBase.serviceName,
                    user.Name);

                Assert.NotNull(listResponse);

                // there should be Azure identification
                Assert.Single(listResponse);
                Assert.Equal(user.Email, listResponse.Single().Id);
                Assert.Equal("Azure", listResponse.Single().Provider);
            }
        }
Example #24
0
        public async Task UpdateHostNameTests()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var testBase = new ApiManagementTestBase(context);

                var createdService = testBase.client.ApiManagementService.CreateOrUpdate(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName,
                    parameters: testBase.serviceProperties);

                ValidateService(createdService,
                                testBase.serviceName,
                                testBase.rgName,
                                testBase.subscriptionId,
                                testBase.location,
                                testBase.serviceProperties.PublisherEmail,
                                testBase.serviceProperties.PublisherName,
                                testBase.serviceProperties.Sku.Name,
                                testBase.tags);

                var base64ArrayCertificate = Convert.FromBase64String(testBase.base64EncodedTestCertificateData);
                var cert = new X509Certificate2(base64ArrayCertificate, testBase.testCertificatePassword);

                var uploadCertificateParams = new ApiManagementServiceUploadCertificateParameters()
                {
                    Type                = HostnameType.Proxy,
                    Certificate         = testBase.base64EncodedTestCertificateData,
                    CertificatePassword = testBase.testCertificatePassword
                };
                var certificateInformation = await testBase.client.ApiManagementService.UploadCertificateAsync(testBase.rgName, testBase.serviceName, uploadCertificateParams);

                Assert.NotNull(certificateInformation);
                Assert.Equal(cert.Thumbprint, certificateInformation.Thumbprint);
                Assert.Equal(cert.Subject, certificateInformation.Subject);

                var updateHostnameParams = new ApiManagementServiceUpdateHostnameParameters()
                {
                    Update = new List <HostnameConfigurationOld>()
                    {
                        new HostnameConfigurationOld(HostnameType.Proxy, "proxy.msitesting.net", certificateInformation)
                    }
                };

                var serviceResource = await testBase.client.ApiManagementService.UpdateHostnameAsync(
                    testBase.rgName,
                    testBase.serviceName,
                    updateHostnameParams);

                Assert.NotNull(serviceResource);
                Assert.Single(serviceResource.HostnameConfigurations);
                Assert.Equal(HostnameType.Proxy, serviceResource.HostnameConfigurations.First().Type);
                Assert.Equal("proxy.msitesting.net", serviceResource.HostnameConfigurations.First().HostName);

                // Delete
                testBase.client.ApiManagementService.Delete(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName);

                Assert.Throws <CloudException>(() =>
                {
                    testBase.client.ApiManagementService.Get(
                        resourceGroupName: testBase.rgName,
                        serviceName: testBase.serviceName);
                });
            }
        }
Example #25
0
        public async Task GetRegenerateKeys()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // list gateways: there should be none
                var gatewayListResponse = testBase.client.Gateway.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    null);

                Assert.NotNull(gatewayListResponse);
                Assert.Empty(gatewayListResponse);

                string gatewayId = TestUtilities.GenerateName("gatewayid");;

                try
                {
                    var gatewayContract = new GatewayContract()
                    {
                        LocationData = new ResourceLocationDataContract()
                        {
                            City            = "Seattle",
                            CountryOrRegion = "USA",
                            District        = "King County",
                            Name            = "Microsoft"
                        },
                        Description = TestUtilities.GenerateName()
                    };

                    var createResponse = await testBase.client.Gateway.CreateOrUpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        gatewayContract);

                    Assert.NotNull(createResponse);
                    Assert.Equal(gatewayId, createResponse.Name);
                    Assert.Equal(gatewayContract.Description, createResponse.Description);
                    Assert.NotNull(createResponse.LocationData);
                    Assert.Equal(gatewayContract.LocationData.City, createResponse.LocationData.City);
                    Assert.Equal(gatewayContract.LocationData.CountryOrRegion, createResponse.LocationData.CountryOrRegion);
                    Assert.Equal(gatewayContract.LocationData.District, createResponse.LocationData.District);
                    Assert.Equal(gatewayContract.LocationData.Name, createResponse.LocationData.Name);

                    // get keys
                    var getResponse = await testBase.client.Gateway.ListKeysAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId);

                    Assert.NotNull(getResponse);
                    Assert.NotNull(getResponse.Primary);
                    Assert.NotNull(getResponse.Secondary);

                    var primaryKey   = getResponse.Primary;
                    var secondaryKey = getResponse.Secondary;
                    Assert.NotEqual(primaryKey, secondaryKey);

                    var expiry = DateTime.UtcNow;

                    // generate token
                    var tokenResponse = await testBase.client.Gateway.GenerateTokenAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        new GatewayTokenRequestContract()
                    {
                        Expiry = expiry, KeyType = KeyType.Primary
                    });

                    Assert.NotNull(tokenResponse);
                    Assert.NotNull(tokenResponse.Value);
                    var primaryToken = tokenResponse.Value;

                    //check the same token stays
                    tokenResponse = await testBase.client.Gateway.GenerateTokenAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        new GatewayTokenRequestContract()
                    {
                        Expiry = expiry, KeyType = KeyType.Primary
                    });

                    Assert.NotNull(tokenResponse);
                    Assert.NotNull(tokenResponse.Value);
                    Assert.Equal(primaryToken, tokenResponse.Value);

                    // generate secondary token
                    tokenResponse = await testBase.client.Gateway.GenerateTokenAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        new GatewayTokenRequestContract()
                    {
                        Expiry = expiry, KeyType = KeyType.Secondary
                    });

                    Assert.NotNull(tokenResponse);
                    Assert.NotNull(tokenResponse.Value);
                    var secondaryToken = tokenResponse.Value;

                    Assert.NotEqual(primaryToken, secondaryToken);

                    //change keys
                    await testBase.client.Gateway.RegenerateKeyAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        new GatewayKeyRegenerationRequestContract()
                    {
                        KeyType = KeyType.Primary
                    });

                    await testBase.client.Gateway.RegenerateKeyAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        new GatewayKeyRegenerationRequestContract()
                    {
                        KeyType = KeyType.Secondary
                    });

                    // get keys
                    getResponse = await testBase.client.Gateway.ListKeysAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId);

                    Assert.NotNull(getResponse);
                    Assert.NotNull(getResponse.Primary);
                    Assert.NotNull(getResponse.Secondary);

                    Assert.NotEqual(primaryKey, getResponse.Primary);
                    Assert.NotEqual(secondaryKey, getResponse.Secondary);

                    // generate token
                    tokenResponse = await testBase.client.Gateway.GenerateTokenAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        new GatewayTokenRequestContract()
                    {
                        Expiry = expiry, KeyType = KeyType.Primary
                    });

                    Assert.NotNull(tokenResponse);
                    Assert.NotNull(tokenResponse.Value);
                    Assert.NotEqual(primaryToken, tokenResponse.Value);

                    // generate secondary token
                    tokenResponse = await testBase.client.Gateway.GenerateTokenAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        new GatewayTokenRequestContract()
                    {
                        Expiry = expiry, KeyType = KeyType.Secondary
                    });

                    Assert.NotNull(tokenResponse);
                    Assert.NotNull(tokenResponse.Value);
                    Assert.NotEqual(secondaryToken, tokenResponse.Value);
                }
                finally
                {
                    testBase.client.Gateway.Delete(testBase.rgName, testBase.serviceName, gatewayId, "*");
                }
            }
        }
Example #26
0
        public async Task CreateListUpdateDelete()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // list gateways: there should be none
                var gatewayListResponse = testBase.client.Gateway.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    null);

                Assert.NotNull(gatewayListResponse);
                Assert.Empty(gatewayListResponse);

                // list all the APIs
                var apisResponse = testBase.client.Api.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    null);

                Assert.NotNull(apisResponse);
                Assert.Single(apisResponse);
                Assert.Null(apisResponse.NextPageLink);
                var echoApi = apisResponse.First();

                string gatewayId        = TestUtilities.GenerateName("gatewayid");;
                string certificateId    = TestUtilities.GenerateName("certificateId");
                string hostnameConfigId = TestUtilities.GenerateName("hostnameConfigId");

                try
                {
                    var gatewayContract = new GatewayContract()
                    {
                        LocationData = new ResourceLocationDataContract()
                        {
                            City            = "Seattle",
                            CountryOrRegion = "USA",
                            District        = "King County",
                            Name            = "Microsoft"
                        },
                        Description = TestUtilities.GenerateName()
                    };

                    var createResponse = await testBase.client.Gateway.CreateOrUpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        gatewayContract);

                    Assert.NotNull(createResponse);
                    Assert.Equal(gatewayId, createResponse.Name);
                    Assert.Equal(gatewayContract.Description, createResponse.Description);
                    Assert.NotNull(createResponse.LocationData);
                    Assert.Equal(gatewayContract.LocationData.City, createResponse.LocationData.City);
                    Assert.Equal(gatewayContract.LocationData.CountryOrRegion, createResponse.LocationData.CountryOrRegion);
                    Assert.Equal(gatewayContract.LocationData.District, createResponse.LocationData.District);
                    Assert.Equal(gatewayContract.LocationData.Name, createResponse.LocationData.Name);

                    // get the gateway to check is was created
                    var getResponse = await testBase.client.Gateway.GetWithHttpMessagesAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId);

                    Assert.NotNull(getResponse);
                    Assert.Equal(gatewayId, getResponse.Body.Name);

                    // list gateways
                    gatewayListResponse = testBase.client.Gateway.ListByService(
                        testBase.rgName,
                        testBase.serviceName,
                        null);

                    Assert.NotNull(gatewayListResponse);
                    Assert.Single(gatewayListResponse);


                    var associationContract = new AssociationContract()
                    {
                        ProvisioningState = ProvisioningState.Created
                    };

                    // assign gateway to api
                    var assignResponse = await testBase.client.GatewayApi.CreateOrUpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        echoApi.Name,
                        associationContract);

                    Assert.NotNull(assignResponse);
                    Assert.Equal(echoApi.Name, assignResponse.Name);

                    // list gateway apis
                    var apiGatewaysResponse = await testBase.client.GatewayApi.ListByServiceAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId);

                    Assert.NotNull(apiGatewaysResponse);
                    Assert.Single(apiGatewaysResponse);
                    Assert.Equal(echoApi.Name, apiGatewaysResponse.First().Name);

                    //certificate first:
                    var base64ArrayCertificate = Convert.FromBase64String(testBase.base64EncodedTestCertificateData);
                    var cert = new X509Certificate2(base64ArrayCertificate, testBase.testCertificatePassword);

                    var certCreateResponse = testBase.client.Certificate.CreateOrUpdate(
                        testBase.rgName,
                        testBase.serviceName,
                        certificateId,
                        new CertificateCreateOrUpdateParameters
                    {
                        Data     = testBase.base64EncodedTestCertificateData,
                        Password = testBase.testCertificatePassword
                    },
                        null);

                    //GatewayCertificateAuthority:
                    var gatewayCertificateAuthority = new GatewayCertificateAuthorityContract()
                    {
                        IsTrusted = true
                    };

                    var gatewayCertificateAuthorityCreateResponse = await testBase.client.GatewayCertificateAuthority.CreateOrUpdateWithHttpMessagesAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        certificateId,
                        gatewayCertificateAuthority
                        );

                    Assert.NotNull(gatewayCertificateAuthorityCreateResponse);
                    Assert.Equal(certificateId, gatewayCertificateAuthorityCreateResponse.Body.Name);
                    Assert.True(gatewayCertificateAuthorityCreateResponse.Body.IsTrusted);

                    var gatewayCertificateAuthorityResponse = await testBase.client.GatewayCertificateAuthority.GetAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        certificateId
                        );

                    Assert.NotNull(gatewayCertificateAuthorityResponse);
                    Assert.Equal(certificateId, gatewayCertificateAuthorityResponse.Name);
                    Assert.True(gatewayCertificateAuthorityResponse.IsTrusted);

                    //delete
                    testBase.client.GatewayCertificateAuthority.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        certificateId,
                        "*");

                    //hostnameConfiguration:
                    var hostnameConfig = new GatewayHostnameConfigurationContract()
                    {
                        CertificateId = certCreateResponse.Id,
                        Hostname      = "www.contoso.com",
                        NegotiateClientCertificate = false
                    };

                    var hostnameConfigCreateResponse = await testBase.client.GatewayHostnameConfiguration.CreateOrUpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        hostnameConfigId,
                        hostnameConfig
                        );

                    Assert.NotNull(hostnameConfigCreateResponse);
                    Assert.Equal(hostnameConfigId, hostnameConfigCreateResponse.Name);
                    Assert.Equal(hostnameConfigCreateResponse.CertificateId, hostnameConfigCreateResponse.CertificateId);
                    Assert.Equal("www.contoso.com", hostnameConfigCreateResponse.Hostname);
                    Assert.False(hostnameConfigCreateResponse.NegotiateClientCertificate);

                    var hostnameConfigResponse = await testBase.client.GatewayHostnameConfiguration.GetAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        hostnameConfigId
                        );

                    Assert.NotNull(hostnameConfigCreateResponse);
                    Assert.Equal(hostnameConfigId, hostnameConfigCreateResponse.Name);
                    Assert.Equal(hostnameConfigCreateResponse.CertificateId, hostnameConfigCreateResponse.CertificateId);
                    Assert.Equal("www.contoso.com", hostnameConfigCreateResponse.Hostname);
                    Assert.False(hostnameConfigCreateResponse.NegotiateClientCertificate);

                    //delete hostname config
                    testBase.client.GatewayHostnameConfiguration.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        hostnameConfigId,
                        "*");

                    //get latest etag for delete
                    getResponse = await testBase.client.Gateway.GetWithHttpMessagesAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId);

                    // remove the gateway
                    testBase.client.Gateway.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        gatewayId,
                        getResponse.Headers.ETag);

                    // list again to see it was removed
                    gatewayListResponse = testBase.client.Gateway.ListByService(
                        testBase.rgName,
                        testBase.serviceName,
                        null);

                    Assert.NotNull(gatewayListResponse);
                    Assert.Empty(gatewayListResponse);
                }
                finally
                {
                    try
                    {
                        testBase.client.GatewayHostnameConfiguration.Delete(testBase.rgName, testBase.serviceName, gatewayId, hostnameConfigId, "*");
                    }
                    catch (ErrorResponseException) { }
                    testBase.client.Gateway.Delete(testBase.rgName, testBase.serviceName, gatewayId, "*");
                    testBase.client.Certificate.Delete(testBase.rgName, testBase.serviceName, certificateId, "*");
                }
            }
        }
Example #27
0
        public async Task CreateUpdateDelete()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                // list all the APIs
                var apiListResponse = testBase.client.Api.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    null);
                Assert.NotNull(apiListResponse);
                Assert.Single(apiListResponse);
                Assert.Null(apiListResponse.NextPageLink);

                // find the echo api
                var echoApi = apiListResponse.First();

                // list users
                var listUsersResponse = testBase.client.User.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    null);

                Assert.NotNull(listUsersResponse);
                Assert.Single(listUsersResponse);

                var adminUser = listUsersResponse.First();

                // there should be now issues initially
                var issuesList = testBase.client.ApiIssue.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    echoApi.Name,
                    null);
                Assert.NotNull(issuesList);
                Assert.Empty(issuesList);

                string       newissueId      = TestUtilities.GenerateName("newIssue");
                string       newcommentId    = TestUtilities.GenerateName("newComment");
                string       newattachmentId = TestUtilities.GenerateName("newattachment");
                const string attachmentPath  = "./Resources/apiissueattachment.JPG";

                try
                {
                    // add a recipient to the notification
                    var issueContract = new IssueContract()
                    {
                        Title       = TestUtilities.GenerateName("title"),
                        Description = TestUtilities.GenerateName("description"),
                        UserId      = adminUser.Id,
                        ApiId       = echoApi.Id,
                        CreatedDate = DateTime.UtcNow
                    };
                    var apiIssueContract = await testBase.client.ApiIssue.CreateOrUpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        issueContract);

                    Assert.NotNull(apiIssueContract);
                    Assert.Equal(echoApi.Id, apiIssueContract.ApiId);
                    Assert.Equal(State.Proposed, apiIssueContract.State);
                    Assert.Equal(issueContract.Title, apiIssueContract.Title);
                    // get the issue
                    var issueData = await testBase.client.ApiIssue.GetAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId);

                    Assert.NotNull(issueData);
                    Assert.Equal(issueData.Name, newissueId);
                    Assert.Equal(adminUser.Id, issueData.UserId);

                    // update the issue
                    var updateTitle       = TestUtilities.GenerateName("updatedTitle");
                    var updateDescription = TestUtilities.GenerateName("updateddescription");

                    var issueUpdateContract = new IssueUpdateContract()
                    {
                        Description = updateDescription,
                        Title       = updateTitle
                    };

                    await testBase.client.ApiIssue.UpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        issueUpdateContract,
                        "*");

                    // get the issue
                    issueData = await testBase.client.ApiIssue.GetAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId);

                    Assert.NotNull(issueData);
                    Assert.Equal(issueData.Name, newissueId);
                    Assert.Equal(adminUser.Id, issueData.UserId);
                    Assert.Equal(updateTitle, issueData.Title);
                    Assert.Equal(updateDescription, issueData.Description);

                    // get commments on issue. there should be none initially
                    var emptyCommentList = await testBase.client.ApiIssueComment.ListByServiceAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        null);

                    Assert.Empty(emptyCommentList);

                    // add a comment
                    var issueCommentParameters = new IssueCommentContract()
                    {
                        Text        = TestUtilities.GenerateName("issuecommenttext"),
                        UserId      = adminUser.Id,
                        CreatedDate = DateTime.UtcNow
                    };
                    var addedComment = await testBase.client.ApiIssueComment.CreateOrUpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        newcommentId,
                        issueCommentParameters);

                    Assert.NotNull(addedComment);
                    Assert.Equal(addedComment.Name, newcommentId);
                    // https://msazure.visualstudio.com/DefaultCollection/One/_workitems/edit/4402087
                    //Assert.Equal(addedComment.UserId, adminUser.Id); //Bug userId is not getting populated
                    Assert.NotNull(addedComment.CreatedDate);

                    // get the comment tag.
                    var commentEntityTag = await testBase.client.ApiIssueComment.GetEntityTagAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        newcommentId);

                    Assert.NotNull(commentEntityTag);
                    Assert.NotNull(commentEntityTag.ETag);

                    // delete the commment
                    await testBase.client.ApiIssueComment.DeleteAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        newcommentId,
                        commentEntityTag.ETag);

                    try
                    {
                        // get the apicomment
                        var getComment = await testBase.client.ApiIssueComment.GetAsync(
                            testBase.rgName,
                            testBase.serviceName,
                            echoApi.Name,
                            newissueId,
                            newcommentId);

                        // should not come here
                        throw new Exception("This code should not have been executed.");
                    }
                    catch (ErrorResponseException ex)
                    {
                        Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
                    }

                    // get the issue attachments
                    var apiIssueAttachments = await testBase.client.ApiIssueAttachment.ListByServiceAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        null);

                    Assert.Empty(apiIssueAttachments);

                    // add an attachment to the issue
                    FileInfo fileInfo = new FileInfo(attachmentPath);

                    // The byte[] to save the data in
                    byte[] data = new byte[fileInfo.Length];

                    // Load a filestream and put its content into the byte[]
                    using (FileStream fs = fileInfo.OpenRead())
                    {
                        fs.Read(data, 0, data.Length);
                    }

                    var content = Convert.ToBase64String(data);
                    var issueAttachmentContract = new IssueAttachmentContract()
                    {
                        Content       = content,
                        ContentFormat = "image/jpeg",
                        Title         = TestUtilities.GenerateName("attachment")
                    };
                    var issueAttachment = await testBase.client.ApiIssueAttachment.CreateOrUpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        newattachmentId,
                        issueAttachmentContract);

                    Assert.NotNull(issueAttachment);
                    Assert.Equal(newattachmentId, issueAttachment.Name);
                    Assert.Equal("link", issueAttachment.ContentFormat);
                    Assert.NotNull(issueAttachment.Content);

                    // get the attachment tag
                    var issueAttachmentTag = await testBase.client.ApiIssueAttachment.GetEntityTagAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        newattachmentId);

                    Assert.NotNull(issueAttachmentTag);
                    Assert.NotNull(issueAttachmentTag.ETag);

                    // delete the attachment
                    await testBase.client.ApiIssueAttachment.DeleteAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        newattachmentId,
                        issueAttachmentTag.ETag);

                    try
                    {
                        var issueattachment = await testBase.client.ApiIssueAttachment.GetAsync(
                            testBase.rgName,
                            testBase.serviceName,
                            echoApi.Name,
                            newissueId,
                            newattachmentId);

                        // it should not reach here.
                        throw new Exception("This code should not have been executed.");
                    }
                    catch (ErrorResponseException ex)
                    {
                        Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
                    }

                    // get the issue tag
                    var apiIssuetag = await testBase.client.ApiIssue.GetEntityTagAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId);

                    Assert.NotNull(apiIssuetag);

                    // delete the issue
                    await testBase.client.ApiIssue.DeleteAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        apiIssuetag.ETag);

                    // check the issue exist
                    try
                    {
                        var apiIssue = await testBase.client.ApiIssue.GetAsync(
                            testBase.rgName,
                            testBase.serviceName,
                            echoApi.Name,
                            newissueId);

                        // it should not reach here.
                        throw new Exception("This code should not have been executed.");
                    }
                    catch (ErrorResponseException ex)
                    {
                        Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
                    }
                }
                finally
                {
                    // cleanup the api issue attachment, if exists
                    testBase.client.ApiIssueAttachment.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        newattachmentId,
                        "*");

                    // cleanup the api issue comment if exists
                    testBase.client.ApiIssueComment.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        newcommentId,
                        "*");

                    // cleanup the api issue if exists
                    testBase.client.ApiIssue.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        newissueId,
                        "*");
                }
            }
        }
Example #28
0
        public async Task CreateListUpdateDelete()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                var userId     = TestUtilities.GenerateName("sdkUserId");
                var newGroupId = TestUtilities.GenerateName("sdkGroupId");

                try
                {
                    // create a new group
                    var newGroupDisplayName = TestUtilities.GenerateName("sdkGroup");
                    var parameters          = new GroupCreateParameters()
                    {
                        DisplayName = newGroupDisplayName,
                        Description = "Group created from Sdk client"
                    };

                    var groupContract = await testBase.client.Group.CreateOrUpdateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        parameters);

                    Assert.NotNull(groupContract);
                    Assert.Equal(newGroupDisplayName, groupContract.DisplayName);
                    Assert.False(groupContract.BuiltIn);
                    Assert.NotNull(groupContract.Description);
                    Assert.Equal(GroupType.Custom, groupContract.GroupContractType);

                    // list all group users
                    var listResponse = testBase.client.GroupUser.List(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        null);
                    Assert.NotNull(listResponse);
                    Assert.Empty(listResponse);

                    // create a new user and add to the group
                    var createParameters = new UserCreateParameters()
                    {
                        FirstName = TestUtilities.GenerateName("sdkFirst"),
                        LastName  = TestUtilities.GenerateName("sdkLast"),
                        Email     = TestUtilities.GenerateName("sdkFirst.Last") + "@contoso.com",
                        State     = UserState.Active,
                        Note      = "dummy note"
                    };

                    var userContract = testBase.client.User.CreateOrUpdate(
                        testBase.rgName,
                        testBase.serviceName,
                        userId,
                        createParameters);
                    Assert.NotNull(userContract);

                    // add user to group
                    var addUserContract = testBase.client.GroupUser.Create(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        userId);
                    Assert.NotNull(addUserContract);
                    Assert.Equal(userContract.Email, addUserContract.Email);
                    Assert.Equal(userContract.FirstName, addUserContract.FirstName);

                    // list group user
                    var listgroupResponse = testBase.client.GroupUser.List(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId);
                    Assert.NotNull(listgroupResponse);
                    Assert.Single(listgroupResponse);
                    Assert.Equal(addUserContract.Email, listgroupResponse.GetEnumerator().ToIEnumerable().First().Email);

                    // check entity exists
                    var entityStatus = await testBase.client.GroupUser.CheckEntityExistsAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        userId);

                    Assert.True(entityStatus);

                    // remove user from group
                    testBase.client.GroupUser.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        userId);

                    // make sure user is removed
                    entityStatus = await testBase.client.GroupUser.CheckEntityExistsAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        userId);

                    Assert.False(entityStatus);
                }
                finally
                {
                    // delete the user
                    testBase.client.User.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        userId,
                        "*",
                        deleteSubscriptions: true);

                    // delete the group
                    testBase.client.Group.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        newGroupId,
                        "*");
                }
            }
        }
        public async Task CreateListUpdateDeleteOperationTags()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                var tagsResources = await testBase.client.Tag.ListByServiceAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.Empty(tagsResources);

                // there should be 'Echo API' which is created by default for every new instance of API Management
                var apis = testBase.client.Api.ListByService(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.Single(apis);
                var api = apis.Single();

                // list paged
                var listResponse = testBase.client.ApiOperation.ListByApi(
                    testBase.rgName,
                    testBase.serviceName,
                    api.Name,
                    new Microsoft.Rest.Azure.OData.ODataQuery <OperationContract> {
                    Top = 1
                });

                var firstOperation = listResponse.First();

                string tagId = TestUtilities.GenerateName("operationTag");
                try
                {
                    string tagDisplayName   = TestUtilities.GenerateName("opreationTag");
                    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 Operation
                    tagContract = await testBase.client.Tag.AssignToOperationAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        api.Name,
                        firstOperation.Name,
                        tagId);

                    Assert.NotNull(tagContract);

                    // Tag list by Api Operation
                    var tagsInOperation = await testBase.client.Tag.ListByOperationAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        api.Name,
                        firstOperation.Name);

                    Assert.NotNull(tagsInOperation);
                    Assert.Single(tagsInOperation);
                    Assert.Equal(tagDisplayName, tagsInOperation.First().DisplayName);

                    // get the tag on the api operation
                    var tagOnOperation = await testBase.client.Tag.GetByOperationAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        api.Name,
                        firstOperation.Name,
                        tagId);

                    Assert.NotNull(tagOnOperation);
                    Assert.Equal(tagDisplayName, tagOnOperation.DisplayName);

                    // get the tag resources for the service.
                    var tagResources = await testBase.client.TagResource.ListByServiceAsync(
                        testBase.rgName,
                        testBase.serviceName);

                    Assert.NotNull(tagResources);
                    Assert.Single(tagResources);
                    Assert.Equal(tagDisplayName, tagResources.First().Tag.Name);
                    Assert.Null(tagResources.First().Api);
                    Assert.NotNull(tagResources.First().Operation);
                    Assert.Null(tagResources.First().Product);
                    Assert.Equal(firstOperation.DisplayName, tagResources.GetEnumerator().ToIEnumerable().First().Operation.Name, true);
                    Assert.Equal(firstOperation.Method, tagResources.GetEnumerator().ToIEnumerable().First().Operation.Method);

                    // get the tag Etag
                    var tagEtagByOperation = await testBase.client.Tag.GetEntityStateByOperationAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        api.Name,
                        firstOperation.Name,
                        tagId);

                    Assert.NotNull(tagEtagByOperation);
                    Assert.NotNull(tagEtagByOperation.ETag);

                    // detach the tag
                    await testBase.client.Tag.DetachFromOperationAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        api.Name,
                        firstOperation.Name,
                        tagId);

                    Assert.Throws <ErrorResponseException>(()
                                                           => testBase.client.Tag.GetByOperation(
                                                               testBase.rgName,
                                                               testBase.serviceName,
                                                               api.Name,
                                                               firstOperation.Name,
                                                               tagId));

                    var tagEtag = await testBase.client.Tag.GetEntityStateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        tagId);

                    Assert.NotNull(tagEtag);
                    Assert.NotNull(tagEtag.ETag);

                    //delete the tag
                    await testBase.client.Tag.DeleteAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        tagId,
                        tagEtag.ETag);

                    Assert.Throws <ErrorResponseException>(()
                                                           => testBase.client.Tag.GetEntityState(
                                                               testBase.rgName,
                                                               testBase.serviceName,
                                                               tagId));
                }
                finally
                {
                    testBase.client.Tag.DetachFromOperation(
                        testBase.rgName,
                        testBase.serviceName,
                        api.Name,
                        firstOperation.Name,
                        tagId);

                    testBase.client.Tag.Delete(
                        testBase.rgName, testBase.serviceName, tagId, "*");
                }
            }
        }
        public async Task CreateListUpdateDeleteApiTags()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                var tagsResources = await testBase.client.Tag.ListByServiceAsync(
                    testBase.rgName,
                    testBase.serviceName);

                Assert.Empty(tagsResources);

                // 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);

                    // get APIs with Tags
                    var apisWithTags = await testBase.client.Api.ListByTagsAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        new Microsoft.Rest.Azure.OData.ODataQuery <TagResourceContract>
                    {
                        Top = 1
                    });

                    Assert.NotNull(apisWithTags);
                    Assert.Single(apisWithTags);
                    Assert.Equal(tagContract.DisplayName, apisWithTags.GetEnumerator().ToIEnumerable().First().Tag.Name);

                    // Tag list by API
                    var tagsInApi = await testBase.client.Tag.ListByApiAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name);

                    Assert.NotNull(tagsInApi);
                    Assert.Single(tagsInApi);
                    Assert.Equal(tagDisplayName, tagsInApi.GetEnumerator().ToIEnumerable().First().DisplayName);

                    // get the tag on the api
                    var tagOnApi = await testBase.client.Tag.GetByApiAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        tagId);

                    Assert.NotNull(tagOnApi);
                    Assert.Equal(tagDisplayName, tagOnApi.DisplayName);

                    // get the tag Etag
                    var tagEtagByApi = await testBase.client.Tag.GetEntityStateByApiAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        tagId);

                    Assert.NotNull(tagEtagByApi);
                    Assert.NotNull(tagEtagByApi.ETag);

                    // get the tag resources for the service.
                    var tagResources = await testBase.client.TagResource.ListByServiceAsync(
                        testBase.rgName,
                        testBase.serviceName);

                    Assert.NotNull(tagResources);
                    Assert.Single(tagResources);
                    Assert.Equal(tagDisplayName, tagResources.GetEnumerator().ToIEnumerable().First().Tag.Name);
                    Assert.NotNull(tagResources.GetEnumerator().ToIEnumerable().First().Api);
                    Assert.Equal(echoApi.DisplayName, tagResources.GetEnumerator().ToIEnumerable().First().Api.Name);

                    // detach the tag
                    await testBase.client.Tag.DetachFromApiAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        echoApi.Name,
                        tagId);

                    Assert.Throws <ErrorResponseException>(()
                                                           => testBase.client.Tag.GetByApi(
                                                               testBase.rgName,
                                                               testBase.serviceName,
                                                               echoApi.Name,
                                                               tagId));

                    var tagEtag = await testBase.client.Tag.GetEntityStateAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        tagId);

                    Assert.NotNull(tagEtag);
                    Assert.NotNull(tagEtag.ETag);

                    //delete the tag
                    await testBase.client.Tag.DeleteAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        tagId,
                        tagEtag.ETag);

                    Assert.Throws <ErrorResponseException>(()
                                                           => testBase.client.Tag.GetEntityState(
                                                               testBase.rgName,
                                                               testBase.serviceName,
                                                               tagId));
                }
                finally
                {
                    testBase.client.Tag.DetachFromApi(
                        testBase.rgName, testBase.serviceName, echoApi.Name, tagId);
                    testBase.client.Tag.Delete(
                        testBase.rgName, testBase.serviceName, tagId, "*");
                }
            }
        }