internal static RuleListResult DeserializeRuleListResult(JsonElement element)
        {
            Optional <IReadOnlyList <ServiceBusRuleData> > value = default;
            Optional <string> nextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <ServiceBusRuleData> array = new List <ServiceBusRuleData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ServiceBusRuleData.DeserializeServiceBusRuleData(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("nextLink"))
                {
                    nextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new RuleListResult(Optional.ToList(value), nextLink.Value));
        }
예제 #2
0
        public async Task CreateGetUpdateDeleteRule()
        {
            IgnoreTestInLiveMode();

            const string strSqlExp = "myproperty=test";

            //create namespace
            ResourceGroup resourceGroup = await CreateResourceGroupAsync();

            string namespaceName = await CreateValidNamespaceName("testnamespacemgmt");

            ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace           serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;

            //create a topic
            ServiceBusTopicCollection topicCollection = serviceBusNamespace.GetServiceBusTopics();
            string          topicName = Recording.GenerateAssetName("topic");
            ServiceBusTopic 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();
            ServiceBusSubscription     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();
            ServiceBusRule           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");
            ServiceBusRule 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 <ServiceBusRule> rules = await ruleCollection.GetAllAsync().ToEnumerableAsync();

            Assert.AreEqual(2, rules.Count);

            //update rule with sql filter and action
            ServiceBusRuleData updateParameters = new ServiceBusRuleData()
            {
                Action = new SqlRuleAction()
                {
                    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);
        }