public void DoesNotRewriteColumnReferences()
        {
            var script = @" select abc, def, abc from dbo.tableaaa
	        order by abc, def /*jkjkjj*/
	   ";
            var rewriter = new OrderByOrdinalRewrites();

            var replacements = rewriter.GetReplacements(ScriptDom.ScriptDom.GetQuerySpecifications(script));
            Assert.AreEqual(0, replacements.Count);
        }
        public override GlyphDefinition GetDefintions(string fragment, TSqlStatement statement, GlyphDefinition definition, List<QuerySpecification> queries)
        {
            var rewriter = new OrderByOrdinalRewrites();
            var replacements = rewriter.GetReplacements(queries);

            if (replacements == null)
                return definition;

            if (replacements.Count > 0)
            {
                definition.Menu.Add(new MenuDefinition()
                {
                    Caption = "Replace Ordinals in Order By",
                    Action = () => { },
                    Type = MenuItemType.Header
                    ,
                    Glyph = definition
                });

                var offsettedReplacments = new List<Replacements>();
                foreach (var replacement in replacements)
                {
                    var replacement1 = replacement;
                    replacement1.OriginalOffset += statement.StartOffset;
                    offsettedReplacments.Add(replacement1);
                }

                if (replacements.Count > 1)
                {
                    var menu = new MenuDefinition();
                    menu.Operation = new ClippyReplacementOperations(offsettedReplacments);
                    menu.Action = () => PerformAction(menu.Operation, menu.Glyph);

                    menu.Glyph = definition;
                    menu.Caption = GetCaptionForAll(statement);
                    menu.Type = MenuItemType.MenuItem;
                    definition.Menu.Add(menu);
                }


                foreach (var replacement in offsettedReplacments)
                {
                    var menu = new MenuDefinition();
                    menu.Action = () => PerformAction(menu.Operation, menu.Glyph);
                    menu.Glyph = definition;
                    menu.Caption = string.Format("\t\"{0}\" into \"{1}\"", replacement.Original, replacement.Replacement);
                    menu.Type = MenuItemType.MenuItem;
                    menu.Operation = new ClippyReplacementOperation(replacement);
                    definition.Menu.Add(menu);
                }

                definition.GenerateKey();
            }
            return definition;
        }
        public void DoesNotRewriteOrdinalsWithSelectStarBeforePosition()
        {
            var script = @" select *, abc from dbo.tableaaa
	        order by 1
	   ";
            var rewriter = new OrderByOrdinalRewrites();

            var replacements = rewriter.GetReplacements(ScriptDom.ScriptDom.GetQuerySpecifications(script));
            Assert.IsNull(replacements);
            
        }
        public void DoesRewriteOrdinalsWithSelectStarAfterPosition()
        {
            var script = @" select abc, *, abc from dbo.tableaaa
	        order by 1
	   ";
            var rewriter = new OrderByOrdinalRewrites();

            var replacements = rewriter.GetReplacements(ScriptDom.ScriptDom.GetQuerySpecifications(script));
            Assert.IsNotNull(replacements);
            Assert.AreEqual(1, replacements.Count);
            Assert.AreEqual("abc", replacements.FirstOrDefault().Replacement);

        }
        public void DoesRewriteOrdinals()
        {
            var script = @" select abc, def, abc from dbo.tableaaa
	        order by 2,/*jkjkjj*/3
	   ";
            var rewriter = new OrderByOrdinalRewrites();

            var replacements = rewriter.GetReplacements(ScriptDom.ScriptDom.GetQuerySpecifications(script));
            Assert.IsNotNull(replacements);
            Assert.AreEqual(2, replacements.Count);
            Assert.AreEqual("def", replacements.FirstOrDefault().Replacement);
            Assert.AreEqual("abc", replacements.LastOrDefault().Replacement);

        }