Example #1
0
        /// <summary>
        /// Initialize "inline" tool window and grid with specified list of result items
        /// </summary>
        private BatchInlineToolWindow_Accessor InitBatchWindow(List <CodeReferenceResultItem> inlineList, out Dictionary <ProjectItem, int> sourceItemCounts, out int checkedCount)
        {
            BatchInlineToolWindow_Accessor window = new BatchInlineToolWindow_Accessor(new PrivateObject(new BatchInlineToolWindow()));

            window.SetData(inlineList);

            BatchInlineToolGrid grid = ((BatchInlineToolGrid)window.panel.Target);
            Random rnd = new Random();

            checkedCount     = 0;
            sourceItemCounts = new Dictionary <ProjectItem, int>();

            foreach (DataGridViewCheckedRow <CodeReferenceResultItem> row in grid.Rows)
            {
                bool check = rnd.Next(2) == 0;

                row.Cells[grid.CheckBoxColumnName].Value = check;
                if (check)
                {
                    checkedCount++;
                }

                if (!sourceItemCounts.ContainsKey(row.DataSourceItem.SourceItem))
                {
                    sourceItemCounts.Add(row.DataSourceItem.SourceItem, 0);
                }
                if (check)
                {
                    sourceItemCounts[row.DataSourceItem.SourceItem]++;
                }
            }

            grid.Sort(grid.Columns[rnd.Next(grid.Columns.Count)], rnd.Next(2) == 0 ? System.ComponentModel.ListSortDirection.Ascending : System.ComponentModel.ListSortDirection.Descending);

            return(window);
        }
Example #2
0
        /// <summary>
        /// Generic testing method
        /// </summary>
        /// <param name="fileOpened">True if files should be opened</param>
        /// <param name="referenceFiles">Files to test</param>
        /// <param name="correction">Number of string literals reported by the "batch move" command in the files</param>
        private void InternalFileTest(bool fileOpened, string[] referenceFiles, int correction)
        {
            // backup the files
            Dictionary <string, string> backups = CreateBackupsOf(referenceFiles);

            // open/close the files
            SetFilesOpened(referenceFiles, fileOpened);

            // run inline command in order to obtain result items
            List <CodeReferenceResultItem> inlineList = BatchInlineLookup(referenceFiles);

            // init the tool window and the grid
            int checkedCount;
            Dictionary <ProjectItem, int>  sourceItemsCounts;
            BatchInlineToolWindow_Accessor window = InitBatchWindow(inlineList, out sourceItemsCounts, out checkedCount);

            try {
                // run the command
                window.RunClick(null, null);
                VLDocumentViewsManager.CloseInvisibleWindows(typeof(BatchInlineCommand), false);

                // run "batch move" command
                List <CodeStringResultItem> moveList = BatchMoveLookup(referenceFiles);
                VLDocumentViewsManager.CloseInvisibleWindows(typeof(BatchMoveCommand), false);

                // the number of string literals found by the "batch move" command, minus the string literals that were
                // already there should be equal to the number of inlined result items
                Assert.AreEqual(checkedCount, moveList.Count - correction);

                // check correct value was inlined
                int i = 0, j = 0;
                for (; i < checkedCount;)
                {
                    while (!inlineList[i].MoveThisItem)
                    {
                        i++;
                    }
                    while (moveList[j].Value != inlineList[i].Value)
                    {
                        j++;
                    }

                    Assert.AreEqual(inlineList[i].Value, moveList[j].Value);
                    i++;
                    j++;
                }

                // use the undo manager to revert the changes
                if (fileOpened)
                {
                    foreach (string file in referenceFiles)
                    {
                        IOleUndoManager undoManager;
                        VLDocumentViewsManager.GetTextLinesForFile(file, false).GetUndoManager(out undoManager);

                        foreach (AbstractUndoUnit unit in undoManager.RemoveTopFromUndoStack(sourceItemsCounts[Agent.GetDTE().Solution.FindProjectItem(file)]))
                        {
                            unit.Undo();
                        }

                        Assert.AreEqual(File.ReadAllText(backups[file]), File.ReadAllText(file));
                    }
                }
            } finally {
                // close the files
                SetFilesOpened(referenceFiles, false);
                VLDocumentViewsManager.CloseInvisibleWindows(typeof(BatchInlineCommand), false);

                // restore backups
                RestoreBackups(backups);
            }
        }