コード例 #1
0
 /// <summary>
 /// Update product.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IProductsOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='pid'>
 /// Required. Identifier of the product.
 /// </param>
 /// <param name='parameters'>
 /// Required. Update parameters.
 /// </param>
 /// <param name='etag'>
 /// Required. ETag.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse Update(this IProductsOperations operations, string resourceGroupName, string serviceName, string pid, ProductUpdateParameters parameters, string etag)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IProductsOperations)s).UpdateAsync(resourceGroupName, serviceName, pid, parameters, etag);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
コード例 #2
0
 /// <summary>
 /// Update product.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IProductsOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='pid'>
 /// Required. Identifier of the product.
 /// </param>
 /// <param name='parameters'>
 /// Required. Update parameters.
 /// </param>
 /// <param name='etag'>
 /// Required. ETag.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> UpdateAsync(this IProductsOperations operations, string resourceGroupName, string serviceName, string pid, ProductUpdateParameters parameters, string etag)
 {
     return operations.UpdateAsync(resourceGroupName, serviceName, pid, parameters, etag, CancellationToken.None);
 }
        public void ProductsCreateListUpdateDelete()
        {
            TestUtilities.StartTest("SmapiFunctionalTests", "ProductsCreateListUpdateDelete");

            try
            {
                // list all products: there should be two products: Starter and Unlimited
                var listResponse = ApiManagementClient.Products.List(ResourceGroupName, ApiManagementServiceName, null);

                Assert.NotNull(listResponse);
                Assert.NotNull(listResponse.Result);
                Assert.Equal(2, listResponse.Result.TotalCount);
                Assert.Equal(2, listResponse.Result.Values.Count);

                // list paged
                listResponse = ApiManagementClient.Products.List(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    new QueryParameters {Top = 1});

                Assert.NotNull(listResponse);
                Assert.NotNull(listResponse.Result);
                Assert.Equal(2, listResponse.Result.TotalCount);
                Assert.Equal(1, listResponse.Result.Values.Count);

                // create new product
                string productId = TestUtilities.GenerateName("productId");
                string productName = TestUtilities.GenerateName("productName");
                bool? productApprovalRequired = true;
                string productDescription = TestUtilities.GenerateName("productDescription");
                PeriodContract productNotificationPeriod = new PeriodContract
                {
                    Interval = PeriodIntervalContract.Month,
                    Value = 2
                };
                ProductStateContract productState = ProductStateContract.NotPublished;
                PeriodContract productSubscriptionPeriod = new PeriodContract
                {
                    Interval = PeriodIntervalContract.Year,
                    Value = 1
                };
                bool? productSubscriptionRequired = true;
                int? productSubscriptionsLimit = 10;
                string productTerms = TestUtilities.GenerateName("productTerms");

                ProductContract productContract = new ProductContract(productName)
                {
                    ApprovalRequired = productApprovalRequired,
                    Description = productDescription,
                    //Groups = 
                    NotificationPeriod = productNotificationPeriod,
                    State = productState,
                    SubscriptionPeriod = productSubscriptionPeriod,
                    SubscriptionRequired = productSubscriptionRequired,
                    SubscriptionsLimit = productSubscriptionsLimit,
                    Terms = productTerms
                };

                var createResponse = ApiManagementClient.Products.Create(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    productId,
                    new ProductCreateParameters(productContract));

                Assert.NotNull(createResponse);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // get to check it was created
                var getResponse = ApiManagementClient.Products.Get(ResourceGroupName, ApiManagementServiceName, productId);

                Assert.NotNull(getResponse);
                Assert.NotNull(getResponse.Value);

                Assert.Equal(productId, getResponse.Value.Id);
                Assert.Equal(productName, getResponse.Value.Name);
                Assert.Equal(productApprovalRequired, getResponse.Value.ApprovalRequired);
                Assert.Equal(productDescription, getResponse.Value.Description);
                Assert.Equal(productNotificationPeriod.Interval, getResponse.Value.NotificationPeriod.Interval);
                Assert.Equal(productNotificationPeriod.Value, getResponse.Value.NotificationPeriod.Value);
                Assert.Equal(productState, getResponse.Value.State);
                Assert.Equal(productSubscriptionPeriod.Interval, getResponse.Value.SubscriptionPeriod.Interval);
                Assert.Equal(productSubscriptionPeriod.Value, getResponse.Value.SubscriptionPeriod.Value);
                Assert.Equal(productSubscriptionRequired, getResponse.Value.SubscriptionRequired);
                Assert.Equal(productSubscriptionsLimit, getResponse.Value.SubscriptionsLimit);
                Assert.Equal(productTerms, getResponse.Value.Terms);

                // update product
                string patchedName = TestUtilities.GenerateName("productName");
                string patchedDescription = TestUtilities.GenerateName("productDescription");
                string patchedTerms = TestUtilities.GenerateName("productTerms");
                var updateParameters = new ProductUpdateParameters
                {
                    Name = patchedName,
                    Description = patchedDescription,
                    Terms = patchedTerms
                };
                ApiManagementClient.Products.Update(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    productId,
                    updateParameters,
                    getResponse.ETag);

                // get to check it was updated
                getResponse = ApiManagementClient.Products.Get(ResourceGroupName, ApiManagementServiceName, productId);

                Assert.NotNull(getResponse);
                Assert.NotNull(getResponse.Value);

                Assert.Equal(productId, getResponse.Value.Id);
                Assert.Equal(patchedName, getResponse.Value.Name);
                Assert.Equal(productApprovalRequired, getResponse.Value.ApprovalRequired);
                Assert.Equal(patchedDescription, getResponse.Value.Description);
                Assert.Equal(productNotificationPeriod.Interval, getResponse.Value.NotificationPeriod.Interval);
                Assert.Equal(productNotificationPeriod.Value, getResponse.Value.NotificationPeriod.Value);
                Assert.Equal(productState, getResponse.Value.State);
                Assert.Equal(productSubscriptionPeriod.Interval, getResponse.Value.SubscriptionPeriod.Interval);
                Assert.Equal(productSubscriptionPeriod.Value, getResponse.Value.SubscriptionPeriod.Value);
                Assert.Equal(productSubscriptionRequired, getResponse.Value.SubscriptionRequired);
                Assert.Equal(productSubscriptionsLimit, getResponse.Value.SubscriptionsLimit);
                Assert.Equal(patchedTerms, getResponse.Value.Terms);

                // delete the product 
                var deleteResponse = ApiManagementClient.Products.Delete(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    productId,
                    getResponse.ETag,
                    true);

                Assert.NotNull(deleteResponse);
                Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode);

                // get the deleted api to make sure it was deleted
                try
                {
                    ApiManagementClient.Products.Get(ResourceGroupName, ApiManagementServiceName, productId);
                    throw new Exception("This code should not have been executed.");
                }
                catch (CloudException ex)
                {
                    Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
                }
            }
            finally
            {
                TestUtilities.EndTest();
            }
        }