public void CallingProcessWithPerformDbOperationExpressionWhenInPreviewOnlyModeWillNotMakeDbChanges()
        {
            var output = new StringWriter();

            var connection = new NpgsqlConnection(IntegrationTestOptions.Postgres.ConnectionString);

            var processor = new PostgresProcessor(
                connection,
                new PostgresGenerator(),
                new TextWriterAnnouncer(output),
                new ProcessorOptions {
                PreviewOnly = true
            },
                new PostgresDbFactory());

            bool tableExists;

            try
            {
                var expression =
                    new PerformDBOperationExpression
                {
                    Operation = (con, trans) =>
                    {
                        var command = con.CreateCommand();
                        command.CommandText = "CREATE TABLE processtesttable (test int NULL) ";
                        command.Transaction = trans;

                        command.ExecuteNonQuery();
                    }
                };

                processor.BeginTransaction();
                processor.Process(expression);

                var com = connection.CreateCommand();
                com.CommandText = "";

                tableExists = processor.TableExists("public", "processtesttable");
            }
            finally
            {
                processor.RollbackTransaction();
            }

            tableExists.ShouldBeFalse();
            output.ToString().ShouldBe(
                @"/* Beginning Transaction */
/* Performing DB Operation */
/* Rolling back transaction */
");
        }
Example #2
0
        protected static void ExecuteWithPostgres(Action <IMigrationProcessor> test, IntegrationTestOptions.DatabaseServerOptions serverOptions, Boolean tryRollback)
        {
            if (!serverOptions.IsEnabled)
            {
                return;
            }
            var connection = new NpgsqlConnection(serverOptions.ConnectionString);
            var processor  = new PostgresProcessor(connection, new PostgresGenerator(), new TextWriterAnnouncer(System.Console.Out), new ProcessorOptions(), new PostgresDbFactory());

            test(processor);

            if (!processor.WasCommitted)
            {
                processor.RollbackTransaction();
            }
        }