public async Task Should_not_update_properties_of_an_existing_system_queue()
        {
            var queuePath = "errorQ";

            var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value));
            await namespaceManager.DeleteQueue(queuePath).ConfigureAwait(false);

            if (!await namespaceManager.QueueExists(queuePath).ConfigureAwait(false))
            {
                await namespaceManager.CreateQueue(new QueueDescription(queuePath)).ConfigureAwait(false);
            }

            var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer());

            settings.Set(WellKnownConfigurationKeys.Core.RecoverabilityNumberOfImmediateRetries, 2);
            var queueBindings = new QueueBindings();

            queueBindings.BindSending(queuePath);
            settings.Set <QueueBindings>(queueBindings);

            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            extensions.Queues().LockDuration(TimeSpan.FromMinutes(4));

            var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings);

            await creator.Create(queuePath, namespaceManager);

            var real = await namespaceManager.GetQueue(queuePath);

            Assert.That(real.LockDuration, Is.EqualTo(TimeSpan.FromSeconds(60)));

            //cleanup
            await namespaceManager.DeleteQueue(queuePath);
        }
        public async Task Should_be_able_to_update_an_existing_queue_with_new_property_values()
        {
            var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value));
            await namespaceManager.DeleteQueue("existingqueue").ConfigureAwait(false);

            await namespaceManager.CreateQueue(new QueueDescription("existingqueue"));

            var settings   = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer());
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            extensions.Queues().DescriptionCustomizer(qd =>
            {
                qd.AutoDeleteOnIdle = TimeSpan.FromMinutes(100);
                qd.EnableExpress    = true;
            });

            var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings);
            await creator.Create("existingqueue", namespaceManager);

            var queueDescription = await namespaceManager.GetQueue("existingqueue");

            Assert.AreEqual(TimeSpan.FromMinutes(100), queueDescription.AutoDeleteOnIdle);

            //cleanup
            await namespaceManager.DeleteQueue("existingqueue");
        }
        public async Task Should_be_able_to_update_an_existing_queue_with_new_property_values_without_failing_on_readonly_properties()
        {
            var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value));
            await namespaceManager.DeleteQueue("existingqueue").ConfigureAwait(false);

            await namespaceManager.CreateQueue(new QueueDescription("existingqueue")
            {
                LockDuration               = TimeSpan.FromSeconds(50),
                MaxSizeInMegabytes         = SizeInMegabytes.Size2048,
                RequiresDuplicateDetection = true,
                EnablePartitioning         = true,
                RequiresSession            = true
            });

            var queueDescription = await namespaceManager.GetQueue("existingqueue");

            // partitioned topics will have a size that is 16x the requested max
            Assert.AreEqual(2048 * 16, queueDescription.MaxSizeInMegabytes);
            Assert.AreEqual(TimeSpan.FromSeconds(50), queueDescription.LockDuration);
            Assert.IsTrue(queueDescription.EnablePartitioning);
            Assert.IsTrue(queueDescription.RequiresDuplicateDetection);

            var settings   = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer());
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            extensions.Queues().DescriptionCustomizer(qd =>
            {
                qd.LockDuration               = TimeSpan.FromSeconds(70);
                qd.MaxSizeInMegabytes         = SizeInMegabytes.Size3072;
                qd.RequiresDuplicateDetection = false;
                qd.EnablePartitioning         = false;
                qd.RequiresSession            = false;
            });

            var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings);
            await creator.Create("existingqueue", namespaceManager);

            queueDescription = await namespaceManager.GetQueue("existingqueue");

            Assert.AreEqual(3072 * 16, queueDescription.MaxSizeInMegabytes);
            Assert.AreEqual(TimeSpan.FromSeconds(70), queueDescription.LockDuration);
            Assert.IsTrue(queueDescription.EnablePartitioning);
            Assert.IsTrue(queueDescription.RequiresDuplicateDetection);

            //cleanup
            await namespaceManager.DeleteQueue("existingqueue");
        }
        public void TopicSetup()
        {
            var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value));

            if (!namespaceManager.TopicExists(topicPath).GetAwaiter().GetResult())
            {
                namespaceManager.CreateTopic(new TopicDescription(topicPath)).GetAwaiter().GetResult();
            }
            if (!namespaceManager.QueueExists(forwardToQueue).GetAwaiter().GetResult())
            {
                namespaceManager.CreateQueue(new QueueDescription(forwardToQueue)).GetAwaiter().GetResult();
            }

            namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Fallback));
            if (!namespaceManager.TopicExists(topicPath).GetAwaiter().GetResult())
            {
                namespaceManager.CreateTopic(new TopicDescription(topicPath)).GetAwaiter().GetResult();
            }
            if (!namespaceManager.QueueExists(forwardToQueue).GetAwaiter().GetResult())
            {
                namespaceManager.CreateQueue(new QueueDescription(forwardToQueue)).GetAwaiter().GetResult();
            }
        }