public async Task Should_remove_old_property_after_phase_three() { var dialect = BuildSqlDialect.MsSqlServer; var sagaPhase1 = RuntimeSagaDefinitionReader.GetSagaDefinition(typeof(Phase1Saga), dialect); var sagaPhase2 = RuntimeSagaDefinitionReader.GetSagaDefinition(typeof(Phase2Saga), dialect); var sagaPhase3 = RuntimeSagaDefinitionReader.GetSagaDefinition(typeof(Phase3Saga), dialect); using (var connection = MsSqlSystemDataClientConnectionBuilder.Build()) { await connection.OpenAsync().ConfigureAwait(false); connection.ExecuteCommand(SagaScriptBuilder.BuildDropScript(sagaPhase1, dialect), ""); connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaPhase1, dialect), ""); var phase1Schema = GetSchema(connection); connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaPhase2, dialect), ""); var phase2Schema = GetSchema(connection); connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaPhase3, dialect), ""); var phase3Schema = GetSchema(connection); CollectionAssert.Contains(phase1Schema, "Correlation_OrderNumber"); CollectionAssert.DoesNotContain(phase1Schema, "Correlation_OrderId"); CollectionAssert.Contains(phase2Schema, "Correlation_OrderNumber"); CollectionAssert.Contains(phase2Schema, "Correlation_OrderId"); CollectionAssert.DoesNotContain(phase3Schema, "Correlation_OrderNumber"); CollectionAssert.Contains(phase3Schema, "Correlation_OrderId"); } }
[TestCase(TransportTransactionMode.ReceiveOnly, true)] //Uses the Outbox to ensure exactly-once public async Task Should_rollback_changes_when_transport_transaction_is_rolled_back(TransportTransactionMode transactionMode, bool enableOutbox) { using (var connection = MsSqlSystemDataClientConnectionBuilder.Build()) { await connection.OpenAsync().ConfigureAwait(false); using (var command = connection.CreateCommand()) { command.CommandText = CreateUserDataTableText; await command.ExecuteNonQueryAsync().ConfigureAwait(false); } } var context = await Scenario.Define <Context>() .WithEndpoint <Endpoint>( b => b.When((session, ctx) => session.SendLocal(new MyMessage() { Id = ctx.TestRunId })).DoNotFailOnErrorMessages().CustomConfig(c => { c.ConfigureTransport().TransportTransactionMode = transactionMode; if (enableOutbox) { c.EnableOutbox(); } })) .Done(c => c.ReplyReceived) .Run(); Assert.True(context.ReplyReceived); Assert.IsFalse(context.TransactionEscalatedToDTC); Assert.AreEqual(2, context.InvocationCount, "Handler should be called twice"); Assert.AreEqual(1, context.RecordCount, "There should be only once record in the database"); }
public void SetUp() { using (var connection = MsSqlSystemDataClientConnectionBuilder.Build()) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @" if not exists ( select * from sys.schemas where name = 'schema_name') exec('create schema schema_name');"; command.ExecuteNonQuery(); } } using (var connection = PostgreSqlConnectionBuilder.Build()) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @"create schema if not exists ""SchemaName"";"; command.ExecuteNonQuery(); } } }
protected override Func <string, DbConnection> GetConnection() { return(x => { var connection = MsSqlSystemDataClientConnectionBuilder.Build(); connection.Open(); return connection; }); }
public static void Setup(string tenantId) { var dbName = "nservicebus_" + tenantId.ToLower(); using (var conn = MsSqlSystemDataClientConnectionBuilder.Build()) { conn.Open(); conn.ExecuteCommand($"if not exists (select * from sysdatabases where name = '{dbName}') create database {dbName};"); } }
public Task Configure(string endpointName, EndpointConfiguration configuration, RunSettings settings, PublisherMetadata publisherMetadata) { transport = new TestingSqlServerTransport(async cancellationToken => { var conn = MsSqlSystemDataClientConnectionBuilder.Build(); await conn.OpenAsync(cancellationToken).ConfigureAwait(false); return(conn); }); configuration.UseTransport(transport); return(Task.FromResult(0)); }
public Task Cleanup() { using (var conn = MsSqlSystemDataClientConnectionBuilder.Build()) { conn.Open(); var queueAddresses = queueBindings.ReceivingAddresses.Select(QueueAddress.Parse).ToList(); foreach (var address in queueAddresses) { TryDeleteTable(conn, address); TryDeleteTable(conn, new QueueAddress(address.Table + ".Delayed", address.Schema, address.Catalog)); } } return(Task.FromResult(0)); }
public Task Configure(string endpointName, EndpointConfiguration configuration, RunSettings settings, PublisherMetadata publisherMetadata) { queueBindings = configuration.GetSettings().Get <QueueBindings>(); var transportConfig = configuration.UseTransport <SqlServerTransport>(); transportConfig.UseCustomSqlConnectionFactory(async() => { var conn = MsSqlSystemDataClientConnectionBuilder.Build(); await conn.OpenAsync().ConfigureAwait(false); return(conn); }); return(Task.FromResult(0)); }
protected override Func <string, DbConnection> GetConnection() { return(x => MsSqlSystemDataClientConnectionBuilder.Build()); }