Beispiel #1
0
        public void Execute(string fullFilename, ConnectionSettings settings, ITaskObserver taskObserver)
        {
            string scriptFilename = getFilename(fullFilename);

            if (_executionTracker.TestDataScriptAlreadyExecuted(settings, scriptFilename))
            {
                taskObserver.Log(string.Format("Skipping (already executed): {0}", scriptFilename));
            }
            else
            {
                string sql = _fileSystem.ReadTextFile(fullFilename);
                if (!_executor.ScriptSupportsTransactions(sql))
                {
                    taskObserver.Log(string.Format("Executing: {0}", scriptFilename));
                    _executor.ExecuteNonQuery(settings, sql, true);
                    _executionTracker.MarkTestDataScriptAsExecuted(settings, scriptFilename, taskObserver);
                }
                else
                {
                    taskObserver.Log(string.Format("Executing: {0} in a transaction", scriptFilename));
                    _executor.ExecuteNonQueryTransactional(settings, sql);
                    _executionTracker.MarkTestDataScriptAsExecuted(settings, scriptFilename, taskObserver);
                }
            }
        }
Beispiel #2
0
        public void CorrectlyExecutesScriptIfItHasntAlreadyBeenExecuted()
        {
            var    settings     = new ConnectionSettings("server", "db", true, null, null);
            string scriptFile   = @"c:\scripts\TestData\01_Test.sql";
            string fileContents = "file contents...";

            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.TestDataScriptAlreadyExecuted(settings, "01_Test.sql")).Return(false);
            taskObserver.Log("Executing: 01_Test.sql in a transaction");
            Expect.Call(fileSystem.ReadTextFile(scriptFile)).Return(fileContents);
            Expect.Call(queryExecutor.ScriptSupportsTransactions(fileContents)).Return(true);
            queryExecutor.ExecuteNonQueryTransactional(settings, fileContents);
            executionTracker.MarkTestDataScriptAsExecuted(settings, "01_Test.sql", taskObserver);

            mocks.ReplayAll();

            ITestDataScriptExecutor executor = new TestDataScriptExecutor(executionTracker, queryExecutor, fileSystem);

            executor.Execute(scriptFile, settings, taskObserver);

            mocks.VerifyAll();
        }