public async Task GetAllNamespaces() { //create two namespaces string namespaceName1 = await CreateValidNamespaceName("testnamespacemgmt1"); string namespaceName2 = await CreateValidNamespaceName("testnamespacemgmt2"); _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); _ = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, new EventHubNamespaceData(DefaultLocation))).Value; _ = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new EventHubNamespaceData(DefaultLocation))).Value; int count = 0; EventHubNamespaceResource namespace1 = null; EventHubNamespaceResource namespace2 = null; //validate await foreach (EventHubNamespaceResource eventHubNamespace in namespaceCollection.GetAllAsync()) { count++; if (eventHubNamespace.Id.Name == namespaceName1) { namespace1 = eventHubNamespace; } if (eventHubNamespace.Id.Name == namespaceName2) { namespace2 = eventHubNamespace; } } Assert.AreEqual(count, 2); VerifyNamespaceProperties(namespace1, true); VerifyNamespaceProperties(namespace2, true); }
public async Task CreateDeleteNamespace() { //create namespace and wait for completion string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; VerifyNamespaceProperties(eventHubNamespace, true); //validate if created successfully eventHubNamespace = await namespaceCollection.GetAsync(namespaceName); Assert.IsTrue(await namespaceCollection.ExistsAsync(namespaceName)); VerifyNamespaceProperties(eventHubNamespace, true); //delete namespace await eventHubNamespace.DeleteAsync(true); //validate if deleted successfully eventHubNamespace = await namespaceCollection.GetIfExistsAsync(namespaceName); Assert.IsNull(eventHubNamespace); Assert.IsFalse(await namespaceCollection.ExistsAsync(namespaceName)); }
public async Task UpdateNamespace() { //create namespace string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespaceResource eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; VerifyNamespaceProperties(eventHubNamespace, true); //update namespace var updateNamespaceParameter = eventHubNamespace.Data; updateNamespaceParameter.Tags.Add("key1", "value1"); updateNamespaceParameter.Tags.Add("key2", "value2"); eventHubNamespace = await eventHubNamespace.UpdateAsync(updateNamespaceParameter); //validate Assert.AreEqual(eventHubNamespace.Data.Tags.Count, 2); Assert.AreEqual("value1", eventHubNamespace.Data.Tags["key1"]); Assert.AreEqual("value2", eventHubNamespace.Data.Tags["key2"]); //wait until provision state is succeeded await GetSucceededNamespace(eventHubNamespace); }
public async Task AddSetRemoveTag() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceResource eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; //add a tag eventHubNamespace = await eventHubNamespace.AddTagAsync("key", "value"); Assert.AreEqual(eventHubNamespace.Data.Tags.Count, 1); Assert.AreEqual(eventHubNamespace.Data.Tags["key"], "value"); //set the tag eventHubNamespace.Data.Tags.Add("key1", "value1"); eventHubNamespace = await eventHubNamespace.SetTagsAsync(eventHubNamespace.Data.Tags); Assert.AreEqual(eventHubNamespace.Data.Tags.Count, 2); Assert.AreEqual(eventHubNamespace.Data.Tags["key1"], "value1"); //remove a tag eventHubNamespace = await eventHubNamespace.RemoveTagAsync("key"); Assert.AreEqual(eventHubNamespace.Data.Tags.Count, 1); //wait until provision state is succeeded await GetSucceededNamespace(eventHubNamespace); }
public async Task CreateDeleteNamespace() { //create namespace and wait for completion string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespaceResource eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; VerifyNamespaceProperties(eventHubNamespace, true); //validate if created successfully eventHubNamespace = await namespaceCollection.GetAsync(namespaceName); Assert.IsTrue(await namespaceCollection.ExistsAsync(namespaceName)); VerifyNamespaceProperties(eventHubNamespace, true); //delete namespace await eventHubNamespace.DeleteAsync(WaitUntil.Completed); //validate if deleted successfully var exception = Assert.ThrowsAsync <RequestFailedException>(async() => { await namespaceCollection.GetAsync(namespaceName); }); Assert.AreEqual(404, exception.Status); Assert.IsFalse(await namespaceCollection.ExistsAsync(namespaceName)); }
public async Task CreateOrUpdate() { #region Snippet:Managing_Namespaces_CreateNamespace string namespaceName = "myNamespace"; EventHubNamespaceCollection namespaceCollection = resourceGroup.GetEventHubNamespaces(); AzureLocation location = AzureLocation.EastUS2; EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, new EventHubNamespaceData(location))).Value; #endregion }
public async Task CreateNamespaceAndGetEventhubCollection() { _resourceGroup = await CreateResourceGroupAsync(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespaceResource eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; _eventHubCollection = eventHubNamespace.GetEventHubs(); }
public async Task CreateNamespaceAndGetEventhubCollection() { _resourceGroup = await CreateResourceGroupAsync(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespace eHNamespace = (await namespaceCollection.CreateOrUpdateAsync(true, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; _schemaGroupCollection = eHNamespace.GetSchemaGroups(); }
public async Task CreateNamespaceAndGetEventhubCollection() { _resourceGroup = await CreateResourceGroupAsync(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespaceResource eHNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; EventHubCollection eventhubCollection = eHNamespace.GetEventHubs(); string eventhubName = Recording.GenerateAssetName("eventhub"); _eventHub = (await eventhubCollection.CreateOrUpdateAsync(WaitUntil.Completed, eventhubName, new EventHubData())).Value; _consumerGroupCollection = _eventHub.GetConsumerGroups(); }
public async Task GetPrivateLinkResources() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; //get private link resource IReadOnlyList <PrivateLinkResource> privateLinkResources = (await eventHubNamespace.GetPrivateLinkResourcesAsync()).Value; Assert.NotNull(privateLinkResources); }
public async Task CreateNamespaceWithKafkaEnabled() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceData parameter = new EventHubNamespaceData(DefaultLocation) { KafkaEnabled = true }; EventHubNamespaceResource eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; VerifyNamespaceProperties(eventHubNamespace, false); Assert.IsTrue(eventHubNamespace.Data.KafkaEnabled); }
public async Task GetPrivateLinkResources() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceResource eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; //get private link resource await foreach (var _ in eventHubNamespace.GetPrivateLinkResourcesAsync()) { return; } Assert.Fail($"{nameof(EventHubNamespaceResource)}.{nameof(EventHubNamespaceResource.GetPrivateLinkResourcesAsync)} has returned an empty collection of {nameof(PrivateLinkResource)}."); }
public async Task NamespaceAuthorizationRuleRegenerateKey() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceResource eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; NamespaceAuthorizationRuleCollection ruleCollection = eventHubNamespace.GetNamespaceAuthorizationRules(); //create authorization rule string ruleName = Recording.GenerateAssetName("authorizationrule"); AuthorizationRuleData parameter = new AuthorizationRuleData() { Rights = { AccessRights.Listen, AccessRights.Send } }; NamespaceAuthorizationRuleResource authorizationRule = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, parameter)).Value; Assert.NotNull(authorizationRule); Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count); AccessKeys keys1 = await authorizationRule.GetKeysAsync(); Assert.NotNull(keys1); Assert.NotNull(keys1.PrimaryConnectionString); Assert.NotNull(keys1.SecondaryConnectionString); AccessKeys keys2 = await authorizationRule.RegenerateKeysAsync(new RegenerateAccessKeyOptions(KeyType.PrimaryKey)); if (Mode != RecordedTestMode.Playback) { Assert.AreNotEqual(keys1.PrimaryKey, keys2.PrimaryKey); Assert.AreEqual(keys1.SecondaryKey, keys2.SecondaryKey); } AccessKeys keys3 = await authorizationRule.RegenerateKeysAsync(new RegenerateAccessKeyOptions(KeyType.SecondaryKey)); if (Mode != RecordedTestMode.Playback) { Assert.AreEqual(keys2.PrimaryKey, keys3.PrimaryKey); Assert.AreNotEqual(keys2.SecondaryKey, keys3.SecondaryKey); } }
public async Task GetNamespacesInSubscription() { //create two namespaces in two resourcegroups string namespaceName1 = await CreateValidNamespaceName("testnamespacemgmt1"); string namespaceName2 = await CreateValidNamespaceName("testnamespacemgmt2"); _resourceGroup = await CreateResourceGroupAsync(); ResourceGroupResource resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection1 = _resourceGroup.GetEventHubNamespaces(); EventHubNamespaceCollection namespaceCollection2 = resourceGroup.GetEventHubNamespaces(); _ = (await namespaceCollection1.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, new EventHubNamespaceData(DefaultLocation))).Value; _ = (await namespaceCollection2.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new EventHubNamespaceData(DefaultLocation))).Value; int count = 0; EventHubNamespaceResource namespace1 = null; EventHubNamespaceResource namespace2 = null; //validate await foreach (EventHubNamespaceResource eventHubNamespace in DefaultSubscription.GetEventHubNamespacesAsync()) { count++; if (eventHubNamespace.Id.Name == namespaceName1) { namespace1 = eventHubNamespace; } if (eventHubNamespace.Id.Name == namespaceName2) { namespace2 = eventHubNamespace; } } VerifyNamespaceProperties(namespace1, true); VerifyNamespaceProperties(namespace2, true); Assert.AreEqual(namespace1.Id.ResourceGroupName, _resourceGroup.Id.Name); Assert.AreEqual(namespace2.Id.ResourceGroupName, resourceGroup.Id.Name); await namespace2.DeleteAsync(WaitUntil.Completed); }
public async Task CreateNamespace() { #region Snippet:Managing_EventHubs_DefaultSubscription ArmClient armClient = new ArmClient(new DefaultAzureCredential()); Subscription subscription = await armClient.GetDefaultSubscriptionAsync(); #endregion #region Snippet:Managing_EventHubs_CreateResourceGroup string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation <ResourceGroup> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location)); ResourceGroup resourceGroup = operation.Value; #endregion #region Snippet:Managing_EventHubs_CreateNamespace string namespaceName = "myNamespace"; EventHubNamespaceCollection namespaceCollection = resourceGroup.GetEventHubNamespaces(); EventHubNamespace eHNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(location))).Value; EventHubCollection eventHubCollection = eHNamespace.GetEventHubs(); #endregion this.eventHubCollection = eventHubCollection; }
public async Task CreateGetUpdateDeleteDisasterRecovery() { _resourceGroup = await CreateResourceGroupAsync(); //create namespace1 string namespaceName1 = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespaceResource eHNamespace1 = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, new EventHubNamespaceData(DefaultLocation))).Value; //create namespace2 with a different location string namespaceName2 = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceResource eHNamespace2 = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new EventHubNamespaceData(AzureLocation.EastUS))).Value; //create authorization rule on namespace1 string ruleName = Recording.GenerateAssetName("authorizationrule"); AuthorizationRuleData ruleParameter = new AuthorizationRuleData() { Rights = { AccessRights.Listen, AccessRights.Send } }; NamespaceAuthorizationRuleResource authorizationRule = (await eHNamespace1.GetNamespaceAuthorizationRules().CreateOrUpdateAsync(WaitUntil.Completed, ruleName, ruleParameter)).Value; Assert.NotNull(authorizationRule); Assert.AreEqual(authorizationRule.Data.Rights.Count, ruleParameter.Rights.Count); //create a disaster recovery string disasterRecoveryName = Recording.GenerateAssetName("disasterrecovery"); DisasterRecoveryData parameter = new DisasterRecoveryData() { PartnerNamespace = eHNamespace2.Id }; DisasterRecoveryResource armDisasterRecovery = (await eHNamespace1.GetDisasterRecoveries().CreateOrUpdateAsync(WaitUntil.Completed, disasterRecoveryName, parameter)).Value; Assert.NotNull(armDisasterRecovery); Assert.AreEqual(armDisasterRecovery.Id.Name, disasterRecoveryName); Assert.AreEqual(armDisasterRecovery.Data.PartnerNamespace, eHNamespace2.Id.ToString()); //get the disaster recovery - primary armDisasterRecovery = await eHNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); Assert.AreEqual(armDisasterRecovery.Data.Role, RoleDisasterRecovery.Primary); //get the disaster recovery - secondary DisasterRecoveryResource armDisasterRecoverySec = await eHNamespace2.GetDisasterRecoveries().GetAsync(disasterRecoveryName); Assert.AreEqual(armDisasterRecoverySec.Data.Role, RoleDisasterRecovery.Secondary); //wait for completion, this may take several minutes in live and record mode armDisasterRecovery = await eHNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); int i = 0; while (armDisasterRecovery.Data.ProvisioningState != ProvisioningStateDisasterRecovery.Succeeded && i < 100) { if (Mode != RecordedTestMode.Playback) { await Task.Delay(5000); } i++; armDisasterRecovery = await eHNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); } System.Console.WriteLine(i); //check name availability CheckNameAvailabilityResult nameAvailability = await eHNamespace1.CheckDisasterRecoveryNameAvailabilityAsync(new CheckNameAvailabilityOptions(disasterRecoveryName)); Assert.IsFalse(nameAvailability.NameAvailable); List <DisasterRecoveryAuthorizationRuleResource> rules = await armDisasterRecovery.GetDisasterRecoveryAuthorizationRules().GetAllAsync().ToEnumerableAsync(); Assert.IsTrue(rules.Count > 0); //get access keys of the authorization rule DisasterRecoveryAuthorizationRuleResource rule = rules.First(); AccessKeys keys = await rule.GetKeysAsync(); Assert.NotNull(keys); //break pairing and wait for completion await armDisasterRecovery.BreakPairingAsync(); armDisasterRecovery = await eHNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); i = 0; while (armDisasterRecovery.Data.ProvisioningState != ProvisioningStateDisasterRecovery.Succeeded && i < 100) { if (Mode != RecordedTestMode.Playback) { await Task.Delay(5000); } i++; armDisasterRecovery = await eHNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); } //get all disaster recoveries for a name space List <DisasterRecoveryResource> disasterRcoveries = await eHNamespace1.GetDisasterRecoveries().GetAllAsync().ToEnumerableAsync(); Assert.IsTrue(disasterRcoveries.Count >= 1); //delete disaster recovery; await armDisasterRecovery.DeleteAsync(WaitUntil.Completed); }
public async Task NamespaceCreateGetUpdateDeleteAuthorizationRule() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceResource eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; NamespaceAuthorizationRuleCollection ruleCollection = eventHubNamespace.GetNamespaceAuthorizationRules(); //create authorization rule string ruleName = Recording.GenerateAssetName("authorizationrule"); AuthorizationRuleData parameter = new AuthorizationRuleData() { Rights = { AccessRights.Listen, AccessRights.Send } }; NamespaceAuthorizationRuleResource authorizationRule = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, parameter)).Value; Assert.NotNull(authorizationRule); Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count); //get authorization rule authorizationRule = await ruleCollection.GetAsync(ruleName); Assert.AreEqual(authorizationRule.Id.Name, ruleName); Assert.NotNull(authorizationRule); Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count); //get all authorization rules List <NamespaceAuthorizationRuleResource> rules = await ruleCollection.GetAllAsync().ToEnumerableAsync(); //there should be two authorization rules Assert.True(rules.Count > 1); bool isContainAuthorizationRuleName = false; bool isContainDefaultRuleName = false; foreach (NamespaceAuthorizationRuleResource rule in rules) { if (rule.Id.Name == ruleName) { isContainAuthorizationRuleName = true; } if (rule.Id.Name == DefaultNamespaceAuthorizationRule) { isContainDefaultRuleName = true; } } Assert.True(isContainDefaultRuleName); Assert.True(isContainAuthorizationRuleName); //update authorization rule parameter.Rights.Add(AccessRights.Manage); authorizationRule = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, parameter)).Value; Assert.NotNull(authorizationRule); Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count); //delete authorization rule await authorizationRule.DeleteAsync(WaitUntil.Completed); //validate if deleted Assert.IsFalse(await ruleCollection.ExistsAsync(ruleName)); rules = await ruleCollection.GetAllAsync().ToEnumerableAsync(); Assert.True(rules.Count == 1); Assert.AreEqual(rules[0].Id.Name, DefaultNamespaceAuthorizationRule); }
public async Task SetGetNetworkRuleSets() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceResource eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; //prepare vnet string vnetName = Recording.GenerateAssetName("sdktestvnet"); var parameters = new VirtualNetworkData { Subnets = { new SubnetData { Name = "default1", AddressPrefix = "10.0.0.0/24", ServiceEndpoints ={ new ServiceEndpointPropertiesFormat { Service = "Microsoft.EventHub" } } }, new SubnetData { Name = "default2", AddressPrefix = "10.0.1.0/24", ServiceEndpoints ={ new ServiceEndpointPropertiesFormat { Service = "Microsoft.EventHub" } } }, new SubnetData { Name = "default3", AddressPrefix = "10.0.2.0/24", ServiceEndpoints ={ new ServiceEndpointPropertiesFormat { Service = "Microsoft.EventHub" } } } }, Location = "eastus2" }; parameters.AddressPrefixes.Add("10.0.0.0/16"); VirtualNetworkResource virtualNetwork = (await _resourceGroup.GetVirtualNetworks().CreateOrUpdateAsync(WaitUntil.Completed, vnetName, parameters)).Value; //set network rule set string subscriptionId = DefaultSubscription.Id.ToString(); ResourceIdentifier subnetId1 = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default1"); ResourceIdentifier subnetId2 = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default2"); ResourceIdentifier subnetId3 = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default3"); NetworkRuleSetData parameter = new NetworkRuleSetData() { DefaultAction = DefaultAction.Deny, VirtualNetworkRules = { new NetworkRuleSetVirtualNetworkRules() { Subnet = new WritableSubResource() { Id = subnetId1 } }, new NetworkRuleSetVirtualNetworkRules() { Subnet = new WritableSubResource() { Id = subnetId2 } }, new NetworkRuleSetVirtualNetworkRules() { Subnet = new WritableSubResource() { Id = subnetId3 } } }, IPRules = { new NetworkRuleSetIPRules() { IPMask = "1.1.1.1", Action = "Allow" }, new NetworkRuleSetIPRules() { IPMask = "1.1.1.2", Action = "Allow" }, new NetworkRuleSetIPRules() { IPMask = "1.1.1.3", Action = "Allow" }, new NetworkRuleSetIPRules() { IPMask = "1.1.1.4", Action = "Allow" }, new NetworkRuleSetIPRules() { IPMask = "1.1.1.5", Action = "Allow" } } }; await eventHubNamespace.GetNetworkRuleSet().CreateOrUpdateAsync(WaitUntil.Completed, parameter); //get the network rule set NetworkRuleSetResource networkRuleSet = await eventHubNamespace.GetNetworkRuleSet().GetAsync(); Assert.NotNull(networkRuleSet); Assert.NotNull(networkRuleSet.Data.IPRules); Assert.NotNull(networkRuleSet.Data.VirtualNetworkRules); Assert.AreEqual(networkRuleSet.Data.VirtualNetworkRules.Count, 3); Assert.AreEqual(networkRuleSet.Data.IPRules.Count, 5); //delete virtual network await virtualNetwork.DeleteAsync(WaitUntil.Completed); }