public void Run_should_leave_schema_unchanged_if_migration_script_throws_exception_when_migrating_down() { // arrange _mockMigrationScripts.Add(_mockScriptWithBadTeardown.Object); // migrate up first _migrateCommand.Run(_commandArgs); _commandArgs.TargetVersion = 0; // act try { _migrateCommand.Run(_commandArgs); } catch (MigrationException) { } // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar<long>(SelectMaxVersionSql); Assert.AreEqual(4, version, "schema version doesn't match the original schema version"); var testTableCount = sql.ExecuteScalar<int>("select count(*) from information_schema.tables where table_name='TestTable'"); Assert.AreEqual(1, testTableCount, "schema changed"); } }
public void Run_should_call_MigrateCommand_Execute_if_there_is_a_previous_version_to_rollback_to() { // arrange InitializeDatabase(); // insert some version numbers using (var sql = new SqlDatabaseHelper(TestConnectionString)) { sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1)"); } bool runCalled = false; _mockMigrateCommand.Protected().Setup("Execute", ItExpr.IsAny<MigrateCommandArgs>()).Callback(() => runCalled = true); // act _rollbackCommand.Run(_commandArgs); // assert Assert.IsTrue(runCalled); }
public void ExecuteScript_should_perform_case_insensitive_replace_DNM_PROVIDER_token_in_script_with_the_current_ADO_provider_name() { // arrange using (var helper = new SqlDatabaseHelper(TestConnectionString)) { helper.ExecuteNonQuery("CREATE TABLE [providers] ([name] [nvarchar](100))"); // act _subject.OpenConnection(); using (var tran = _subject.BeginTransaction()) { _subject.ExecuteScript(tran, "INSERT INTO [providers] ([name]) VALUES ('/*dNm:PrOvIdEr*/')"); tran.Commit(); } // assert var providerNameInserted = helper.ExecuteScalar<string>("SELECT [name] FROM [providers]"); Assert.AreEqual("System.Data.SqlServerCe.4.0", providerNameInserted); } }
public void Run_should_set_MigrateCommand_Log_to_its_own_Log() { // arrange InitializeDatabase(); // insert some version numbers using (var sql = new SqlDatabaseHelper(TestConnectionString)) { sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1)"); } // act _rollbackCommand.Run(_commandArgs); // assert Assert.AreSame(_rollbackCommand.Log, _mockMigrateCommand.Object.Log); }
public void Run_should_set_MigrateCommandArgs_TargetVersion_to_previous_schema_version_in_schema_migrations_table() { // arrange InitializeDatabase(); // insert some version numbers using (var sql = new SqlDatabaseHelper(TestConnectionString)) { sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (3)"); sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (1)"); sql.ExecuteNonQuery("insert into [schema_migrations] ([version]) values (2)"); } _mockMigrateCommand.Protected().Setup("Execute", ItExpr.IsAny<MigrateCommandArgs>()) .Callback((MigrateCommandArgs args) => Assert.AreEqual(2, args.TargetVersion)); // act _rollbackCommand.Run(_commandArgs); // assert _mockMigrateCommand.Verify(); }
public void Run_should_rollback_all_migrations_if_TargetVersion_is_0() { // arrange // migrate up first _migrateCommand.Run(_commandArgs); _commandArgs.TargetVersion = 0; // act _migrateCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar<long>(SelectMaxVersionSql); Assert.AreEqual(0, version, "schema version doesn't match TargetVersion"); var testTableCount = sql.ExecuteScalar<int>("select count(*) from information_schema.tables where table_name='TestTable'"); Assert.AreEqual(0, testTableCount, "not all migration scripts were run as expected"); } }
public void Run_should_migrate_up_to_TargetVersion_if_greater_than_current_schema_version() { // arrange // migrate to version 1 first _commandArgs.TargetVersion = 1; _migrateCommand.Run(_commandArgs); _commandArgs.TargetVersion = 2; // act _migrateCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar<long>(SelectMaxVersionSql); Assert.AreEqual(2, version, "schema version doesn't match TargetVersion"); var testTableId = sql.ExecuteScalar<int>("select max(Id) from [TestTable]"); Assert.AreEqual(2, testTableId, "not all migration scripts were run as expected"); } }
public void Run_should_migrate_to_latest_script_version_if_no_TargetVersion_is_given() { // arrange // act _migrateCommand.Run(_commandArgs); // assert using (var sql = new SqlDatabaseHelper(TestConnectionString)) { var version = sql.ExecuteScalar<long>( "select max(version) from schema_migrations"); Assert.AreEqual(2, version, "schema version doesn't match latest script version"); var testTableId = sql.ExecuteScalar<int>("select max(Id) from [TestTable]"); Assert.AreEqual(2, testTableId, "not all migration scripts were run as expected"); } }
public DataSet GetEmployeeOffWorkByApprovalStatus(int iEmployeeID, string sApprovalStatus, string sStatus = "Alive") { return(SqlDatabaseHelper.RunStoredProcedure("spl_GetDataEmployeeOffWorkByEmployeeID", iEmployeeID, sApprovalStatus, sStatus)); }
public virtual void InvalidateSearchResultsControl(object sender, String strEventName) { try { Cursor.Current = Cursors.WaitCursor; VinaDbUtil dbUtil = new VinaDbUtil(); String strMainTableName = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject); string mainTablePrimaryColumn = dbUtil.GetTablePrimaryColumn(strMainTableName); BaseBusinessController objMainObjectController = BusinessControllerFactory.GetBusinessController(strMainTableName + "Controller"); //Invalidate toolbar collection PropertyInfo[] properties; DataRow newRow; String strMainObjectTableName = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject); int iObjectID = Convert.ToInt32(dbUtil.GetPropertyValue(CurrentModuleEntity.MainObject, SqlDatabaseHelper.GetPrimaryKeyColumn(strMainObjectTableName))); if (Toolbar.ObjectCollection == null) { DataSet ds = objMainObjectController.GetDataSetByID(iObjectID); Toolbar.SetToolbar(ds); } else { //if Toolbar.ModusAction is new, add new object to object collection of toolbar if (Toolbar.ModuleAction == BaseToolbar.ModuleNew) { newRow = Toolbar.ObjectCollection.Tables[0].NewRow(); newRow = objMainObjectController.GetDataRowFromBusinessObject(newRow, CurrentModuleEntity.MainObject); Toolbar.ObjectCollection.Tables[0].Rows.Add(newRow); Toolbar.CurrentIndex = Toolbar.ObjectCollection.Tables[0].Rows.Count - 1; } else { //Update object in object collection of toolbar properties = CurrentModuleEntity.MainObject.GetType().GetProperties(); int iCurrIndex = Toolbar.CurrentIndex; for (int i = 0; i < properties.Length; i++) { if (Toolbar.ObjectCollection.Tables[0].Columns[properties[i].Name] != null) { Toolbar.ObjectCollection.Tables[0].Rows[iCurrIndex][properties[i].Name] = properties[i].GetValue(CurrentModuleEntity.MainObject, null); } } } } //Invalidate search result control Control searchResultControl = null; foreach (Control ctrl in Controls.Values) { if (ctrl.Tag == VinaScreen.SearchResultControl) { searchResultControl = ctrl; break; } } if (searchResultControl != null) { if (searchResultControl is GridControl) { VinaSearchResultsGridControl gridControl = searchResultControl as VinaSearchResultsGridControl; GridView gridView = gridControl.Views[0] as GridView; if (gridControl.DataSource == null) { VinaSearchResultsGridControl.BindingSearchResultGridControl(gridControl, Toolbar.ObjectCollection); } //gridControl.InvalidateLookupEditColumns(); gridView.RefreshData(); gridView.FocusedRowHandle = gridView.GetRowHandle(Toolbar.CurrentIndex); } } } catch (Exception) { } }