Ejemplo n.º 1
0
    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 = MsSqlMicrosoftDataClientConnectionBuilder.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 = MsSqlMicrosoftDataClientConnectionBuilder.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");
        }
Ejemplo n.º 3
0
 protected override Func <string, DbConnection> GetConnection()
 {
     return(x =>
     {
         var connection = MsSqlMicrosoftDataClientConnectionBuilder.Build();
         connection.Open();
         return connection;
     });
 }
Ejemplo n.º 4
0
    public Task Configure(string endpointName, EndpointConfiguration configuration, RunSettings settings, PublisherMetadata publisherMetadata)
    {
        transport = new TestingSqlServerTransport(async cancellationToken =>
        {
            var conn = MsSqlMicrosoftDataClientConnectionBuilder.Build();
            await conn.OpenAsync(cancellationToken).ConfigureAwait(false);
            return(conn);
        });

        configuration.UseTransport(transport);

        return(Task.FromResult(0));
    }
    public Task Cleanup()
    {
        using (var conn = MsSqlMicrosoftDataClientConnectionBuilder.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 = MsSqlMicrosoftDataClientConnectionBuilder.Build();
            await conn.OpenAsync().ConfigureAwait(false);
            return(conn);
        });

        return(Task.FromResult(0));
    }
Ejemplo n.º 7
0
        public void Setup()
        {
            using (var connection = MsSqlMicrosoftDataClientConnectionBuilder.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();
                }
            }
        }
Ejemplo n.º 8
0
 protected override Func <string, DbConnection> GetConnection()
 {
     return(x => MsSqlMicrosoftDataClientConnectionBuilder.Build());
 }