public void RefactorTableName_IsRefactorable_ExtractionInformation(string transformSql, bool expectedToBeRefactorable)
        {
            var ei = WhenIHaveA <ExtractionInformation>();

            ei.SelectSQL = transformSql;
            ei.Alias     = "MyCatalogueItem";
            ei.SaveToDatabase();

            var ci = ei.ColumnInfo;

            ci.Name = "[database]..[table].[column]";
            ci.SaveToDatabase();

            var tableInfo = ei.ColumnInfo.TableInfo;

            tableInfo.Database = "database";
            tableInfo.Name     = "[database]..[table]";
            tableInfo.SaveToDatabase();

            var refactorer = new SelectSQLRefactorer();

            Assert.AreEqual(expectedToBeRefactorable, refactorer.IsRefactorable(ei));

            if (expectedToBeRefactorable)
            {
                refactorer.RefactorTableName(ei, tableInfo, "[database]..[table2]");
            }
            else
            {
                Assert.Throws <RefactoringException>(() => refactorer.RefactorTableName(ei, tableInfo, "[database]..[table2]"));
            }
        }
        public void RefactorTableName_TestValidReplacement_ExtractionInformation()
        {
            var ei = WhenIHaveA <ExtractionInformation>();

            ei.SelectSQL = "UPPER([database]..[table].[column])";
            ei.Alias     = "MyCatalogueItem";
            ei.SaveToDatabase();

            var ci = ei.ColumnInfo;

            ci.Name = "[database]..[table].[column]";
            ci.SaveToDatabase();

            var tableInfo = ei.ColumnInfo.TableInfo;

            tableInfo.Database = "database";
            tableInfo.Name     = "[database]..[table]";
            tableInfo.SaveToDatabase();

            var refactorer = new SelectSQLRefactorer();

            refactorer.RefactorTableName(ei, tableInfo, "[database]..[table2]");

            Assert.AreEqual("UPPER([database]..[table2].[column])", ei.SelectSQL);
        }
Esempio n. 3
0
        private void DoRefactoring(string toReplace, string toReplaceWith)
        {
            var refactorer = new SelectSQLRefactorer();

            int updatesMade = refactorer.RefactorTableName(_tableInfo, toReplace, toReplaceWith);

            MessageBox.Show("Made " + updatesMade + " replacements in ExtractionInformation/ColumnInfos.");
        }
Esempio n. 4
0
        public void RefactorTableName_IsRefactorable_ColumnInfo(string columnTable, string findTableName)
        {
            var col = WhenIHaveA <ColumnInfo>();

            col.Name = columnTable + "[MyTbl].[A]";
            col.SaveToDatabase();

            var refactorer = new SelectSQLRefactorer();

            Assert.AreEqual(1, refactorer.RefactorTableName(col, findTableName + "[MyTbl].[A]", findTableName + "[MyTbl2].[A]"));

            Assert.AreEqual(findTableName + "[MyTbl2].[A]", col.Name);
        }
        public override void Execute()
        {
            base.Execute();

            if (TypeText("Rename Table (in database)", "New Name:", 500, TableInfo.GetRuntimeName(), out string newName, true))
            {
                //rename the underlying table
                Table.Rename(newName);

                var newNameFullyQualified = Table.Database.ExpectTable(newName, TableInfo.Schema).GetFullyQualifiedName();
                _refactorer.RefactorTableName(TableInfo, newNameFullyQualified);
            }

            Publish(TableInfo);
        }
        public void RefactorTableName_IsRefactorable_ColumnInfo(string columnName, string findTableName)
        {
            var col = WhenIHaveA <ColumnInfo>();

            col.Name = columnName;
            col.SaveToDatabase();

            var refactorer = new SelectSQLRefactorer();

            var oldName = findTableName;
            var newName = oldName.Replace("MyTbl", "MyNewTbl");

            Assert.AreEqual(1, refactorer.RefactorTableName(col, oldName, newName));

            Assert.AreEqual(newName + ".[A]", col.Name);
        }
        public void RefactorTableName_TestValidReplacement_ColumnInfo()
        {
            var columnInfo = WhenIHaveA <ColumnInfo>();

            columnInfo.Name = "[database]..[table].[column]";

            var tableInfo = columnInfo.TableInfo;

            tableInfo.Database = "database";
            tableInfo.Name     = "[database]..[table]";

            var refactorer = new SelectSQLRefactorer();

            refactorer.RefactorTableName(columnInfo, tableInfo, "[database]..[table2]");

            Assert.AreEqual("[database]..[table2].[column]", columnInfo.Name);
        }
        public void RefactorTableName_IsRefactorable_TableInfoWithNoColumnInfos(string oldName, string newName)
        {
            var ti = WhenIHaveA <TableInfo>();

            ti.Name     = oldName;
            ti.Database = "Fish";
            ti.SaveToDatabase();

            foreach (IDeleteable d in ti.ColumnInfos)
            {
                d.DeleteInDatabase();
            }

            var refactorer = new SelectSQLRefactorer();

            Assert.IsTrue(refactorer.IsRefactorable(ti));

            Assert.AreEqual(1, refactorer.RefactorTableName(ti, newName));
            Assert.AreEqual(newName, ti.Name);
        }
        public void RefactorTableName_IsNotRefactorable_TableInfoWithNoColumnInfos(string oldName, string newName, string expectedReason)
        {
            var ti = WhenIHaveA <TableInfo>();

            ti.Name     = oldName;
            ti.Database = "Fish";
            ti.SaveToDatabase();

            foreach (IDeleteable d in ti.ColumnInfos)
            {
                d.DeleteInDatabase();
            }

            var refactorer = new SelectSQLRefactorer();

            Assert.IsFalse(refactorer.IsRefactorable(ti));

            var ex = Assert.Throws <RefactoringException>(() => refactorer.RefactorTableName(ti, newName));

            StringAssert.Contains(expectedReason, ex.Message);
        }