/// <summary>
 /// Updates an existing delivery rule within a rule set.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the Resource group within the Azure subscription.
 /// </param>
 /// <param name='profileName'>
 /// Name of the CDN profile which is unique within the resource group.
 /// </param>
 /// <param name='ruleSetName'>
 /// Name of the rule set under the profile.
 /// </param>
 /// <param name='ruleName'>
 /// Name of the delivery rule which is unique within the endpoint.
 /// </param>
 /// <param name='ruleUpdateProperties'>
 /// Delivery rule properties
 /// </param>
 public static Rule BeginUpdate(this IRulesOperations operations, string resourceGroupName, string profileName, string ruleSetName, string ruleName, RuleUpdateParameters ruleUpdateProperties)
 {
     return(operations.BeginUpdateAsync(resourceGroupName, profileName, ruleSetName, ruleName, ruleUpdateProperties).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Updates an existing delivery rule within a rule set.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the Resource group within the Azure subscription.
 /// </param>
 /// <param name='profileName'>
 /// Name of the CDN profile which is unique within the resource group.
 /// </param>
 /// <param name='ruleSetName'>
 /// Name of the rule set under the profile.
 /// </param>
 /// <param name='ruleName'>
 /// Name of the delivery rule which is unique within the endpoint.
 /// </param>
 /// <param name='ruleUpdateProperties'>
 /// Delivery rule properties
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <Rule> BeginUpdateAsync(this IRulesOperations operations, string resourceGroupName, string profileName, string ruleSetName, string ruleName, RuleUpdateParameters ruleUpdateProperties, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(resourceGroupName, profileName, ruleSetName, ruleName, ruleUpdateProperties, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemplo n.º 3
0
        public void AFDRuleUpdateTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                // Create clients
                var cdnMgmtClient   = CdnTestUtilities.GetCdnManagementClient(context, handler1);
                var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2);

                // Create resource group
                var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient);

                try
                {
                    // Create a standard Azure frontdoor profile
                    string  profileName      = TestUtilities.GenerateName("profile");
                    Profile createParameters = new Profile
                    {
                        Location = "WestUs",
                        Sku      = new Sku {
                            Name = SkuName.StandardAzureFrontDoor
                        },
                        Tags = new Dictionary <string, string>
                        {
                            { "key1", "value1" },
                            { "key2", "value2" }
                        }
                    };
                    var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters);

                    string ruleSetName = TestUtilities.GenerateName("ruleSetName");
                    var    ruleSet     = cdnMgmtClient.RuleSets.Create(resourceGroupName, profileName, ruleSetName);
                    Assert.NotNull(ruleSet);
                    Assert.Equal(ruleSetName, ruleSet.Name);

                    // Create a standard Azure frontdoor rule
                    string ruleName = TestUtilities.GenerateName("ruleName");
                    var    ruleGroupCreateParameters = new Rule
                    {
                        Conditions = new List <DeliveryRuleCondition>()
                        {
                            new DeliveryRuleRequestUriCondition()
                            {
                                Parameters = new RequestUriMatchConditionParameters()
                                {
                                    OperatorProperty = "Any"
                                }
                            }
                        },
                        Actions = new List <DeliveryRuleAction>
                        {
                            new DeliveryRuleCacheExpirationAction()
                            {
                                Parameters = new CacheExpirationActionParameters()
                                {
                                    CacheBehavior = "Override",
                                    CacheDuration = "00:00:20"
                                }
                            }
                        }
                    };
                    var rule = cdnMgmtClient.Rules.Create(resourceGroupName, profileName, ruleSetName, ruleName, ruleGroupCreateParameters);
                    Assert.NotNull(rule);
                    Assert.Equal(ruleName, rule.Name);
                    Assert.Equal(ruleGroupCreateParameters.Conditions.Count, rule.Conditions.Count);
                    Assert.Equal(ruleGroupCreateParameters.Actions.Count, rule.Actions.Count);


                    RuleUpdateParameters ruleUpdateProperties = new RuleUpdateParameters()
                    {
                        Conditions = new List <DeliveryRuleCondition>()
                        {
                        },
                        Actions = new List <DeliveryRuleAction>
                        {
                            new DeliveryRuleCacheExpirationAction()
                            {
                                Parameters = new CacheExpirationActionParameters()
                                {
                                    CacheBehavior = "Override",
                                    CacheDuration = "00:00:20"
                                }
                            }
                        }
                    };
                    var updatedRule = cdnMgmtClient.Rules.Update(resourceGroupName, profileName, ruleSetName, ruleName, ruleUpdateProperties);
                    Assert.NotNull(updatedRule);
                    Assert.Equal(ruleName, updatedRule.Name);
                    Assert.Equal(ruleUpdateProperties.Conditions.Count, updatedRule.Conditions.Count);
                    Assert.Equal(ruleUpdateProperties.Actions.Count, updatedRule.Actions.Count);
                }
                finally
                {
                    // Delete resource group
                    _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName);
                }
            }
        }