public async Task Should_store_event_original_name_as_usermetadata()
        {
            const string subscriptionName = "sub16";

            var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value), AzureServiceBusConnectionString.Value);

            var creator = new AzureServiceBusSubscriptionCreator(new TopologySubscriptionSettings());
            var subscriptionDescription = await creator.Create(topicPath, subscriptionName, new SubscriptionMetadataInternal { Description = "very.long.name.of.an.event.that.would.exceed.subscription.length" }, sqlFilter, namespaceManager);

            Assert.IsTrue(await namespaceManager.SubscriptionExists(topicPath, subscriptionName));
            Assert.AreEqual("very.long.name.of.an.event.that.would.exceed.subscription.length", subscriptionDescription.UserMetadata);

            await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName));
        }
        public async Task Should_create_subscription_on_multiple_namespaces()
        {
            const string subscriptionName = "MultipleNamespaceEvent";

            var creator = new AzureServiceBusSubscriptionCreator(new TopologySubscriptionSettings());

            var namespaceManager1 = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value), AzureServiceBusConnectionString.Value);
            var namespaceManager2 = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Fallback), AzureServiceBusConnectionString.Fallback);

            await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager1);

            await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager2);

            Assert.IsTrue(await namespaceManager1.SubscriptionExists(topicPath, subscriptionName), "Subscription on Value namespace was not created.");
            Assert.IsTrue(await namespaceManager2.SubscriptionExists(topicPath, subscriptionName), "Subscription on Fallback namespace was not created.");
        }
        public async Task Should_properly_set_use_subscription_description_defaults_if_user_does_not_provide_topic_description_values()
        {
            var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value));

            var          creator                 = new AzureServiceBusForwardingSubscriptionCreator(new TopologySubscriptionSettings());
            const string subscriptionName        = "endpoint1";
            var          subscriptionDescription = await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager, forwardToQueue);

            Assert.IsTrue(await namespaceManager.SubscriptionExists(topicPath, subscriptionName));
            Assert.AreEqual(TimeSpan.MaxValue, subscriptionDescription.AutoDeleteOnIdle);
            Assert.AreEqual(TimeSpan.MaxValue, subscriptionDescription.DefaultMessageTimeToLive);
            Assert.AreEqual(TimeSpan.FromMilliseconds(30000), subscriptionDescription.LockDuration);
            Assert.True(subscriptionDescription.EnableBatchedOperations);
            Assert.IsFalse(subscriptionDescription.EnableDeadLetteringOnFilterEvaluationExceptions);
            Assert.IsFalse(subscriptionDescription.EnableDeadLetteringOnMessageExpiration);
            Assert.IsFalse(subscriptionDescription.RequiresSession);
            Assert.AreEqual(AzureServiceBusForwardingSubscriptionCreator.DefaultMaxDeliveryCountForNoImmediateRetries, subscriptionDescription.MaxDeliveryCount);
            Assert.IsNull(subscriptionDescription.ForwardDeadLetteredMessagesTo);
            Assert.That(subscriptionDescription.ForwardTo, Does.EndWith(forwardToQueue));

            await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName));
        }
        public async Task Should_properly_set_use_subscription_description_provided_by_user()
        {
            var settings         = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer());
            var extensions       = new TransportExtensions <AzureServiceBusTransport>(settings);
            var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value));

            const string subscriptionName = "endpoint2";

            var userCustomizationsWhereInvoked = false;

            extensions.Subscriptions().DescriptionCustomizer(_ =>
            {
                userCustomizationsWhereInvoked = true;
            });

            var creator = new AzureServiceBusForwardingSubscriptionCreator(settings.Get <TopologySettings>().SubscriptionSettings);

            await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager, forwardToQueue);

            Assert.IsTrue(await namespaceManager.SubscriptionExists(topicPath, subscriptionName));
            Assert.IsTrue(userCustomizationsWhereInvoked);

            await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName));
        }
        public async Task Should_create_subscription_on_multiple_namespaces()
        {
            const string subscriber = "MultipleNamespaceSubscriber";

            var namespaceManager1 = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value));
            var namespaceManager2 = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Fallback));

            var creator = new AzureServiceBusForwardingSubscriptionCreator(new TopologySubscriptionSettings
            {
                DescriptionCustomizer = description =>
                {
                    description.MaxDeliveryCount = 100;
                    description.EnableDeadLetteringOnMessageExpiration = true;
                }
            });

            await creator.Create(topicPath, subscriber, metadata, sqlFilter, namespaceManager1, forwardToQueue);

            await creator.Create(topicPath, subscriber, metadata, sqlFilter, namespaceManager2, forwardToQueue);


            Assert.IsTrue(await namespaceManager1.SubscriptionExists(topicPath, subscriber), "Subscription on Value namespace was not created.");
            Assert.IsTrue(await namespaceManager2.SubscriptionExists(topicPath, subscriber), "Subscription on Fallback namespace was not created.");
        }