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 ProfileResource AfdProfileResource = await resourceGroup.GetProfiles().GetAsync("myAfdProfile"); FrontDoorRuleSetResource ruleSet = await AfdProfileResource.GetFrontDoorRuleSets().GetAsync("myAfdRuleSet"); FrontDoorRuleCollection ruleCollection = ruleSet.GetFrontDoorRules(); // Now we can get the rule with GetAsync() FrontDoorRuleResource rule = await ruleCollection.GetAsync("myAfdRule"); // With UpdateAsync(), we can update the rule FrontDoorRulePatch input = new FrontDoorRulePatch { Order = 2 }; input.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchCondition(RequestUriMatchConditionType.RequestUriCondition, RequestUriOperator.Any))); input.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionProperties(CacheExpirationActionType.CacheExpirationAction, CacheBehaviorSetting.Override, CacheLevel.All) { CacheDuration = new TimeSpan(0, 0, 30) })); ArmOperation <FrontDoorRuleResource> lro = await rule.UpdateAsync(WaitUntil.Completed, input); rule = lro.Value; #endregion Snippet:Managing_AfdRules_UpdateAnAzureFrontDoorRule }
public async Task Update() { SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync(); ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-"); string afdProfileName = Recording.GenerateAssetName("AFDProfile-"); ProfileResource afdProfile = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor); string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet"); FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfile, afdRuleSetName); string afdRuleName = Recording.GenerateAssetName("AFDRule"); FrontDoorRuleResource afdRule = await CreateAfdRule(afdRuleSet, afdRuleName); FrontDoorRulePatch updateOptions = new FrontDoorRulePatch { Order = 2 }; updateOptions.Conditions.Add(ResourceDataHelper.CreateDeliveryRuleCondition()); updateOptions.Actions.Add(ResourceDataHelper.CreateDeliveryRuleOperation()); var lro = await afdRule.UpdateAsync(WaitUntil.Completed, updateOptions); FrontDoorRuleResource updatedAfdRule = lro.Value; ResourceDataHelper.AssertAfdRuleUpdate(updatedAfdRule, updateOptions); }
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 CdnSku { Name = CdnSkuName.StandardAzureFrontDoor }); ArmOperation <ProfileResource> lro1 = await resourceGroup.GetProfiles().CreateOrUpdateAsync(WaitUntil.Completed, AfdProfileName, input1); ProfileResource AfdProfileResource = lro1.Value; // Get the rule set collection from the specific azure front door ProfileResource and create a rule set string ruleSetName = "myAfdRuleSet"; ArmOperation <FrontDoorRuleSetResource> lro2 = await AfdProfileResource.GetFrontDoorRuleSets().CreateOrUpdateAsync(WaitUntil.Completed, ruleSetName); FrontDoorRuleSetResource ruleSet = lro2.Value; // Get the rule collection from the specific rule set and create a rule string ruleName = "myAfdRule"; FrontDoorRuleData input3 = new FrontDoorRuleData { Order = 1 }; input3.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchCondition(RequestUriMatchConditionType.RequestUriCondition, RequestUriOperator.Any))); input3.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionProperties(CacheExpirationActionType.CacheExpirationAction, CacheBehaviorSetting.Override, CacheLevel.All) { CacheDuration = new TimeSpan(0, 0, 20) })); ArmOperation <FrontDoorRuleResource> lro3 = await ruleSet.GetFrontDoorRules().CreateOrUpdateAsync(WaitUntil.Completed, ruleName, input3); FrontDoorRuleResource rule = lro3.Value; #endregion Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule }
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 ProfileResource AfdProfileResource = await resourceGroup.GetProfiles().GetAsync("myAfdProfile"); FrontDoorRuleSetResource ruleSet = await AfdProfileResource.GetFrontDoorRuleSets().GetAsync("myAfdRuleSet"); FrontDoorRuleCollection ruleCollection = ruleSet.GetFrontDoorRules(); // Now we can get the rule with GetAsync() FrontDoorRuleResource rule = await ruleCollection.GetAsync("myAfdRule"); // With DeleteAsync(), we can delete the rule await rule.DeleteAsync(WaitUntil.Completed); #endregion Snippet:Managing_AfdRules_DeleteAnAzureFrontDoorRule }
public async Task CreateOrUpdate() { SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync(); ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-"); string afdProfileName = Recording.GenerateAssetName("AFDProfile-"); ProfileResource afdProfileResource = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor); string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet"); FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName); string afdRuleName = Recording.GenerateAssetName("AFDRule"); FrontDoorRuleResource afdRule = await CreateAfdRule(afdRuleSet, afdRuleName); Assert.AreEqual(afdRuleName, afdRule.Data.Name); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetFrontDoorRules().CreateOrUpdateAsync(WaitUntil.Completed, null, afdRule.Data)); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetFrontDoorRules().CreateOrUpdateAsync(WaitUntil.Completed, afdRuleName, null)); }
public async Task Get() { SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync(); ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-"); string afdProfileName = Recording.GenerateAssetName("AFDProfile-"); ProfileResource afdProfileResource = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor); string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet"); FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName); string afdRuleName = Recording.GenerateAssetName("AFDRule"); FrontDoorRuleResource afdRule = await CreateAfdRule(afdRuleSet, afdRuleName); FrontDoorRuleResource getAfdRule = await afdRuleSet.GetFrontDoorRules().GetAsync(afdRuleName); ResourceDataHelper.AssertValidAfdRule(afdRule, getAfdRule); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetFrontDoorRules().GetAsync(null)); }
public static void AssertValidAfdRule(FrontDoorRuleResource model, FrontDoorRuleResource getResult) { Assert.AreEqual(model.Data.Name, getResult.Data.Name); Assert.AreEqual(model.Data.Id, getResult.Data.Id); Assert.AreEqual(model.Data.ResourceType, getResult.Data.ResourceType); 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() { SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync(); ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-"); string afdProfileName = Recording.GenerateAssetName("AFDProfile-"); ProfileResource afdProfile = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor); string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet"); FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfile, afdRuleSetName); string afdRuleName = Recording.GenerateAssetName("AFDRule"); FrontDoorRuleResource afdRule = await CreateAfdRule(afdRuleSet, afdRuleName); await afdRule.DeleteAsync(WaitUntil.Completed); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await afdRule.GetAsync()); Assert.AreEqual(404, ex.Status); }
public static void AssertAfdRuleUpdate(FrontDoorRuleResource updatedRule, FrontDoorRulePatch updateOptions) { Assert.AreEqual(updatedRule.Data.Order, updateOptions.Order); }