public async Task CreateDeleteNamespace() { IgnoreTestInLiveMode(); //create namespace and wait for completion string namespaceName = await CreateValidNamespaceName(namespacePrefix); _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value; VerifyNamespaceProperties(serviceBusNamespace, true); //validate if created successfully serviceBusNamespace = await namespaceCollection.GetAsync(namespaceName); Assert.IsTrue(await namespaceCollection.ExistsAsync(namespaceName)); VerifyNamespaceProperties(serviceBusNamespace, true); //delete namespace await serviceBusNamespace.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 UpdateNamespace() { IgnoreTestInLiveMode(); //create namespace string namespaceName = await CreateValidNamespaceName(namespacePrefix); _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value; VerifyNamespaceProperties(serviceBusNamespace, true); //update namespace ServiceBusNamespacePatch parameters = new ServiceBusNamespacePatch(DefaultLocation); parameters.Tags.Add("key1", "value1"); parameters.Tags.Add("key2", "value2"); serviceBusNamespace = await serviceBusNamespace.UpdateAsync(parameters); //validate Assert.AreEqual(serviceBusNamespace.Data.Tags.Count, 2); Assert.AreEqual("value1", serviceBusNamespace.Data.Tags["key1"]); Assert.AreEqual("value2", serviceBusNamespace.Data.Tags["key2"]); //wait until provision state is succeeded await GetSucceededNamespace(serviceBusNamespace); }
public async Task GetAllNamespaces() { IgnoreTestInLiveMode(); //create two namespaces _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); string namespaceName1 = await CreateValidNamespaceName(namespacePrefix); _ = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, new ServiceBusNamespaceData(DefaultLocation))).Value; string namespaceName2 = await CreateValidNamespaceName(namespacePrefix); _ = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new ServiceBusNamespaceData(DefaultLocation))).Value; int count = 0; ServiceBusNamespaceResource namespace1 = null; ServiceBusNamespaceResource namespace2 = null; //validate await foreach (ServiceBusNamespaceResource serviceBusNamespace in namespaceCollection.GetAllAsync()) { count++; if (serviceBusNamespace.Id.Name == namespaceName1) { namespace1 = serviceBusNamespace; } if (serviceBusNamespace.Id.Name == namespaceName2) { namespace2 = serviceBusNamespace; } } Assert.AreEqual(count, 2); VerifyNamespaceProperties(namespace1, true); VerifyNamespaceProperties(namespace2, true); }
public async Task Get() { #region Snippet:Managing_ServiceBusNamespaces_GetNamespace ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceResource serviceBusNamespace = await namespaceCollection.GetAsync("myNamespace"); Console.WriteLine(serviceBusNamespace.Id.Name); #endregion }
public async Task CreateOrUpdate() { #region Snippet:Managing_ServiceBusNamespaces_CreateNamespace string namespaceName = "myNamespace"; ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces(); AzureLocation location = AzureLocation.EastUS2; ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(location))).Value; #endregion }
public async Task Delete() { #region Snippet:Managing_ServiceBusNamespaces_DeleteNamespace ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceResource serviceBusNamespace = await namespaceCollection.GetAsync("myNamespace"); await serviceBusNamespace.DeleteAsync(WaitUntil.Completed); #endregion }
public static void VerifyNamespaceProperties(ServiceBusNamespaceResource sBNamespace, bool useDefaults) { Assert.NotNull(sBNamespace); Assert.NotNull(sBNamespace.Id); Assert.NotNull(sBNamespace.Id.Name); Assert.NotNull(sBNamespace.Data); Assert.NotNull(sBNamespace.Data.Location); Assert.NotNull(sBNamespace.Data.CreatedOn); Assert.NotNull(sBNamespace.Data.Sku); if (useDefaults) { Assert.AreEqual(DefaultLocation, sBNamespace.Data.Location); Assert.AreEqual(ServiceBusSkuTier.Standard, sBNamespace.Data.Sku.Tier); } }
public async Task CreateGetDeletePrivateEndPointConnection() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); string namespaceName = await CreateValidNamespaceName(namespacePrefix); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value; ServiceBusPrivateEndpointConnectionCollection privateEndpointConnectionCollection = serviceBusNamespace.GetServiceBusPrivateEndpointConnections(); //create another namespace for connection string namespaceName2 = await CreateValidNamespaceName(namespacePrefix); ServiceBusNamespaceResource serviceBusNamespace2 = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new ServiceBusNamespaceData(DefaultLocation))).Value; //create an endpoint connection string connectionName = Recording.GenerateAssetName("endpointconnection"); ServiceBusPrivateEndpointConnectionData parameter = new ServiceBusPrivateEndpointConnectionData() { PrivateEndpoint = new WritableSubResource() { Id = serviceBusNamespace2.Id } }; ServiceBusPrivateEndpointConnectionResource privateEndpointConnection = (await privateEndpointConnectionCollection.CreateOrUpdateAsync(WaitUntil.Completed, connectionName, parameter)).Value; Assert.NotNull(privateEndpointConnection); Assert.AreEqual(privateEndpointConnection.Data.PrivateEndpoint.Id, serviceBusNamespace2.Id.ToString()); connectionName = privateEndpointConnection.Id.Name; //get the endpoint connection and validate privateEndpointConnection = await privateEndpointConnectionCollection.GetAsync(connectionName); Assert.NotNull(privateEndpointConnection); Assert.AreEqual(privateEndpointConnection.Data.PrivateEndpoint.Id, serviceBusNamespace2.Id.ToString()); //get all endpoint connections and validate List <ServiceBusPrivateEndpointConnectionResource> privateEndpointConnections = await privateEndpointConnectionCollection.GetAllAsync().ToEnumerableAsync(); Assert.AreEqual(privateEndpointConnections, 1); Assert.AreEqual(privateEndpointConnections.First().Data.PrivateEndpoint.Id, serviceBusNamespace2.Id.ToString()); //delete endpoint connection and validate await privateEndpointConnection.DeleteAsync(WaitUntil.Completed); Assert.IsFalse(await privateEndpointConnectionCollection.ExistsAsync(connectionName)); }
public async Task GetPrivateLinkResources() { IgnoreTestInLiveMode(); //create namespace _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); string namespaceName = await CreateValidNamespaceName(namespacePrefix); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value; //get private link resource await foreach (var _ in serviceBusNamespace.GetPrivateLinkResourcesAsync()) { return; } }
public async Task NamespaceAuthorizationRuleRegenerateKey() { IgnoreTestInLiveMode(); //create namespace _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); string namespaceName = await CreateValidNamespaceName(namespacePrefix); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value; NamespaceAuthorizationRuleCollection ruleCollection = serviceBusNamespace.GetNamespaceAuthorizationRules(); //create authorization rule string ruleName = Recording.GenerateAssetName("authorizationrule"); ServiceBusAuthorizationRuleData parameter = new ServiceBusAuthorizationRuleData() { 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 <ServiceBusNamespaceResource> GetSucceededNamespace(ServiceBusNamespaceResource serviceBusNamespace) { int i = 0; serviceBusNamespace = await serviceBusNamespace.GetAsync(); while (!serviceBusNamespace.Data.ProvisioningState.Equals("Succeeded") && i < 100) { if (Mode != RecordedTestMode.Playback) { await Task.Delay(10000); } serviceBusNamespace = await serviceBusNamespace.GetAsync(); i++; } return(serviceBusNamespace); }
public async Task CreateNamespaceAndGetQueueCollection() { IgnoreTestInLiveMode(); _resourceGroup = await CreateResourceGroupAsync(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceData parameters = new ServiceBusNamespaceData(DefaultLocation) { Sku = new ServiceBusSku(ServiceBusSkuName.Premium) { Tier = ServiceBusSkuTier.Premium } }; ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, parameters)).Value; _queueCollection = serviceBusNamespace.GetServiceBusQueues(); }
public async Task createNamespace() { #region Snippet:Managing_ServiceBusQueues_DefaultSubscription ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); #endregion #region Snippet:Managing_ServiceBusQueues_CreateResourceGroup string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation <ResourceGroupResource> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location)); ResourceGroupResource resourceGroup = operation.Value; #endregion #region Snippet:Managing_ServiceBusQueues_CreateNamespace string namespaceName = "myNamespace"; ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(location))).Value; ServiceBusQueueCollection serviceBusQueueCollection = serviceBusNamespace.GetServiceBusQueues(); #endregion this.serviceBusQueueCollection = serviceBusQueueCollection; }
public async Task CreateNamespaceWithZoneRedundant() { IgnoreTestInLiveMode(); //create namespace and wait for completion string namespaceName = await CreateValidNamespaceName(namespacePrefix); _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); var parameters = new ServiceBusNamespaceData(DefaultLocation) { Sku = new ServiceBusSku(ServiceBusSkuName.Premium) { Tier = ServiceBusSkuTier.Premium }, ZoneRedundant = true }; ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, parameters)).Value; VerifyNamespaceProperties(serviceBusNamespace, false); Assert.IsTrue(serviceBusNamespace.Data.ZoneRedundant); }
public async Task GetNamespacesInSubscription() { IgnoreTestInLiveMode(); //create two namespaces in two resourcegroups string namespaceName1 = await CreateValidNamespaceName(namespacePrefix); _resourceGroup = await CreateResourceGroupAsync(); ResourceGroupResource resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection1 = _resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceCollection namespaceCollection2 = resourceGroup.GetServiceBusNamespaces(); _ = (await namespaceCollection1.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, new ServiceBusNamespaceData(DefaultLocation))).Value; string namespaceName2 = await CreateValidNamespaceName(namespacePrefix); _ = (await namespaceCollection2.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new ServiceBusNamespaceData(DefaultLocation))).Value; int count = 0; ServiceBusNamespaceResource namespace1 = null; ServiceBusNamespaceResource namespace2 = null; //validate await foreach (ServiceBusNamespaceResource serviceBusNamespace in DefaultSubscription.GetServiceBusNamespacesAsync()) { count++; if (serviceBusNamespace.Id.Name == namespaceName1) { namespace1 = serviceBusNamespace; } if (serviceBusNamespace.Id.Name == namespaceName2) { namespace2 = serviceBusNamespace; } } VerifyNamespaceProperties(namespace1, true); VerifyNamespaceProperties(namespace2, true); Assert.AreEqual(namespace1.Id.ResourceGroupName, _resourceGroup.Id.Name); Assert.AreEqual(namespace2.Id.ResourceGroupName, resourceGroup.Id.Name); }
public async Task CreateGetUpdateDeleteRule() { IgnoreTestInLiveMode(); const string strSqlExp = "myproperty=test"; //create namespace ResourceGroupResource resourceGroup = await CreateResourceGroupAsync(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value; //create a topic ServiceBusTopicCollection topicCollection = serviceBusNamespace.GetServiceBusTopics(); string topicName = Recording.GenerateAssetName("topic"); ServiceBusTopicResource topic = (await topicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName, new ServiceBusTopicData())).Value; Assert.NotNull(topic); Assert.AreEqual(topic.Id.Name, topicName); //create a subscription ServiceBusSubscriptionCollection serviceBusSubscriptionCollection = topic.GetServiceBusSubscriptions(); string subscriptionName = Recording.GenerateAssetName("subscription"); ServiceBusSubscriptionData parameters = new ServiceBusSubscriptionData(); ServiceBusSubscriptionResource serviceBusSubscription = (await serviceBusSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionName, parameters)).Value; Assert.NotNull(serviceBusSubscription); Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName); //create rule with no filters string ruleName1 = Recording.GenerateAssetName("rule"); ServiceBusRuleCollection ruleCollection = serviceBusSubscription.GetServiceBusRules(); ServiceBusRuleResource rule1 = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName1, new ServiceBusRuleData())).Value; Assert.NotNull(rule1); Assert.AreEqual(rule1.Id.Name, ruleName1); //create rule with correlation filter string ruleName2 = Recording.GenerateAssetName("rule"); ServiceBusRuleResource rule2 = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName2, new ServiceBusRuleData() { FilterType = FilterType.CorrelationFilter })).Value; Assert.NotNull(rule2); Assert.AreEqual(rule2.Id.Name, ruleName2); //get created rules rule1 = await ruleCollection.GetAsync(ruleName1); Assert.NotNull(rule1); Assert.AreEqual(rule1.Id.Name, ruleName1); //get all rules List <ServiceBusRuleResource> rules = await ruleCollection.GetAllAsync().ToEnumerableAsync(); Assert.AreEqual(2, rules.Count); //update rule with sql filter and action ServiceBusRuleData updateParameters = new ServiceBusRuleData() { Action = new FilterAction() { RequiresPreprocessing = true, SqlExpression = "SET " + strSqlExp, }, SqlFilter = new SqlFilter() { SqlExpression = strSqlExp }, FilterType = FilterType.SqlFilter, CorrelationFilter = new CorrelationFilter() }; rule1 = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName1, updateParameters)).Value; await rule1.DeleteAsync(WaitUntil.Completed); await rule2.DeleteAsync(WaitUntil.Completed); }
public async Task StandardToPremiumMigration() { IgnoreTestInLiveMode(); //create namespace with premium _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); string namespaceName1 = await CreateValidNamespaceName(namespacePrefix); ServiceBusNamespaceData createParameters1 = new ServiceBusNamespaceData(DefaultLocation); createParameters1.Sku = new ServiceBusSku(ServiceBusSkuName.Premium) { Tier = ServiceBusSkuTier.Premium }; ServiceBusNamespaceResource serviceBusNamespace1 = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, createParameters1)).Value; //create namespace with standard string namespaceName2 = await CreateValidNamespaceName(namespacePrefix); ServiceBusNamespaceData createParameters2 = new ServiceBusNamespaceData(AzureLocation.EastUS); createParameters2.Sku = new ServiceBusSku(ServiceBusSkuName.Standard) { Tier = ServiceBusSkuTier.Standard }; ServiceBusNamespaceResource serviceBusNamespace2 = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, createParameters2)).Value; //add 10 queues to standard namespace for (int i = 0; i < 10; i++) { string queueName = Recording.GenerateAssetName("queue" + i); _ = await serviceBusNamespace2.GetServiceBusQueues().CreateOrUpdateAsync(WaitUntil.Completed, queueName, new ServiceBusQueueData()); } //add 10 topics to standard namespace for (int i = 0; i < 10; i++) { string topicName = Recording.GenerateAssetName("topic" + i); _ = await serviceBusNamespace2.GetServiceBusTopics().CreateOrUpdateAsync(WaitUntil.Completed, topicName, new ServiceBusTopicData()); } //create the migration config, it's name should always be $default string postMigrationName = Recording.GenerateAssetName("postmigration"); var migrationParameters = new MigrationConfigPropertiesData() { PostMigrationName = postMigrationName, TargetNamespace = serviceBusNamespace1.Id.ToString() }; _ = await serviceBusNamespace2.GetMigrationConfigProperties().CreateOrUpdateAsync(WaitUntil.Completed, MigrationConfigurationName.Default, migrationParameters); //wait for migration state MigrationConfigPropertiesResource migrationConfig = await serviceBusNamespace2.GetMigrationConfigProperties().GetAsync(MigrationConfigurationName.Default); int count = 0; while (count < 100 && (migrationConfig.Data.MigrationState != "Active" || (migrationConfig.Data.PendingReplicationOperationsCount.HasValue && migrationConfig.Data.PendingReplicationOperationsCount != 0))) { if (Mode != RecordedTestMode.Playback) { await Task.Delay(30000); } migrationConfig = await serviceBusNamespace2.GetMigrationConfigProperties().GetAsync(MigrationConfigurationName.Default); count++; } Assert.NotNull(migrationConfig); List <MigrationConfigPropertiesResource> migrationConfigs = await serviceBusNamespace2.GetMigrationConfigProperties().GetAllAsync().ToEnumerableAsync(); Assert.AreEqual(1, migrationConfigs.Count); //complete migration await migrationConfig.CompleteMigrationAsync(); //validate migration List <ServiceBusTopicResource> topics = await serviceBusNamespace1.GetServiceBusTopics().GetAllAsync().ToEnumerableAsync(); Assert.AreEqual(10, topics.Count); List <ServiceBusQueueResource> queues = await serviceBusNamespace1.GetServiceBusQueues().GetAllAsync().ToEnumerableAsync(); Assert.AreEqual(10, queues.Count); //wait for migration config and premium namespace migrationConfig = await serviceBusNamespace2.GetMigrationConfigProperties().GetAsync(MigrationConfigurationName.Default); count = 0; while (count < 100 && migrationConfig.Data.MigrationState != "Active") { if (Mode != RecordedTestMode.Playback) { await Task.Delay(30000); } migrationConfig = await serviceBusNamespace2.GetMigrationConfigProperties().GetAsync(MigrationConfigurationName.Default); count++; } await GetSucceededNamespace(serviceBusNamespace1); }
public async Task SetGetNetworkRuleSets() { IgnoreTestInLiveMode(); //create namespace with premium _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); string namespaceName = await CreateValidNamespaceName(namespacePrefix); ServiceBusNamespaceData createParameters = new ServiceBusNamespaceData(DefaultLocation); createParameters.Sku = new ServiceBusSku(ServiceBusSkuName.Premium) { Tier = ServiceBusSkuTier.Premium }; ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, createParameters)).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.ServiceBus" } } }, new SubnetData { Name = "default2", AddressPrefix = "10.0.1.0/24", ServiceEndpoints ={ new ServiceEndpointPropertiesFormat { Service = "Microsoft.ServiceBus" } } }, new SubnetData { Name = "default3", AddressPrefix = "10.0.2.0/24", ServiceEndpoints ={ new ServiceEndpointPropertiesFormat { Service = "Microsoft.ServiceBus" } } } }, 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 }, IgnoreMissingVnetServiceEndpoint = true }, new NetworkRuleSetVirtualNetworkRules() { Subnet = new WritableSubResource() { Id = subnetId2 }, IgnoreMissingVnetServiceEndpoint = false }, new NetworkRuleSetVirtualNetworkRules() { Subnet = new WritableSubResource() { Id = subnetId3 }, IgnoreMissingVnetServiceEndpoint = false } }, 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 serviceBusNamespace.GetNetworkRuleSet().CreateOrUpdateAsync(WaitUntil.Completed, parameter); //get the network rule set NetworkRuleSetResource networkRuleSet = await serviceBusNamespace.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); }
public async Task CreateGetUpdateDeleteSubscription() { IgnoreTestInLiveMode(); //create namespace ResourceGroupResource resourceGroup = await CreateResourceGroupAsync(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value; //create a topic ServiceBusTopicCollection topicCollection = serviceBusNamespace.GetServiceBusTopics(); string topicName = Recording.GenerateAssetName("topic"); ServiceBusTopicResource topic = (await topicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName, new ServiceBusTopicData())).Value; Assert.NotNull(topic); Assert.AreEqual(topic.Id.Name, topicName); //create a subscription ServiceBusSubscriptionCollection serviceBusSubscriptionCollection = topic.GetServiceBusSubscriptions(); string subscriptionName = Recording.GenerateAssetName("subscription"); ServiceBusSubscriptionData parameters = new ServiceBusSubscriptionData() { EnableBatchedOperations = true, LockDuration = TimeSpan.Parse("00:03:00"), DefaultMessageTimeToLive = TimeSpan.Parse("00:05:00"), DeadLetteringOnMessageExpiration = true, MaxDeliveryCount = 14, Status = EntityStatus.Active, AutoDeleteOnIdle = TimeSpan.Parse("00:07:00"), DeadLetteringOnFilterEvaluationExceptions = true }; ServiceBusSubscriptionResource serviceBusSubscription = (await serviceBusSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionName, parameters)).Value; Assert.NotNull(serviceBusSubscription); Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName); //get created subscription serviceBusSubscription = await serviceBusSubscriptionCollection.GetAsync(subscriptionName); Assert.NotNull(serviceBusSubscription); Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName); Assert.AreEqual(serviceBusSubscription.Data.Status, EntityStatus.Active); //get all subscriptions List <ServiceBusSubscriptionResource> serviceBusSubscriptions = await serviceBusSubscriptionCollection.GetAllAsync().ToEnumerableAsync(); Assert.AreEqual(serviceBusSubscriptions.Count, 1); //create a topic for autoforward string topicName1 = Recording.GenerateAssetName("topic"); ServiceBusTopicResource topic1 = (await topicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName1, new ServiceBusTopicData() { EnablePartitioning = true })).Value; Assert.NotNull(topic1); Assert.AreEqual(topic1.Id.Name, topicName1); //update subscription and validate ServiceBusSubscriptionData updateParameters = new ServiceBusSubscriptionData() { EnableBatchedOperations = true, DeadLetteringOnMessageExpiration = true, ForwardDeadLetteredMessagesTo = topicName1, ForwardTo = topicName1 }; serviceBusSubscription = (await serviceBusSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionName, updateParameters)).Value; Assert.NotNull(serviceBusSubscription); Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName); Assert.AreEqual(serviceBusSubscription.Data.Status, EntityStatus.Active); Assert.IsTrue(serviceBusSubscription.Data.EnableBatchedOperations); Assert.AreEqual(serviceBusSubscription.Data.ForwardTo, topicName1); //delete subscription await serviceBusSubscription.DeleteAsync(WaitUntil.Completed); Assert.IsFalse(await serviceBusSubscriptionCollection.ExistsAsync(subscriptionName)); }
public async Task NamespaceCreateGetUpdateDeleteAuthorizationRule() { IgnoreTestInLiveMode(); //create namespace _resourceGroup = await CreateResourceGroupAsync(); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); string namespaceName = await CreateValidNamespaceName(namespacePrefix); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value; NamespaceAuthorizationRuleCollection ruleCollection = serviceBusNamespace.GetNamespaceAuthorizationRules(); //create authorization rule string ruleName = Recording.GenerateAssetName("authorizationrule"); ServiceBusAuthorizationRuleData parameter = new ServiceBusAuthorizationRuleData() { 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 CreateGetUpdateDeleteDisasterRecovery() { IgnoreTestInLiveMode(); _resourceGroup = await CreateResourceGroupAsync(); //create namespace1 string namespaceName1 = await CreateValidNamespaceName("testnamespacemgmt"); ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceData parameters1 = new ServiceBusNamespaceData(DefaultLocation) { Sku = new ServiceBusSku(ServiceBusSkuName.Premium) { Tier = ServiceBusSkuTier.Premium, Capacity = 1 } }; ServiceBusNamespaceResource serviceBusNamespace1 = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, parameters1)).Value; //create namespace2 with a different location string namespaceName2 = await CreateValidNamespaceName("testnamespacemgmt"); ServiceBusNamespaceData parameters2 = new ServiceBusNamespaceData(AzureLocation.EastUS) { Sku = new ServiceBusSku(ServiceBusSkuName.Premium) { Tier = ServiceBusSkuTier.Premium, Capacity = 1 } }; ServiceBusNamespaceResource serviceBusNamespace2 = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, parameters2)).Value; //create authorization rule on namespace1 string ruleName = Recording.GenerateAssetName("authorizationrule"); ServiceBusAuthorizationRuleData ruleParameter = new ServiceBusAuthorizationRuleData() { Rights = { AccessRights.Listen, AccessRights.Send } }; NamespaceAuthorizationRuleResource authorizationRule = (await serviceBusNamespace1.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 = serviceBusNamespace2.Id }; DisasterRecoveryResource disasterRecovery = (await serviceBusNamespace1.GetDisasterRecoveries().CreateOrUpdateAsync(WaitUntil.Completed, disasterRecoveryName, parameter)).Value; Assert.NotNull(disasterRecovery); Assert.AreEqual(disasterRecovery.Id.Name, disasterRecoveryName); Assert.AreEqual(disasterRecovery.Data.PartnerNamespace, serviceBusNamespace2.Id.ToString()); //get the disaster recovery - primary disasterRecovery = await serviceBusNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); Assert.AreEqual(disasterRecovery.Data.Role, RoleDisasterRecovery.Primary); //get the disaster recovery - secondary DisasterRecoveryResource disasterRecoverySec = await serviceBusNamespace2.GetDisasterRecoveries().GetAsync(disasterRecoveryName); Assert.AreEqual(disasterRecoverySec.Data.Role, RoleDisasterRecovery.Secondary); //wait for completion, this may take several minutes in live and record mode disasterRecovery = await serviceBusNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); int i = 0; while (disasterRecovery.Data.ProvisioningState != ProvisioningStateDisasterRecovery.Succeeded && i < 100) { if (Mode != RecordedTestMode.Playback) { await Task.Delay(5000); } i++; disasterRecovery = await serviceBusNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); } //check name availability CheckNameAvailabilityResult nameAvailability = await serviceBusNamespace1.CheckDisasterRecoveryNameAvailabilityAsync(new CheckNameAvailability(disasterRecoveryName)); Assert.IsFalse(nameAvailability.NameAvailable); List <NamespaceDisasterRecoveryAuthorizationRuleResource> rules = await disasterRecovery.GetNamespaceDisasterRecoveryAuthorizationRules().GetAllAsync().ToEnumerableAsync(); Assert.IsTrue(rules.Count > 0); //get access keys of the authorization rule NamespaceDisasterRecoveryAuthorizationRuleResource rule = rules.First(); AccessKeys keys = await rule.GetKeysAsync(); Assert.NotNull(keys); //break pairing and wait for competion await disasterRecovery.BreakPairingAsync(); disasterRecovery = await serviceBusNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); i = 0; while (disasterRecovery.Data.ProvisioningState != ProvisioningStateDisasterRecovery.Succeeded && i < 100) { if (Mode != RecordedTestMode.Playback) { await Task.Delay(5000); } i++; disasterRecovery = await serviceBusNamespace1.GetDisasterRecoveries().GetAsync(disasterRecoveryName); } //get all disaster recoveries for a name space List <DisasterRecoveryResource> disasterRcoveries = await serviceBusNamespace1.GetDisasterRecoveries().GetAllAsync().ToEnumerableAsync(); Assert.IsTrue(disasterRcoveries.Count >= 1); //delete disaster recovery; await disasterRecovery.DeleteAsync(WaitUntil.Completed); }