Example #1
0
        public async Task UpdateAfdRules()
        {
            #region Snippet:Managing_AfdRules_UpdateAnAzureFrontDoorRule
            // First we need to get the azure front door rule collection from the specific rule set
            Profile AfdProfile = await resourceGroup.GetProfiles().GetAsync("myAfdProfile");

            AfdRuleSet ruleSet = await AfdProfile.GetAfdRuleSets().GetAsync("myAfdRuleSet");

            AfdRuleCollection ruleCollection = ruleSet.GetAfdRules();
            // Now we can get the rule with GetAsync()
            AfdRule rule = await ruleCollection.GetAsync("myAfdRule");

            // With UpdateAsync(), we can update the rule
            RuleUpdateOptions input = new RuleUpdateOptions
            {
                Order = 2
            };
            input.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchConditionParameters(RequestUriMatchConditionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleRequestUriConditionParameters, RequestUriOperator.Any)));
            input.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionParameters(CacheExpirationActionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleCacheExpirationActionParameters, CacheBehavior.Override, CacheType.All)
            {
                CacheDuration = "00:00:30"
            }));
            AfdRuleUpdateOperation lro = await rule.UpdateAsync(true, input);

            rule = lro.Value;
            #endregion Snippet:Managing_AfdRules_UpdateAnAzureFrontDoorRule
        }
Example #2
0
        public async Task CreateAfdRules()
        {
            #region Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule
            // Create a new azure front door profile
            string AfdProfileName = "myAfdProfile";
            var    input1         = new ProfileData("Global", new Models.Sku {
                Name = SkuName.StandardAzureFrontDoor
            });
            ProfileCreateOperation lro1 = await resourceGroup.GetProfiles().CreateOrUpdateAsync(true, AfdProfileName, input1);

            Profile AfdProfile = lro1.Value;
            // Get the rule set collection from the specific azure front door profile and create a rule set
            string ruleSetName             = "myAfdRuleSet";
            AfdRuleSetCreateOperation lro2 = await AfdProfile.GetAfdRuleSets().CreateOrUpdateAsync(true, ruleSetName);

            AfdRuleSet ruleSet = lro2.Value;
            // Get the rule collection from the specific rule set and create a rule
            string      ruleName = "myAfdRule";
            AfdRuleData input3   = new AfdRuleData
            {
                Order = 1
            };
            input3.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchConditionParameters(RequestUriMatchConditionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleRequestUriConditionParameters, RequestUriOperator.Any)));
            input3.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionParameters(CacheExpirationActionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleCacheExpirationActionParameters, CacheBehavior.Override, CacheType.All)
            {
                CacheDuration = "00:00:20"
            }));
            AfdRuleCreateOperation lro3 = await ruleSet.GetAfdRules().CreateOrUpdateAsync(true, ruleName, input3);

            AfdRule rule = lro3.Value;
            #endregion Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule
        }
        public async Task Update()
        {
            Subscription subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroup rg = await CreateResourceGroup(subscription, "testRg-");

            string  afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            Profile afdProfile     = await CreateAfdProfile(rg, afdProfileName, SkuName.StandardAzureFrontDoor);

            string     afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            AfdRuleSet afdRuleSet     = await CreateAfdRuleSet(afdProfile, afdRuleSetName);

            string  afdRuleName = Recording.GenerateAssetName("AFDRule");
            AfdRule afdRule     = await CreateAfdRule(afdRuleSet, afdRuleName);

            RuleUpdateOptions updateOptions = new RuleUpdateOptions
            {
                Order = 2
            };

            updateOptions.Conditions.Add(ResourceDataHelper.CreateDeliveryRuleCondition());
            updateOptions.Actions.Add(ResourceDataHelper.UpdateDeliveryRuleOperation());
            var lro = await afdRule.UpdateAsync(true, updateOptions);

            AfdRule updatedAfdRule = lro.Value;

            ResourceDataHelper.AssertAfdRuleUpdate(updatedAfdRule, updateOptions);
        }
Example #4
0
        public async Task DeleteAfdRules()
        {
            #region Snippet:Managing_AfdRules_DeleteAnAzureFrontDoorRule
            // First we need to get the azure front door rule collection from the specific rule set
            Profile AfdProfile = await resourceGroup.GetProfiles().GetAsync("myAfdProfile");

            AfdRuleSet ruleSet = await AfdProfile.GetAfdRuleSets().GetAsync("myAfdRuleSet");

            AfdRuleCollection ruleCollection = ruleSet.GetAfdRules();
            // Now we can get the rule with GetAsync()
            AfdRule rule = await ruleCollection.GetAsync("myAfdRule");

            // With DeleteAsync(), we can delete the rule
            await rule.DeleteAsync(true);

            #endregion Snippet:Managing_AfdRules_DeleteAnAzureFrontDoorRule
        }
        public async Task CreateOrUpdate()
        {
            Subscription subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroup rg = await CreateResourceGroup(subscription, "testRg-");

            string  afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            Profile afdProfile     = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string     afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            AfdRuleSet afdRuleSet     = await CreateAfdRuleSet(afdProfile, afdRuleSetName);

            string  afdRuleName = Recording.GenerateAssetName("AFDRule");
            AfdRule afdRule     = await CreateAfdRule(afdRuleSet, afdRuleName);

            Assert.AreEqual(afdRuleName, afdRule.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetAfdRules().CreateOrUpdateAsync(WaitUntil.Completed, null, afdRule.Data));
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetAfdRules().CreateOrUpdateAsync(WaitUntil.Completed, afdRuleName, null));
        }
        public async Task Get()
        {
            Subscription subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroup rg = await CreateResourceGroup(subscription, "testRg-");

            string  afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            Profile afdProfile     = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string     afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            AfdRuleSet afdRuleSet     = await CreateAfdRuleSet(afdProfile, afdRuleSetName);

            string  afdRuleName = Recording.GenerateAssetName("AFDRule");
            AfdRule afdRule     = await CreateAfdRule(afdRuleSet, afdRuleName);

            AfdRule getAfdRule = await afdRuleSet.GetAfdRules().GetAsync(afdRuleName);

            ResourceDataHelper.AssertValidAfdRule(afdRule, getAfdRule);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetAfdRules().GetAsync(null));
        }
 public static void AssertValidAfdRule(AfdRule model, AfdRule getResult)
 {
     Assert.AreEqual(model.Data.Name, getResult.Data.Name);
     Assert.AreEqual(model.Data.Id, getResult.Data.Id);
     Assert.AreEqual(model.Data.Type, getResult.Data.Type);
     Assert.AreEqual(model.Data.Order, getResult.Data.Order);
     Assert.AreEqual(model.Data.Conditions.Count, getResult.Data.Conditions.Count);
     for (int i = 0; i < model.Data.Conditions.Count; ++i)
     {
         Assert.AreEqual(model.Data.Conditions[i].Name, getResult.Data.Conditions[i].Name);
     }
     Assert.AreEqual(model.Data.Actions.Count, getResult.Data.Actions.Count);
     for (int i = 0; i < model.Data.Actions.Count; ++i)
     {
         Assert.AreEqual(model.Data.Actions[i].Name, getResult.Data.Actions[i].Name);
     }
     Assert.AreEqual(model.Data.MatchProcessingBehavior, getResult.Data.MatchProcessingBehavior);
     Assert.AreEqual(model.Data.ProvisioningState, getResult.Data.ProvisioningState);
     Assert.AreEqual(model.Data.DeploymentStatus, getResult.Data.DeploymentStatus);
 }
        public async Task Delete()
        {
            Subscription subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroup rg = await CreateResourceGroup(subscription, "testRg-");

            string  afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            Profile afdProfile     = await CreateAfdProfile(rg, afdProfileName, SkuName.StandardAzureFrontDoor);

            string     afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            AfdRuleSet afdRuleSet     = await CreateAfdRuleSet(afdProfile, afdRuleSetName);

            string  afdRuleName = Recording.GenerateAssetName("AFDRule");
            AfdRule afdRule     = await CreateAfdRule(afdRuleSet, afdRuleName);

            await afdRule.DeleteAsync(true);

            var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await afdRule.GetAsync());

            Assert.AreEqual(404, ex.Status);
        }
 public static void AssertAfdRuleUpdate(AfdRule updatedRule, RuleUpdateOptions updateOptions)
 {
     Assert.AreEqual(updatedRule.Data.Order, updateOptions.Order);
 }