static async Task CreateSecondTopicInBundleForBackwardsCompatibilityTesting(NamespaceManager namespaceManager, string endpointName, string connectionString, string ruleForMyOtherEvent)
        {
            const string topicPath = "bundle-2";

            if (!await namespaceManager.TopicExistsAsync(topicPath))
            {
                await namespaceManager.CreateTopicAsync(topicPath);
            }

            var subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, topicPath, endpointName);

            Task CreateRuleForMyEvent() => subscriptionClient.AddRuleAsync(MD5HashBuilder.Build(typeof(MyEvent).FullName.Replace("+", string.Empty)), new TrueFilter());

            if (!await namespaceManager.SubscriptionExistsAsync(topicPath, endpointName))
            {
                await namespaceManager.CreateSubscriptionAsync(topicPath, endpointName);

                await subscriptionClient.RemoveRuleAsync(RuleDescription.DefaultRuleName);

                await subscriptionClient.AddRuleAsync(ruleForMyOtherEvent, new TrueFilter());
                await CreateRuleForMyEvent();
            }
            else
            {
                await CreateRuleForMyEvent();
            }
        }
        public async Task Should_remove_subscription_rule_from_topology()
        {
            Requires.ForwardingTopology();

            var connectionString       = TestUtility.DefaultConnectionString;
            var namespaceManager       = NamespaceManager.CreateFromConnectionString(connectionString);
            var rawEndpointName        = Conventions.EndpointNamingConvention(typeof(Endpoint));
            var endpointName           = MD5HashBuilder.Build(rawEndpointName);
            var sanitizedEventFullName = typeof(MyOtherEvent).FullName.Replace("+", string.Empty);
            var otherRuleName          = MD5HashBuilder.Build(sanitizedEventFullName);

            await CreateSecondTopicInBundleForBackwardsCompatibilityTesting(namespaceManager, endpointName, connectionString, otherRuleName);

            await Scenario.Define <ScenarioContext>()
            .WithEndpoint <Endpoint>(b => b.When((session, c) => session.Unsubscribe <MyEvent>()))
            .Done(c => c.EndpointsStarted)
            .Run();

            var isSubscriptionFound = await namespaceManager.SubscriptionExistsAsync("bundle-1", endpointName);

            Assert.IsTrue(isSubscriptionFound, "Subscription under 'bundle-1' should have been found, but it wasn't.");

            isSubscriptionFound = await namespaceManager.SubscriptionExistsAsync("bundle-2", endpointName);

            Assert.IsTrue(isSubscriptionFound, "Subscription under 'bundle-2' should have been found, but it wasn't.");

            var rules = await namespaceManager.GetRulesAsync("bundle-1", endpointName);

            CollectionAssert.AreEquivalent(new[] { otherRuleName }, rules.Select(r => r.Name));

            rules = await namespaceManager.GetRulesAsync("bundle-2", endpointName);

            CollectionAssert.AreEquivalent(new[] { otherRuleName }, rules.Select(r => r.Name));
        }
コード例 #3
0
        public async Task Should_remove_subscription_rule_from_topology()
        {
            var context = await Scenario.Define <Context>()
                          .WithEndpoint <Endpoint>(b => b.When((session, c) => session.Unsubscribe <MyEvent>()))
                          .Done(c => c.EndpointsStarted)
                          .Run();

            var connectionString       = EnvironmentHelper.GetEnvironmentVariable("AzureServiceBusTransport.ConnectionString");
            var namespaceManager       = NamespaceManager.CreateFromConnectionString(connectionString);
            var rawEndpointName        = Conventions.EndpointNamingConvention(typeof(Endpoint));
            var endpointName           = MD5HashBuilder.Build(rawEndpointName);
            var sanitizedEventFullName = typeof(MyOtherEvent).FullName.Replace("+", string.Empty);
            var otherRuleName          = MD5HashBuilder.Build(sanitizedEventFullName);

            if (context.IsForwardingTopology)
            {
                var isSubscriptionFound = await namespaceManager.SubscriptionExistsAsync("bundle-1", endpointName);

                Assert.IsTrue(isSubscriptionFound, "Subscription under 'bundle-1' should have been found, but it wasn't.");

                isSubscriptionFound = await namespaceManager.SubscriptionExistsAsync("bundle-2", endpointName);

                Assert.IsTrue(isSubscriptionFound, "Subscription under 'bundle-2' should have been found, but it wasn't.");

                var rules = await namespaceManager.GetRulesAsync("bundle-1", endpointName);

                CollectionAssert.AreEquivalent(new[] { otherRuleName }, rules.Select(r => r.Name));

                rules = await namespaceManager.GetRulesAsync("bundle-2", endpointName);

                CollectionAssert.AreEquivalent(new [] { otherRuleName }, rules.Select(r => r.Name));
            }
            else
            {
                Assert.Ignore("Not applicable to EndpointOrientedTopology");
            }
        }