public async Task Delete() { 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 afdEndpointName = Recording.GenerateAssetName("AFDEndpoint-"); FrontDoorEndpointResource afdEndpointInstance = await CreateAfdEndpoint(afdProfileResource, afdEndpointName); string afdOriginGroupName = Recording.GenerateAssetName("AFDOriginGroup-"); FrontDoorOriginGroupResource afdOriginGroupInstance = await CreateAfdOriginGroup(afdProfileResource, afdOriginGroupName); string afdOriginName = Recording.GenerateAssetName("AFDOrigin-"); FrontDoorOriginResource afdOriginInstance = await CreateAfdOrigin(afdOriginGroupInstance, afdOriginName); string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet"); FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName); string afdRouteName = Recording.GenerateAssetName("AFDRoute"); FrontDoorRouteResource afdRoute = await CreateAfdRoute(afdEndpointInstance, afdRouteName, afdOriginGroupInstance, afdRuleSet); await afdRoute.DeleteAsync(WaitUntil.Completed); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await afdRoute.GetAsync()); Assert.AreEqual(404, ex.Status); }
public async Task Update() { 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 afdEndpointName = Recording.GenerateAssetName("AFDEndpoint-"); FrontDoorEndpointResource afdEndpointInstance = await CreateAfdEndpoint(afdProfileResource, afdEndpointName); string afdOriginGroupName = Recording.GenerateAssetName("AFDOriginGroup-"); FrontDoorOriginGroupResource afdOriginGroupInstance = await CreateAfdOriginGroup(afdProfileResource, afdOriginGroupName); string afdOriginName = Recording.GenerateAssetName("AFDOrigin-"); FrontDoorOriginResource afdOriginInstance = await CreateAfdOrigin(afdOriginGroupInstance, afdOriginName); string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet"); FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName); string afdRouteName = Recording.GenerateAssetName("AFDRoute"); FrontDoorRouteResource afdRoute = await CreateAfdRoute(afdEndpointInstance, afdRouteName, afdOriginGroupInstance, afdRuleSet); FrontDoorRoutePatch updateOptions = new FrontDoorRoutePatch { EnabledState = EnabledState.Disabled }; var lro = await afdRoute.UpdateAsync(WaitUntil.Completed, updateOptions); FrontDoorRouteResource updatedAfdRoute = lro.Value; ResourceDataHelper.AssertAfdRouteUpdate(updatedAfdRoute, updateOptions); }
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 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 afdEndpointName = Recording.GenerateAssetName("AFDEndpoint-"); FrontDoorEndpointResource afdEndpointInstance = await CreateAfdEndpoint(afdProfileResource, afdEndpointName); string afdOriginGroupName = Recording.GenerateAssetName("AFDOriginGroup-"); FrontDoorOriginGroupResource afdOriginGroupInstance = await CreateAfdOriginGroup(afdProfileResource, afdOriginGroupName); string afdOriginName = Recording.GenerateAssetName("AFDOrigin-"); FrontDoorOriginResource afdOriginInstance = await CreateAfdOrigin(afdOriginGroupInstance, afdOriginName); string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet"); FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName); string afdRouteName = Recording.GenerateAssetName("AFDRoute"); FrontDoorRouteResource afdRoute = await CreateAfdRoute(afdEndpointInstance, afdRouteName, afdOriginGroupInstance, afdRuleSet); FrontDoorRouteResource getAfdRoute = await afdEndpointInstance.GetFrontDoorRoutes().GetAsync(afdRouteName); ResourceDataHelper.AssertValidAfdRoute(afdRoute, getAfdRoute); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdEndpointInstance.GetFrontDoorRoutes().GetAsync(null)); }
public async Task List() { 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 afdEndpointName = Recording.GenerateAssetName("AFDEndpoint-"); FrontDoorEndpointResource afdEndpointInstance = await CreateAfdEndpoint(afdProfileResource, afdEndpointName); string afdOriginGroupName = Recording.GenerateAssetName("AFDOriginGroup-"); FrontDoorOriginGroupResource afdOriginGroupInstance = await CreateAfdOriginGroup(afdProfileResource, afdOriginGroupName); string afdOriginName = Recording.GenerateAssetName("AFDOrigin-"); _ = await CreateAfdOrigin(afdOriginGroupInstance, afdOriginName); string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet"); FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName); string afdRouteName = Recording.GenerateAssetName("AFDRoute"); _ = await CreateAfdRoute(afdEndpointInstance, afdRouteName, afdOriginGroupInstance, afdRuleSet); int count = 0; await foreach (var tempRoute in afdEndpointInstance.GetFrontDoorRoutes().GetAllAsync()) { count++; } Assert.AreEqual(count, 1); }
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 afdEndpointName = Recording.GenerateAssetName("AFDEndpoint-"); FrontDoorEndpointResource afdEndpointInstance = await CreateAfdEndpoint(afdProfileResource, afdEndpointName); string afdOriginGroupName = Recording.GenerateAssetName("AFDOriginGroup-"); FrontDoorOriginGroupResource afdOriginGroupInstance = await CreateAfdOriginGroup(afdProfileResource, afdOriginGroupName); string afdOriginName = Recording.GenerateAssetName("AFDOrigin-"); _ = await CreateAfdOrigin(afdOriginGroupInstance, afdOriginName); string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet"); FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName); string afdRouteName = Recording.GenerateAssetName("AFDRoute"); FrontDoorRouteResource afdRoute = await CreateAfdRoute(afdEndpointInstance, afdRouteName, afdOriginGroupInstance, afdRuleSet); Assert.AreEqual(afdRouteName, afdRoute.Data.Name); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdEndpointInstance.GetFrontDoorRoutes().CreateOrUpdateAsync(WaitUntil.Completed, null, afdRoute.Data)); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdEndpointInstance.GetFrontDoorRoutes().CreateOrUpdateAsync(WaitUntil.Completed, afdRouteName, null)); }
public static void AssertValidAfdRuleSet(FrontDoorRuleSetResource model, FrontDoorRuleSetResource 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.ProvisioningState, getResult.Data.ProvisioningState); Assert.AreEqual(model.Data.DeploymentStatus, getResult.Data.DeploymentStatus); }
protected async Task <FrontDoorRuleResource> CreateAfdRule(FrontDoorRuleSetResource ruleSet, string ruleName) { FrontDoorRuleData input = ResourceDataHelper.CreateAfdRuleData(); DeliveryRuleCondition deliveryRuleCondition = ResourceDataHelper.CreateDeliveryRuleCondition(); DeliveryRuleAction deliveryRuleAction = ResourceDataHelper.CreateDeliveryRuleOperation(); input.Conditions.Add(deliveryRuleCondition); input.Actions.Add(deliveryRuleAction); var lro = await ruleSet.GetFrontDoorRules().CreateOrUpdateAsync(WaitUntil.Completed, ruleName, input); return(lro.Value); }
public async Task ListAfdRules() { #region Snippet:Managing_AfdRules_ListAllAzureFrontDoorRules // 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(); // With GetAllAsync(), we can get a list of the rule in the collection AsyncPageable <FrontDoorRuleResource> response = ruleCollection.GetAllAsync(); await foreach (FrontDoorRuleResource rule in response) { Console.WriteLine(rule.Data.Name); } #endregion Snippet:Managing_AfdRules_ListAllAzureFrontDoorRules }
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 GetResourceUsage() { 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); int count = 0; await foreach (var tempUsage in afdRuleSet.GetResourceUsagesAsync()) { count++; Assert.AreEqual(tempUsage.Unit, UsageUnit.Count); Assert.AreEqual(tempUsage.CurrentValue, 0); } Assert.AreEqual(count, 1); }
protected async Task <FrontDoorRouteResource> CreateAfdRoute(FrontDoorEndpointResource endpoint, string routeName, FrontDoorOriginGroupResource originGroup, FrontDoorRuleSetResource ruleSet) { FrontDoorRouteData input = ResourceDataHelper.CreateAfdRouteData(originGroup); input.RuleSets.Add(new WritableSubResource { Id = ruleSet.Id }); input.PatternsToMatch.Add("/*"); var lro = await endpoint.GetFrontDoorRoutes().CreateOrUpdateAsync(WaitUntil.Completed, routeName, input); return(lro.Value); }