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 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); }