public void CreateFakeTableShell(string schemaAndTableName, Boolean keepIdentity = false)
 {
     try
     {
         FakeTable.CreateShell(this.TargetServer, this.DatabaseName, schemaAndTableName, keepIdentity);
     }
     catch (Exception e)
     {
         throw new Exception($"CreateFakeTableShell failed for '{schemaAndTableName}' with the error: {e.Message}; Stacktace: {e.StackTrace}");
     }
 }
Beispiel #2
0
        internal static void CreateShell(Server server, string databaseName, string schemaAndTableName, Boolean keepIdentity = false)
        {
            string   schemaName = SqlTestTable.GetSchemaName(schemaAndTableName);
            string   tableName  = SqlTestTable.GetTableName(schemaAndTableName);
            Database database   = server.Databases[databaseName];

            if (database.Tables[$"{tableName}_Faked", schemaName] != null)
            {
                Console.WriteLine($"Table: {tableName} has already been faked, dropping and restoring...");
                FakeTable.Drop(server, databaseName, schemaAndTableName);
            }

            Table tableToFake = database.Tables[tableName, schemaName];

            if (tableToFake == null)
            {
                throw new Exception($"Error creating fake table:  Table not found: {schemaAndTableName}");
            }

            Table fakeTable = new Table(database, tableName, schemaName);

            foreach (Column column in tableToFake.Columns)
            {
                Column copyofCol = new Column(fakeTable, column.Name, column.DataType);
                if (keepIdentity)
                {
                    copyofCol.Identity = column.Identity;
                }
                if (column.DefaultConstraint != null)
                {
                    copyofCol.AddDefaultConstraint($"{column.DefaultConstraint.Name}_fake");
                    copyofCol.DefaultConstraint.Text = column.DefaultConstraint.Text;
                }
                fakeTable.Columns.Add(copyofCol);
            }

            try
            {
                tableToFake.Rename($"{tableName}_Faked");
                fakeTable.Create();
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to create fake table '{schemaAndTableName}': {e.Message}");
            }
        }
        public object DropFakeTable(string schemaAndTableName, string getActualSql = "")
        {
            object result = "";

            try
            {
                if (!String.IsNullOrEmpty(getActualSql))
                {
                    result = GetActual(getActualSql);
                }
                FakeTable.Drop(this.TargetServer, this.DatabaseName, schemaAndTableName);
            }
            catch (Exception e)
            {
                throw new Exception($"DropFakeTable failed for '{schemaAndTableName}' with the Error: {e.Message}; Stacktrace: '{e.StackTrace}'");
            }

            return(result);
        }