public void CorrectlyExecutesScriptIfItHasntAlreadyBeenExecuted()
        {
            ConnectionSettings settings     = getConnectionSettings();
            string             scriptFile   = @"c:\scripts\Update\01_Test.sql";
            string             fileContents = "file contents...";

            MockRepository          mocks            = new MockRepository();
            IScriptExecutionTracker executionTracker = mocks.CreateMock <IScriptExecutionTracker>();
            IFileSystem             fileSystem       = mocks.CreateMock <IFileSystem>();
            IQueryExecutor          queryExecutor    = mocks.CreateMock <IQueryExecutor>();
            ITaskObserver           taskObserver     = mocks.CreateMock <ITaskObserver>();

            Expect.Call(executionTracker.ScriptAlreadyExecuted(settings, "01_Test.sql")).Return(false);
            taskObserver.Log("Executing: 01_Test.sql");
            Expect.Call(fileSystem.ReadTextFile(scriptFile)).Return(fileContents);
            queryExecutor.ExecuteNonQuery(settings, fileContents, true);
            executionTracker.MarkScriptAsExecuted(settings, "01_Test.sql", taskObserver);

            mocks.ReplayAll();

            IChangeScriptExecutor executor = new ChangeScriptExecutor(executionTracker, queryExecutor, fileSystem);

            executor.Execute(scriptFile, settings, taskObserver);

            mocks.VerifyAll();
        }
Exemple #2
0
        public void Execute(string fullFilename, ConnectionSettings settings, ITaskObserver taskObserver, bool logOnly = false)
        {
            string scriptFilename = getFilename(fullFilename);

            if (_executionTracker.ScriptAlreadyExecuted(settings, scriptFilename))
            {
                taskObserver.Log(string.Format("Skipping (already executed): {0}{1}", getLastFolderName(fullFilename), scriptFilename));
            }
            else
            {
                if (!logOnly)
                {
                    string sql = _fileSystem.ReadTextFile(fullFilename);
                    if (!_executor.ScriptSupportsTransactions(sql))
                    {
                        taskObserver.Log(string.Format("Executing: {0}{1}", getLastFolderName(fullFilename), scriptFilename));
                        _executor.ExecuteNonQuery(settings, sql, true);
                    }
                    else
                    {
                        taskObserver.Log(string.Format("Executing: {0}{1} in a transaction", getLastFolderName(fullFilename), scriptFilename));
                        _executor.ExecuteNonQueryTransactional(settings, sql);
                    }
                }
                else
                {
                    taskObserver.Log(string.Format("Executing: {0}{1} in log only mode", getLastFolderName(fullFilename), scriptFilename));
                }

                _executionTracker.MarkScriptAsExecuted(settings, scriptFilename, taskObserver);
            }
        }
Exemple #3
0
        public void RunsScriptsWithTransactionalStopWordsNonTransactional()
        {
            ConnectionSettings settings     = getConnectionSettings();
            string             scriptFile   = @"c:\scripts\Update\01_Test.sql";
            string             fileContents = "CREATE DATABASE ...";

            MockRepository          mocks            = new MockRepository();
            IScriptExecutionTracker executionTracker = mocks.StrictMock <IScriptExecutionTracker>();
            IFileSystem             fileSystem       = mocks.StrictMock <IFileSystem>();
            IQueryExecutor          queryExecutor    = mocks.StrictMock <IQueryExecutor>();
            ITaskObserver           taskObserver     = mocks.StrictMock <ITaskObserver>();

            Expect.Call(executionTracker.ScriptAlreadyExecuted(settings, "01_Test.sql")).Return(false);
            taskObserver.Log("Executing: 01_Test.sql");
            Expect.Call(fileSystem.ReadTextFile(scriptFile)).Return(fileContents);
            Expect.Call(queryExecutor.ScriptSupportsTransactions(fileContents)).Return(false);
            queryExecutor.ExecuteNonQuery(settings, fileContents, true);
            executionTracker.MarkScriptAsExecuted(settings, "01_Test.sql", taskObserver);

            mocks.ReplayAll();

            IChangeScriptExecutor executor = new ChangeScriptExecutor(executionTracker, queryExecutor, fileSystem);

            executor.Execute(scriptFile, settings, taskObserver);

            mocks.VerifyAll();
        }
        public void Execute(string fullFilename, ConnectionSettings settings, ITaskObserver taskObserver)
        {
            string scriptFilename = getFilename(fullFilename);

            if (_executionTracker.ScriptAlreadyExecuted(settings, scriptFilename))
            {
                taskObserver.Log(string.Format("Skipping (already executed): {0}", scriptFilename));
            }
            else
            {
                taskObserver.Log(string.Format("Executing: {0}", scriptFilename));
                string sql = _fileSystem.ReadTextFile(fullFilename);
                _executor.ExecuteNonQuery(settings, sql, true);
                _executionTracker.MarkScriptAsExecuted(settings, scriptFilename, taskObserver);
            }
        }
        public void CorrectlyLogsWarningWhenScriptHasAlreadyBeenExecuted()
        {
            ConnectionSettings settings   = getConnectionSettings();
            string             scriptFile = @"c:\scripts\Update\01_Test.sql";

            MockRepository          mocks            = new MockRepository();
            IScriptExecutionTracker executionTracker = mocks.CreateMock <IScriptExecutionTracker>();
            ITaskObserver           taskObserver     = mocks.CreateMock <ITaskObserver>();

            Expect.Call(executionTracker.ScriptAlreadyExecuted(settings, "01_Test.sql")).Return(true);
            taskObserver.Log("Skipping (already executed): 01_Test.sql");

            mocks.ReplayAll();

            IChangeScriptExecutor executor = new ChangeScriptExecutor(executionTracker, null, null);

            executor.Execute(scriptFile, settings, taskObserver);

            mocks.VerifyAll();
        }
Exemple #6
0
        public void DoesNotExecuteScriptsInBaseLineMode()
        {
            ConnectionSettings settings   = getConnectionSettings();
            string             scriptFile = @"c:\scripts\Update\01_Test.sql";

            MockRepository          mocks            = new MockRepository();
            IScriptExecutionTracker executionTracker = mocks.StrictMock <IScriptExecutionTracker>();
            ITaskObserver           taskObserver     = mocks.StrictMock <ITaskObserver>();

            DoNotExpect.Call(executionTracker.ScriptAlreadyExecuted(settings, "01_Test.sql"));
            taskObserver.Log("Skipping (already executed): 01_Test.sql");

            mocks.ReplayAll();

            IChangeScriptExecutor executor = new ChangeScriptExecutor(executionTracker, null, null);

            executor.Execute(scriptFile, settings, taskObserver);

            mocks.VerifyAll();
        }