Ejemplo n.º 1
0
        public void Should_not_fail_if_datebase_does_not_exist()
        {
            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, null);

            var mocks             = new MockRepository();
            var connectionDropper = mocks.DynamicMock <IDatabaseConnectionDropper>();
            var taskObserver      = mocks.StrictMock <ITaskObserver>();
            var queryExecutor     = mocks.StrictMock <IQueryExecutor>();

            using (mocks.Record())
            {
                Expect.Call(() => taskObserver.Log("Running against: SQL Server"));
                Expect.Call(queryExecutor.ReadFirstColumnAsStringArray(settings, "select @@version")).Return(new string[] { "SQL Server" });
                Expect.Call(() => taskObserver.Log("Dropping database: db\n"));
                Expect.Call(() => queryExecutor.ExecuteNonQuery(settings, "ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [db]"))
                .Throw(new Exception("foo message"));
                Expect.Call(() => taskObserver.Log("Database 'db' could not be dropped."));
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
                dropper.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 2
0
        public void Execute(TaskAttributes taskAttributes, ITaskObserver taskObserver)
        {
            if (!_queryExecutor.CheckDatabaseExists(taskAttributes.ConnectionSettings))
            {
                return;
            }

            var version = _queryExecutor.ReadFirstColumnAsStringArray(taskAttributes.ConnectionSettings, "select @@version")[0];

            taskObserver.Log("Running against: " + version);

            //can't kill connections or enter single user mode in Azure
            var sql = string.Format("drop database [{0}]", taskAttributes.ConnectionSettings.Database);

            if (!version.Contains("SQL Azure"))
            {
                _connectionDropper.Drop(taskAttributes.ConnectionSettings, taskObserver);
                sql = string.Format("ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [{0}]", taskAttributes.ConnectionSettings.Database);
            }

            string message = string.Format("Dropping database: {0}\n", taskAttributes.ConnectionSettings.Database);

            taskObserver.Log(message);
            try
            {
                _queryExecutor.ExecuteNonQuery(taskAttributes.ConnectionSettings, sql);
            }
            catch (Exception)
            {
                taskObserver.Log(string.Format("Database '{0}' could not be dropped.", taskAttributes.ConnectionSettings.Database));
            }
        }
Ejemplo n.º 3
0
        public void Manages_database()
        {
            var settings        = new ConnectionSettings("server", "db", true, null, null);
            var scriptDirectory = @"c:\scripts";
            var taskAttributes  = new TaskAttributes(settings, scriptDirectory);

            var mocks        = new MockRepository();
            var taskObserver = mocks.CreateMock <ITaskObserver>();
            var generator    = mocks.CreateMock <ILogMessageGenerator>();
            var factory      = mocks.CreateMock <IDatabaseActionExecutorFactory>();

            var creator = mocks.CreateMock <IDatabaseActionExecutor>();
            var updater = mocks.CreateMock <IDatabaseActionExecutor>();

            var executors = new IDatabaseActionExecutor[] { creator, updater };

            using (mocks.Record())
            {
                Expect.Call(generator.GetInitialMessage(taskAttributes)).Return("starting...");
                taskObserver.Log("starting...");
                Expect.Call(factory.GetExecutors(RequestedDatabaseAction.Create)).Return(executors);

                creator.Execute(taskAttributes, taskObserver);
                updater.Execute(taskAttributes, taskObserver);
            }

            using (mocks.Playback())
            {
                ISqlDatabaseManager manager = new SqlDatabaseManager(generator, factory);

                manager.Upgrade(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 4
0
        public void Executes_all_the_scripts_within_a_folder()
        {
            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var sqlFiles       = new[] { "c:\\scripts\\Update\\001.sql", "c:\\scripts\\Update\\002_data_.sql", "c:\\scripts\\Update\\003.sql" };
            var taskAttributes = new TaskAttributes(settings, "c:\\scripts")
            {
                RequestedDatabaseAction = RequestedDatabaseAction.Update,
            };

            var mocks            = new MockRepository();
            var initializer      = mocks.StrictMock <ISchemaInitializer>();
            var fileLocator      = mocks.StrictMock <ISqlFileLocator>();
            var executor         = mocks.StrictMock <IChangeScriptExecutor>();
            var testdataexecutor = mocks.StrictMock <ITestDataScriptExecutor>();
            var versioner        = mocks.StrictMock <IDatabaseVersioner>();
            var taskObserver     = mocks.StrictMock <ITaskObserver>();

            using (mocks.Record())
            {
                initializer.EnsureSchemaCreated(settings);
                Expect.Call(fileLocator.GetSqlFilenames("c:\\scripts", "Update")).Return(sqlFiles);
                executor.Execute("c:\\scripts\\Update\\001.sql", settings, taskObserver);
                executor.Execute("c:\\scripts\\Update\\002_data_.sql", settings, taskObserver);
                executor.Execute("c:\\scripts\\Update\\003.sql", settings, taskObserver);
                versioner.VersionDatabase(settings, taskObserver);
            }

            using (mocks.Playback())
            {
                IScriptFolderExecutor folderExecutor = new ScriptFolderExecutor(initializer, fileLocator, executor, testdataexecutor, versioner);
                folderExecutor.ExecuteScriptsInFolder(taskAttributes, "Update", taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 5
0
        public void Updates_database()
        {
            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, "c:\\scripts");

            taskAttributes.RequestedDatabaseAction = RequestedDatabaseAction.Update;
            var mocks = new MockRepository();
            var scriptfolderexecutor = mocks.StrictMock <IScriptFolderExecutor>();
            var queryexecutor        = mocks.StrictMock <IQueryExecutor>();

            queryexecutor.Stub(x => x.CheckDatabaseExists(taskAttributes.ConnectionSettings)).Return(true);

            var taskObserver = mocks.StrictMock <ITaskObserver>();

            using (mocks.Record())
            {
                taskObserver.Log(string.Format("Run scripts in Update folder."));
                scriptfolderexecutor.ExecuteScriptsInFolder(taskAttributes, "Update", taskObserver);

                taskObserver.Log(string.Format("Run scripts in Everytime folder."));
                scriptfolderexecutor.ExecuteChangedScriptsInFolder(taskAttributes, "Everytime", taskObserver);
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor updater = new DatabaseUpdater(scriptfolderexecutor, queryexecutor);
                updater.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 6
0
        public bool UpdateDatabase(ConnectionSettings settings, string scriptDirectory, RequestedDatabaseAction action)
        {
            var manager = new SqlDatabaseManager();

            var taskAttributes = new TaskAttributes(settings, scriptDirectory)
            {
                RequestedDatabaseAction = action,
            };

            try
            {
                manager.Upgrade(taskAttributes, this);

                foreach (var property in _properties)
                {
                    Log(property.Key + ": " + property.Value);
                }
                return(true);
            }
            catch (Exception exception)
            {
                var ex = exception;
                do
                {
                    Log("Failure: " + ex.Message);
                    ex = ex.InnerException;
                } while (ex != null);

                //Log(exception.ToString());
            }
            return(false);
        }
Ejemplo n.º 7
0
        public void Drops_database()
        {
            var taskAttributes = new TaskAttributes(settings, null);

            var mocks             = new MockRepository();
            var connectionDropper = mocks.StrictMock <IDatabaseConnectionDropper>();
            var taskObserver      = mocks.StrictMock <ITaskObserver>();
            var queryExecutor     = mocks.StrictMock <IQueryExecutor>();

            SetCheckDatabaseExistsValue(queryExecutor, settings, true);

            using (mocks.Record())
            {
                Expect.Call(() => taskObserver.Log("Running against: SQL Server"));
                Expect.Call(queryExecutor.ReadFirstColumnAsStringArray(settings, "select @@version")).Return(new string[] { "SQL Server" });
                connectionDropper.Drop(settings, taskObserver);
                queryExecutor.ExecuteNonQuery(settings, "ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [db]");
                Expect.Call(() => taskObserver.Log("Dropping database: db\n"));
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
                dropper.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 8
0
        public void Should_not_fail_if_datebase_does_not_exist()
        {
            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, null);

            var mocks             = new MockRepository();
            var connectionDropper = mocks.DynamicMock <IDatabaseConnectionDropper>();
            var taskObserver      = mocks.CreateMock <ITaskObserver>();
            var queryExecutor     = mocks.CreateMock <IQueryExecutor>();

            using (mocks.Record())
            {
                Expect.Call(() => queryExecutor.ExecuteNonQuery(settings, "ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [db]", false))
                .Throw(new Exception("foo message"));
                Expect.Call(() => taskObserver.Log("Database 'db' could not be dropped."));
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
                dropper.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 9
0
        public void Drops_database()
        {
            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, null);

            var mocks             = new MockRepository();
            var connectionDropper = mocks.CreateMock <IDatabaseConnectionDropper>();
            var taskObserver      = mocks.CreateMock <ITaskObserver>();
            var queryExecutor     = mocks.CreateMock <IQueryExecutor>();

            using (mocks.Record())
            {
                connectionDropper.Drop(settings, taskObserver);

                queryExecutor.ExecuteNonQuery(settings, "ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [db]", false);
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
                dropper.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 10
0
        public void Drops_Azure_database_without_dropping_connections()
        {
            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, null);

            var mocks             = new MockRepository();
            var connectionDropper = mocks.StrictMock <IDatabaseConnectionDropper>();
            var taskObserver      = mocks.StrictMock <ITaskObserver>();
            var queryExecutor     = mocks.StrictMock <IQueryExecutor>();

            using (mocks.Record())
            {
                Expect.Call(() => taskObserver.Log("Running against: SQL Azure"));
                Expect.Call(queryExecutor.ReadFirstColumnAsStringArray(settings, "select @@version")).Return(new string[] { "SQL Azure" });
                queryExecutor.ExecuteNonQuery(settings, "drop database [db]");
                Expect.Call(() => taskObserver.Log("Dropping database: db\n"));
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
                dropper.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 11
0
        public void Creates_database()
        {
            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, "c:\\scripts");

            taskAttributes.RequestedDatabaseAction = RequestedDatabaseAction.Create;
            var mocks         = new MockRepository();
            var queryExecutor = mocks.StrictMock <IQueryExecutor>();
            var executor      = mocks.StrictMock <IScriptFolderExecutor>();
            var taskObserver  = mocks.StrictMock <ITaskObserver>();

            using (mocks.Record())
            {
                queryExecutor.ExecuteNonQuery(settings, "create database [db]");
                taskObserver.Log(string.Format("Run scripts in Create folder."));
                executor.ExecuteScriptsInFolder(taskAttributes, "Create", taskObserver);
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor creator = new DatabaseCreator(queryExecutor, executor);
                creator.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 12
0
        public void Execute(TaskAttributes taskAttributes, ITaskObserver taskObserver)
        {
            string sql = string.Format("create database [{0}]", taskAttributes.ConnectionSettings.Database);

            _queryExecutor.ExecuteNonQuery(taskAttributes.ConnectionSettings, sql, false);

            _folderExecutor.ExecuteScriptsInFolder(taskAttributes, "ExistingSchema", taskObserver);
        }
Ejemplo n.º 13
0
        public void Execute(TaskAttributes taskAttributes, ITaskObserver taskObserver)
        {
            string sql = string.Format("create database [{0}]", taskAttributes.ConnectionSettings.Database);

            _queryExecutor.ExecuteNonQuery(taskAttributes.ConnectionSettings, sql);

            taskObserver.Log(string.Format("Run scripts in Create folder."));
            _folderExecutor.ExecuteScriptsInFolder(taskAttributes, "Create", taskObserver);
        }
Ejemplo n.º 14
0
        public string GetInitialMessage(TaskAttributes taskAttributes)
        {
            var scriptFolder = taskAttributes.RequestedDatabaseAction != RequestedDatabaseAction.Drop
                                                                                                                        ? string.Format(" using scripts from {0}", taskAttributes.ScriptDirectory)
                                                                                                                        : string.Empty;

            var logMessage = string.Format("{0} {1} on {2}{3}\n", taskAttributes.RequestedDatabaseAction, taskAttributes.ConnectionSettings.Database, taskAttributes.ConnectionSettings.Server, scriptFolder);

            return(logMessage);
        }
Ejemplo n.º 15
0
        public void Creates_initial_log_message_for_database_create()
        {
            ILogMessageGenerator generator = new LogMessageGenerator();

            var    settings       = new ConnectionSettings("server", "db", true, null, null);
            var    taskAttributes = new TaskAttributes(settings, "c:\\scripts");
            string message        = generator.GetInitialMessage(taskAttributes);

            Assert.That(message, Is.EqualTo("Create db on server using scripts from c:\\scripts\n"));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// <para>Runs AliaSQL against a database</para>
        /// <para>Default action is Update but it can be set to other AliaSQL actions</para>
        /// <para>Default script directory is ~/App_Data/scripts/ but it can bet set to any physical path</para>
        /// <para>-If database does not exist it will be created</para>
        /// <para>-Script directory path must exist</para>
        /// <para>Returns an object with a success boolean and a result string</para>
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="action"></param>
        /// <param name="scriptDirectory"></param>
        /// <returns>Returns an object with a success boolean and a result string</returns>
        public AliaSqlResult UpdateDatabase(string connectionString, RequestedDatabaseAction action = RequestedDatabaseAction.Update, string scriptDirectory = "")
        {
            if (scriptDirectory == "")
            {
                scriptDirectory = Path.Combine(AppDomain.CurrentDomain.GetData("DataDirectory").ToString(), "scripts");
            }

            if (!Directory.Exists(scriptDirectory))
            {
                throw new ArgumentException("There are no scripts in the defined data directory.");
            }

            if (action == RequestedDatabaseAction.Update && !PendingChanges(connectionString, scriptDirectory).Any())
            {
                return(new AliaSqlResult {
                    Result = "No pending changes", Success = true
                });
            }

            var result = new AliaSqlResult {
                Success = true
            };
            var manager = new SqlDatabaseManager();

            var taskAttributes = new TaskAttributes(_connectionStringGenerator.GetConnectionSettings(connectionString), scriptDirectory)
            {
                RequestedDatabaseAction = action,
            };

            try
            {
                manager.Upgrade(taskAttributes, this);
                foreach (var property in _properties)
                {
                    Log(property.Key + ": " + property.Value);
                }
                result.Result = sb.ToString();
            }
            catch (Exception exception)
            {
                result.Success = false;
                var ex = exception;
                do
                {
                    Log("Failure: " + ex.Message);
                    if (ex.Data["Custom"] != null)
                    {
                        Log(ex.Data["Custom"].ToString());
                    }
                    ex = ex.InnerException;
                } while (ex != null);
            }
            result.Result = sb.ToString();
            return(result);
        }
Ejemplo n.º 17
0
        public static byte PackAttrByte(bool isFinalData, bool expectReadFromTarget, bool expectWriteToTarget, TaskAttributes taskAttr)
        {
            byte value = 0;

            if (isFinalData) value |= 0x80;
            if (expectReadFromTarget) value |= 0x40;
            if (expectWriteToTarget) value |= 0x20;
            value |= (byte)((int)taskAttr & 0x3);

            return value;
        }
Ejemplo n.º 18
0
        public void ExecuteTestDataScriptsInFolder(TaskAttributes taskAttributes, string scriptDirectory, ITaskObserver taskObserver)
        {
            _schemaInitializer.EnsureTestDataSchemaCreated(taskAttributes.ConnectionSettings);

            var sqlFilenames = _fileLocator.GetSqlFilenames(taskAttributes.ScriptDirectory, scriptDirectory);

            foreach (string sqlFilename in sqlFilenames)
            {
                _testDataScriptExecutor.Execute(sqlFilename, taskAttributes.ConnectionSettings, taskObserver);
            }
        }
Ejemplo n.º 19
0
        public void ExecuteChangedScriptsInFolder(TaskAttributes taskAttributes, string scriptDirectory, ITaskObserver taskObserver)
        {
            var sqlFilenames = _fileLocator.GetSqlFilenames(taskAttributes.ScriptDirectory, scriptDirectory);

            foreach (string sqlFilename in sqlFilenames)
            {
                _scriptExecutor.ExecuteIfChanged(sqlFilename, taskAttributes.ConnectionSettings, taskObserver, taskAttributes.LogOnly);
            }

            _versioner.VersionDatabase(taskAttributes.ConnectionSettings, taskObserver);
        }
Ejemplo n.º 20
0
        public void Upgrade(TaskAttributes taskAttributes, ITaskObserver taskObserver)
        {
            string initializationMessage = _logMessageGenerator.GetInitialMessage(taskAttributes);

            taskObserver.Log(initializationMessage);

            IEnumerable <IDatabaseActionExecutor> executors = _actionExecutorFactory.GetExecutors(taskAttributes.RequestedDatabaseAction);

            foreach (IDatabaseActionExecutor executor in executors)
            {
                executor.Execute(taskAttributes, taskObserver);
            }
        }
Ejemplo n.º 21
0
        public void Creates_initial_log_message_for_database_drop()
        {
            ILogMessageGenerator generator = new LogMessageGenerator();

            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, "c:\\scripts")
            {
                RequestedDatabaseAction = RequestedDatabaseAction.Drop
            };
            string message = generator.GetInitialMessage(taskAttributes);

            Assert.That(message, Is.EqualTo("Drop db on server\n"));
        }
Ejemplo n.º 22
0
    public void AddUiTask(Task task)
    {
        if (numberOfTask >= 8)
        {
            return;
        }

        TaskAttributes taskAttr = Instantiate(TaskPrefab, List.transform).GetComponent <TaskAttributes>();

        PrefabList.Add(task.TaskId, taskAttr.gameObject);
        taskAttr.AddTaskAttributes(task);
        numberOfTask++;
    }
Ejemplo n.º 23
0
        public void Creates_initial_log_message_for_database_create_while_skiping_some_files()
        {
            ILogMessageGenerator generator = new LogMessageGenerator();

            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, "c:\\scripts")
            {
                SkipFileNameContaining = "_data_"
            };
            string message = generator.GetInitialMessage(taskAttributes);

            Assert.That(message, Is.EqualTo("Create db on server using scripts from c:\\scripts while skipping file containing _data_\n"));
        }
Ejemplo n.º 24
0
        public void Execute(TaskAttributes taskAttributes, ITaskObserver taskObserver)
        {
            _connectionDropper.Drop(taskAttributes.ConnectionSettings, taskObserver);
            var sql = string.Format("ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [{0}]", taskAttributes.ConnectionSettings.Database);

            try
            {
                _queryExecutor.ExecuteNonQuery(taskAttributes.ConnectionSettings, sql, false);
            }
            catch (Exception)
            {
                taskObserver.Log(string.Format("Database '{0}' could not be dropped.", taskAttributes.ConnectionSettings.Database));
            }
        }
Ejemplo n.º 25
0
        public string GetInitialMessage(TaskAttributes taskAttributes)
        {
            var scriptFolder = taskAttributes.RequestedDatabaseAction != RequestedDatabaseAction.Drop
                                                                                                                        ? string.Format(" using scripts from {0}", taskAttributes.ScriptDirectory)
                                                                                                                        : string.Empty;

            var skipFiles = !string.IsNullOrEmpty(taskAttributes.SkipFileNameContaining)
                                        ? string.Format(" while skipping file containing {0}", taskAttributes.SkipFileNameContaining)
                                        : string.Empty;

            var logMessage = string.Format("{0} {1} on {2}{3}{4}\n", taskAttributes.RequestedDatabaseAction, taskAttributes.ConnectionSettings.Database, taskAttributes.ConnectionSettings.Server, scriptFolder, skipFiles);

            return(logMessage);
        }
Ejemplo n.º 26
0
        public void ExecuteScriptsInFolder(TaskAttributes taskAttributes, string scriptDirectory, ITaskObserver taskObserver)
        {
            _schemaInitializer.EnsureSchemaCreated(taskAttributes.ConnectionSettings);

            var sqlFilenames = _fileLocator.GetSqlFilenames(taskAttributes.ScriptDirectory, scriptDirectory);

            var filteredFilenames = _fileFilterService.GetFilteredFilenames(sqlFilenames, taskAttributes.SkipFileNameContaining);

            foreach (string sqlFilename in filteredFilenames)
            {
                _scriptExecutor.Execute(sqlFilename, taskAttributes.ConnectionSettings, taskObserver);
            }

            _versioner.VersionDatabase(taskAttributes.ConnectionSettings, taskObserver);
        }
Ejemplo n.º 27
0
        public void Execute(TaskAttributes taskAttributes, ITaskObserver taskObserver)
        {
            if (!_queryExecutor.CheckDatabaseExists(taskAttributes.ConnectionSettings))
            {
                taskObserver.Log(string.Format("Database does not exist. Attempting to create database before updating."));
                string sql = string.Format("create database [{0}]", taskAttributes.ConnectionSettings.Database);
                _queryExecutor.ExecuteNonQuery(taskAttributes.ConnectionSettings, sql);
                taskObserver.Log(string.Format("Run scripts in Create folder."));
                _folderExecutor.ExecuteScriptsInFolder(taskAttributes, "Create", taskObserver);
            }
            taskObserver.Log(string.Format("Run scripts in Update folder."));
            _folderExecutor.ExecuteScriptsInFolder(taskAttributes, "Update", taskObserver);

            taskObserver.Log(string.Format("Run scripts in Everytime folder."));
            _folderExecutor.ExecuteChangedScriptsInFolder(taskAttributes, "Everytime", taskObserver);
        }
Ejemplo n.º 28
0
        public void Does_not_drop_missing_database()
        {
            var taskAttributes = new TaskAttributes(settings, null);

            var mocks = new MockRepository();

            var connectionDropper = mocks.StrictMock <IDatabaseConnectionDropper>();
            var taskObserver      = mocks.StrictMock <ITaskObserver>();
            var queryExecutor     = mocks.StrictMock <IQueryExecutor>();

            SetCheckDatabaseExistsValue(queryExecutor, settings, false);

            queryExecutor.Replay();

            IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);

            dropper.Execute(taskAttributes, taskObserver);

            queryExecutor.AssertWasCalled(qe => qe.CheckDatabaseExists(settings));
        }
Ejemplo n.º 29
0
        public void Updates_database()
        {
            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, "c:\\scripts");

            var mocks        = new MockRepository();
            var executor     = mocks.CreateMock <IScriptFolderExecutor>();
            var taskObserver = mocks.CreateMock <ITaskObserver>();

            using (mocks.Record())
            {
                executor.ExecuteScriptsInFolder(taskAttributes, "Update", taskObserver);
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor updater = new DatabaseUpdater(executor);
                updater.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
Ejemplo n.º 30
0
        protected override void ExecuteTask()
        {
            try
            {
                var manager        = new SqlDatabaseManager();
                var settings       = new ConnectionSettings(Server, Database, IntegratedAuthentication, Username, Password);
                var taskAttributes = new TaskAttributes(settings, ScriptDirectory.FullName)
                {
                    SkipFileNameContaining  = SkipFileNameContaining,
                    RequestedDatabaseAction = Action,
                };

                manager.Upgrade(taskAttributes, this);
            }
            catch
            {
                if (FailOnError)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 31
0
        public void LogsTestData()
        {
            var settings       = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, "c:\\scripts");

            taskAttributes.RequestedDatabaseAction = RequestedDatabaseAction.TestData;
            var mocks        = new MockRepository();
            var executor     = mocks.StrictMock <IScriptFolderExecutor>();
            var taskObserver = mocks.StrictMock <ITaskObserver>();

            using (mocks.Record())
            {
                executor.ExecuteTestDataScriptsInFolder(taskAttributes, "TestData", taskObserver);
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor testdata = new DatabaseTestData(executor);
                testdata.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }