private async Task <RouteFilterRuleResource> CreateDefaultRouteFilterRule(RouteFilterResource filter, string ruleName) { var rule = new RouteFilterRuleData() { Access = Access.Allow, Communities = { Filter_Commmunity }, Location = filter.Data.Location }; // Put route filter rule Operation <RouteFilterRuleResource> ruleOperation = await filter.GetRouteFilterRules().CreateOrUpdateAsync(WaitUntil.Completed, ruleName, rule); Response <RouteFilterRuleResource> ruleResponse = await ruleOperation.WaitForCompletionAsync(); return(ruleResponse); }
public async Task <ExpressRouteCircuitResource> UpdateDefaultExpressRouteCircuitWithMicrosoftPeering(string resourceGroupName, string circuitName, RouteFilterResource filter) { var peering = new ExpressRouteCircuitPeeringData() { Name = ExpressRoutePeeringType.MicrosoftPeering.ToString(), PeeringType = ExpressRoutePeeringType.MicrosoftPeering, PeerASN = Convert.ToInt32(ExpressRouteTests.MS_PeerASN), PrimaryPeerAddressPrefix = ExpressRouteTests.MS_PrimaryPrefix, SecondaryPeerAddressPrefix = ExpressRouteTests.MS_SecondaryPrefix, VlanId = Convert.ToInt32(ExpressRouteTests.MS_VlanId), MicrosoftPeeringConfig = new ExpressRouteCircuitPeeringConfig() { AdvertisedPublicPrefixes = { ExpressRouteTests.MS_PublicPrefix }, LegacyMode = Convert.ToInt32(true) }, RouteFilter = { Id = filter.Id } }; Operation <ExpressRouteCircuitPeeringResource> peerOperation = await GetResourceGroup(resourceGroupName).GetExpressRouteCircuits().Get(circuitName).Value.GetExpressRouteCircuitPeerings().CreateOrUpdateAsync(WaitUntil.Completed, ExpressRouteTests.Peering_Microsoft, peering); Response <ExpressRouteCircuitPeeringResource> peerResponse = await peerOperation.WaitForCompletionAsync(); Assert.AreEqual("Succeeded", peerResponse.Value.Data.ProvisioningState.ToString()); Response <ExpressRouteCircuitResource> getCircuitResponse = await GetResourceGroup(resourceGroupName).GetExpressRouteCircuits().GetAsync(circuitName); return(getCircuitResponse); }
public async Task RouteFilterApiTest() { SubscriptionResource subscription = await ArmClient.GetDefaultSubscriptionAsync(); var filterCollection = await GetCollection(); // Create route filter string filterName = Recording.GenerateAssetName("filter"); string ruleName = Recording.GenerateAssetName("rule"); RouteFilterResource filter = await CreateDefaultRouteFilter(filterCollection, filterName); Assert.AreEqual("Succeeded", filter.Data.ProvisioningState.ToString()); Assert.AreEqual(filterName, filter.Data.Name); Assert.IsEmpty(filter.Data.Rules); var filters = await filterCollection.GetAllAsync().ToEnumerableAsync(); Has.One.Equals(filters); Assert.AreEqual(filterName, filters[0].Data.Name); Assert.IsEmpty(filters[0].Data.Rules); var allFilters = await subscription.GetRouteFiltersAsync().ToEnumerableAsync(); // there could be other filters in the current subscription Assert.True(allFilters.Any(f => filterName == f.Data.Name && f.Data.Rules.Count == 0)); // Crete route filter rule RouteFilterRuleResource filterRule = await CreateDefaultRouteFilterRule(filter, ruleName); Assert.AreEqual("Succeeded", filterRule.Data.ProvisioningState.ToString()); Assert.AreEqual(ruleName, filterRule.Data.Name); Response <RouteFilterResource> getFilterResponse = await filterCollection.GetAsync(filterName); Assert.AreEqual(filterName, getFilterResponse.Value.Data.Name); filter = await filterCollection.GetAsync(filterName); Assert.AreEqual(filterName, filter.Data.Name); Has.One.Equals(filter.Data.Rules); Assert.AreEqual(ruleName, filter.Data.Rules[0].Name); filterRule = await filter.GetRouteFilterRules().GetAsync(ruleName); Assert.AreEqual(ruleName, filterRule.Data.Name); // Update route filter filterRule.Data.Access = Access.Deny; var operation = InstrumentOperation(await filter.GetRouteFilterRules().CreateOrUpdateAsync(WaitUntil.Completed, ruleName, filterRule.Data)); await operation.WaitForCompletionAsync(); Assert.AreEqual(ruleName, filterRule.Data.Name); Assert.AreEqual(Access.Deny, filterRule.Data.Access); // Add filter rule, this will fail due to the limitation of maximum 1 rule per filter Assert.ThrowsAsync <RequestFailedException>(async() => await CreateDefaultRouteFilterRule(filter, Recording.GenerateAssetName("rule2"))); filter = await filterCollection.GetAsync(filterName); Has.One.Equals(filter.Data.Rules); Assert.AreEqual(ruleName, filter.Data.Rules[0].Name); // Delete fileter rule await filterRule.DeleteAsync(WaitUntil.Completed); var rules = await filter.GetRouteFilterRules().GetAllAsync().ToEnumerableAsync(); Assert.IsEmpty(rules); // Delete filter await filter.DeleteAsync(WaitUntil.Completed); allFilters = await subscription.GetRouteFiltersAsync().ToEnumerableAsync(); Assert.False(allFilters.Any(f => filter.Id == f.Id)); }