SqlServerTransport GetTransport(string connectionString, IsolationLevel isolationLevel)
    {
        var rebusTime          = new DefaultRebusTime();
        var rebusLoggerFactory = new ConsoleLoggerFactory(false);

        var connectionProvider = new DbConnectionProvider(connectionString, rebusLoggerFactory)
        {
            IsolationLevel = isolationLevel
        };

        var taskFactory = new TplAsyncTaskFactory(rebusLoggerFactory);

        var transport = new SqlServerTransport(
            connectionProvider: connectionProvider,
            inputQueueName: _queueName,
            rebusLoggerFactory: rebusLoggerFactory,
            asyncTaskFactory: taskFactory,
            rebusTime: rebusTime,
            options: new SqlServerTransportOptions(connectionProvider)
            );

        transport.Initialize();

        return(transport);
    }
        public void It_rejects_connection_string_without_catalog_property()
        {
            var definition = new SqlServerTransport();

            Assert.That(() => definition.Initialize(new SettingsHolder(), @"Data Source=.\SQLEXPRESS;Integrated Security=True"),
                        Throws.Exception.Message.Contains("Initial Catalog property is mandatory in the connection string."));
        }
        public void It_accepts_connection_string_with_catalog_property(string connectionString)
        {
            var definition = new SqlServerTransport();

            definition.Initialize(new SettingsHolder(), connectionString);
            Assert.Pass();
        }
Пример #4
0
        public void It_rejects_connection_string_without_catalog_property()
        {
            var definition = new SqlServerTransport(@"Data Source=.\SQLEXPRESS;Integrated Security=True");

            Assert.That(
                async() => await definition.Initialize(settings, new ReceiveSettings[0], new string[0]).ConfigureAwait(false),
                Throws.Exception.Message.Contains("Initial Catalog property is mandatory in the connection string."));
        }
Пример #5
0
        protected override void SetUp()
        {
            SqlTestHelper.DropTable(_tableName);

            _transport = new SqlServerTransport(new DbConnectionProvider(SqlTestHelper.ConnectionString), _tableName, QueueName);
            _transport.EnsureTableIsCreated();

            Using(_transport);

            _transport.Initialize();
        }
Пример #6
0
        public ITransport CreateOneWayClient()
        {
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
            var asyncTaskFactory     = new TplAsyncTaskFactory(consoleLoggerFactory);
            var transport            = new SqlServerTransport(connectionProvider, null, consoleLoggerFactory, asyncTaskFactory);

            _disposables.Add(transport);

            transport.Initialize();

            return(transport);
        }
Пример #7
0
        public async Task Should_stop_receiving_messages_after_first_unsuccessful_receive()
        {
            var successfulReceives = 46;
            var queueSize          = 1000;

            var parser = new QueueAddressTranslator("nservicebus", "dbo", null, null);

            var inputQueueAddress = parser.Parse("input").Address;
            var inputQueue        = new FakeTableBasedQueue(inputQueueAddress, queueSize, successfulReceives);

            var connectionString = Environment.GetEnvironmentVariable("SqlServerTransportConnectionString");

            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True";
            }

            var transport = new SqlServerTransport(SqlConnectionFactory.Default(connectionString).OpenNewConnection)
            {
                TransportTransactionMode = TransportTransactionMode.None,
                TimeToWaitBeforeTriggeringCircuitBreaker = TimeSpan.MaxValue,
            };

            transport.Testing.QueueFactoryOverride = qa =>
                                                     qa == inputQueueAddress ? inputQueue : new TableBasedQueue(parser.Parse(qa).QualifiedTableName, qa, true);

            var receiveSettings = new ReceiveSettings("receiver", inputQueueAddress, true, false, "error");
            var hostSettings    = new HostSettings("IntegrationTests", string.Empty, new StartupDiagnosticEntries(),
                                                   (_, __, ___) => { },
                                                   true);

            var infrastructure = await transport.Initialize(hostSettings, new[] { receiveSettings }, new string[0]);

            var receiver = infrastructure.Receivers.First().Value;

            await receiver.Initialize(
                new PushRuntimeSettings(1),
                (_, __) => Task.CompletedTask,
                (_, __) => Task.FromResult(ErrorHandleResult.Handled));

            await receiver.StartReceive();

            await WaitUntil(() => inputQueue.NumberOfPeeks > 1);

            await receiver.StopReceive();

            await infrastructure.Shutdown();

            Assert.That(inputQueue.NumberOfReceives, Is.AtMost(successfulReceives + 2), "Receiver should stop receives after first unsuccessful attempt.");
        }
Пример #8
0
        public void It_accepts_connection_string_with_catalog_property(string connectionString)
        {
            var definition = new SqlServerTransport();

            var subscriptionSettings = new SubscriptionSettings();

            subscriptionSettings.DisableSubscriptionCache();
            var settings = new SettingsHolder();

            settings.Set(subscriptionSettings);

            definition.Initialize(settings, connectionString);
            Assert.Pass();
        }
Пример #9
0
        protected override void SetUp()
        {
            SqlTestHelper.DropTable(_tableName);

            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);

            _transport = new SqlServerTransport(connectionProvider, _tableName, QueueName, consoleLoggerFactory);
            _transport.EnsureTableIsCreated();

            Using(_transport);

            _transport.Initialize();
        }
Пример #10
0
        public ITransport Create(string inputQueueAddress)
        {
            var tableName = ("RebusMessages_" + TestConfig.Suffix).TrimEnd('_');

            _tablesToDrop.Add(tableName);

            var transport = new SqlServerTransport(new DbConnectionProvider(SqlTestHelper.ConnectionString), tableName, inputQueueAddress);

            _disposables.Add(transport);

            transport.EnsureTableIsCreated();
            transport.Initialize();

            return(transport);
        }
Пример #11
0
        public void It_reads_catalog_from_open_connection()
        {
            var definition = new SqlServerTransport();
            Func <Task <SqlConnection> > factory = async() =>
            {
                var connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True");
                await connection.OpenAsync().ConfigureAwait(false);

                return(connection);
            };
            var settings = new SettingsHolder();

            settings.Set(SettingsKeys.ConnectionFactoryOverride, factory);
            definition.Initialize(settings, "Invalid-connection-string");
            Assert.Pass();
        }
Пример #12
0
        public void It_reads_catalog_from_open_connection()
        {
            var definition = new SqlServerTransport();
            Func <Task <SqlConnection> > factory = async() =>
            {
                var connection = new SqlConnection(connectionString);
                await connection.OpenAsync().ConfigureAwait(false);

                return(connection);
            };
            var settings = new SettingsHolder();

            settings.Set(SettingsKeys.ConnectionFactoryOverride, factory);
            definition.Initialize(settings, "Invalid-connection-string");
            Assert.Pass();
        }
Пример #13
0
        protected override void SetUp()
        {
            SqlTestHelper.DropTable(_tableName);

            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
            var asyncTaskFactory     = new TplAsyncTaskFactory(consoleLoggerFactory);

            _transport = new SqlServerTransport(connectionProvider, _tableName, QueueName, consoleLoggerFactory, asyncTaskFactory);
            _transport.EnsureTableIsCreated();

            Using(_transport);

            _transport.Initialize();

            _cancellationToken = new CancellationTokenSource().Token;
        }
Пример #14
0
        public ITransport CreateOneWayClient()
        {
            var tableName = ("RebusMessages_" + TestConfig.Suffix).TrimEnd('_');

            _tablesToDrop.Add(tableName);

            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
            var transport            = new SqlServerTransport(connectionProvider, tableName, null, consoleLoggerFactory);

            _disposables.Add(transport);

            transport.EnsureTableIsCreated();
            transport.Initialize();

            return(transport);
        }
Пример #15
0
        public ITransport Create(string inputQueueAddress)
        {
            var tableName = ("RebusMessages_" + TestConfig.Suffix).TrimEnd('_');

            _tablesToDrop.Add(tableName);

            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
            var asyncTaskFactory     = new TplAsyncTaskFactory(consoleLoggerFactory);
            var transport            = new SqlServerTransport(connectionProvider, tableName, inputQueueAddress, consoleLoggerFactory, asyncTaskFactory);

            _disposables.Add(transport);

            transport.EnsureTableIsCreated();
            transport.Initialize();

            return(transport);
        }
        protected override void SetUp()
        {
            // start clean
            SqlTestHelper.DropAllTables();

            // end clean
            Using(new DisposableCallback(SqlTestHelper.DropAllTables));

            var loggerFactory      = new ListLoggerFactory();
            var connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, loggerFactory);

            _subscriptionStorage = new SqlServerSubscriptionStorage(connectionProvider, "Subscriptions", isCentralized: true, loggerFactory);
            _subscriptionStorage.EnsureTableIsCreated();
            _subscriptionStorage.Initialize();

            _subscriberTransport = Using(new SqlServerTransport(connectionProvider, "subscriber", loggerFactory, new TplAsyncTaskFactory(loggerFactory), new FakeRebusTime(), new SqlServerTransportOptions(connectionProvider)));
            _subscriberTransport.EnsureTableIsCreated();
            _subscriberTransport.Initialize();
        }