Esempio n. 1
0
        public void TestIgnore()
        {
            CodeSweep.VSPackage.TaskProvider_Accessor accessor = new CodeSweep.VSPackage.TaskProvider_Accessor(_serviceProvider);

            Project project = Utilities.SetupMSBuildProject();

            Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            MockTermTable  table      = new MockTermTable("termtable.xml");
            MockTerm       term0      = new MockTerm("dupText", 0, "term0Class", "term0Comment", "term0recommended", table);
            MockTerm       term1      = new MockTerm("term2Text", 2, "term2Class", "term2Comment", "term2recommended", table);
            MockScanHit    hit0       = new MockScanHit("file0", 1, 5, "line text", term0, null);
            MockScanHit    hit1       = new MockScanHit("file1", 4, 1, "line text 2", term1, null);
            MockScanHit    hit2       = new MockScanHit("file2", 3, 2, "line text 3", term1, null);
            MockScanResult scanResult = new MockScanResult("file0", new IScanHit[] { hit0, hit1, hit2 }, true);

            accessor.AddResult(scanResult, project.FullPath);

            IVsEnumTaskItems enumerator = null;

            accessor.EnumTaskItems(out enumerator);
            List <IVsTaskItem> items = Utilities.TasksFromEnumerator(enumerator);

            CodeSweep.VSPackage.Task_Accessor task0Accessor = new CodeSweep.VSPackage.Task_Accessor(new PrivateObject(items[0]));
            CodeSweep.VSPackage.Task_Accessor task1Accessor = new CodeSweep.VSPackage.Task_Accessor(new PrivateObject(items[1]));

            MockTaskList taskList = _serviceProvider.GetService(typeof(SVsTaskList)) as MockTaskList;

            // Ensure cmd is disabled with no selection
            OleMenuCommandService mcs     = _serviceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            MenuCommand           command = mcs.FindCommand(new CommandID(CodeSweep.VSPackage.GuidList_Accessor.guidVSPackageCmdSet, (int)CodeSweep.VSPackage.PkgCmdIDList_Accessor.cmdidIgnore));

            // NOTE: simply getting command.Supported or command.Enabled doesn't seem to invoke
            // QueryStatus, so I'll explicitly call the status update method as a workaround.
            accessor.QueryIgnore(null, EventArgs.Empty);

            Assert.IsTrue(command.Supported, "Command not supported.");
            Assert.IsFalse(command.Enabled, "Command enabled with no selection.");

            // Ensure cmd is disabled with an ignored item selected
            task0Accessor.Ignored = true;
            taskList.SetSelected(items[0], true);
            accessor.QueryIgnore(null, EventArgs.Empty);
            Assert.IsFalse(command.Enabled, "Command enabled with ignored item selected.");

            // Ensure cmd is enabled with one ignored and one non-ignored item selected
            taskList.SetSelected(items[1], true);
            accessor.QueryIgnore(null, EventArgs.Empty);
            Assert.IsTrue(command.Enabled, "Command disabled with a non-ignored item selected.");

            // Fire cmd, ensure selected items are ignored
            command.Invoke();
            accessor.QueryIgnore(null, EventArgs.Empty);
            Assert.IsTrue(task0Accessor.Ignored, "Command set ignored task to non-ignored.");
            Assert.IsTrue(task1Accessor.Ignored, "Command did not set non-ignored task to ignored.");

            // Ensure cmd is now disabled
            accessor.QueryIgnore(null, EventArgs.Empty);
            Assert.IsFalse(command.Enabled, "Command still enabled after invocation.");
        }
Esempio n. 2
0
        public void AddResultsThenClear()
        {
            CodeSweep.VSPackage.TaskProvider_Accessor accessor = new CodeSweep.VSPackage.TaskProvider_Accessor(_serviceProvider);

            // Add some tasks
            MockTermTable  table      = new MockTermTable("termtable.xml");
            MockTerm       term0      = new MockTerm("term0Text", 0, "term0Class", "term0Comment", "term0recommended", table);
            MockTerm       term1      = new MockTerm("term1Text", 3, "term1Class", "term1Comment", "term1recommended", table);
            MockScanHit    hit0       = new MockScanHit("file0", 1, 10, "line text", term0, null);
            MockScanHit    hit1       = new MockScanHit("file1", 4, 1, "line text 2", term1, null);
            MockScanResult scanResult = new MockScanResult("file0", new IScanHit[] { hit0, hit1 }, true);

            accessor.AddResult(scanResult, "c:\\projFile");

            IVsEnumTaskItems enumerator;
            int hr = accessor.EnumTaskItems(out enumerator);

            Assert.AreEqual(VSConstants.S_OK, hr, "EnumTaskItems returned wrong hresult.");

            List <IVsTaskItem> tasks = Utilities.TasksFromEnumerator(enumerator);

            Assert.AreEqual(2, tasks.Count, "EnumTaskItems did not enumerate correct number of tasks.");

            accessor.Clear();

            hr = accessor.EnumTaskItems(out enumerator);

            Assert.AreEqual(VSConstants.S_OK, hr, "EnumTaskItems returned wrong hresult.");

            tasks = Utilities.TasksFromEnumerator(enumerator);
            Assert.AreEqual(0, tasks.Count, "EnumTaskItems did not enumerate correct number of tasks after Clear().");
        }
        public void AddResultTest()
        {
            CodeSweep.VSPackage.ScannerHost_Accessor accessor = new CodeSweep.VSPackage.ScannerHost_Accessor(_serviceProvider);

            MockTermTable  table      = new MockTermTable("scannedFile");
            MockTerm       term       = new MockTerm("term text", 0, "term class", "term comment", "recommended", table);
            MockScanHit    hit        = new MockScanHit("scannedFile", 5, 6, "line text", term, null);
            MockScanResult scanResult = new MockScanResult("scannedFile", new IScanHit[] { hit }, true);

            List <int>   resultCounts = new List <int>();
            MockTaskList taskList     = _serviceProvider.GetService(typeof(SVsTaskList)) as MockTaskList;

            taskList.OnRefreshTasks += delegate(object sender, MockTaskList.RefreshTasksArgs args)
            {
                resultCounts.Add(Utilities.TasksOfProvider(args.Provider).Count);
            };

            accessor.AddResult(scanResult, "c:\\projFile");

            Assert.AreEqual(1, resultCounts.Count, "Task list was not updated by AddResult.");
            Assert.AreEqual(1, resultCounts[0], "Refresh did not enumerate one task.");
        }
Esempio n. 4
0
        public void TestEnumerator()
        {
            CodeSweep.VSPackage.TaskProvider_Accessor accessor = new CodeSweep.VSPackage.TaskProvider_Accessor(_serviceProvider);

            // Add some tasks
            MockTermTable  table      = new MockTermTable("termtable.xml");
            MockTerm       term0      = new MockTerm("term0Text", 0, "term0Class", "term0Comment", "term0recommended", table);
            MockTerm       term1      = new MockTerm("term1Text", 3, "term1Class", "term1Comment", "term1recommended", table);
            MockScanHit    hit0       = new MockScanHit("file0", 1, 10, "line text", term0, null);
            MockScanHit    hit1       = new MockScanHit("file1", 4, 1, "line text 2", term1, null);
            MockScanResult scanResult = new MockScanResult("file0", new IScanHit[] { hit0, hit1 }, true);

            accessor.AddResult(scanResult, "c:\\projFile");

            IVsEnumTaskItems enumerator;
            int hr = accessor.EnumTaskItems(out enumerator);

            Assert.AreEqual(VSConstants.S_OK, hr, "EnumTaskItems returned wrong hresult.");

            IVsTaskItem[] items = new IVsTaskItem[3] {
                null, null, null
            };
            uint[] fetched = new uint[1] {
                0
            };
            hr = enumerator.Next(3, items, fetched);
            Assert.AreEqual(VSConstants.S_FALSE, hr, "Next returned wrong hresult with celt too high.");
            Assert.AreEqual((uint)2, fetched[0], "Next returned wrong value for fetched with celt too high.");
            Assert.IsNotNull(items[0], "Next failed to set first item with celt too high.");
            Assert.IsNotNull(items[1], "Next failed to set second item with celt too high.");
            Assert.IsNull(items[2], "Next set third item with celt too high.");

            hr = enumerator.Reset();
            Assert.AreEqual(VSConstants.S_OK, hr, "Reset returned wrong hresult.");

            items[0]   = items[1] = items[2] = null;
            fetched[0] = 0;
            hr         = enumerator.Next(2, items, fetched);
            Assert.AreEqual(VSConstants.S_OK, hr, "Next returned wrong hresult with celt at max.");
            Assert.AreEqual((uint)2, fetched[0], "Next returned wrong value for fetched with celt at max.");
            Assert.IsNotNull(items[0], "Next failed to set first item with celt at max.");
            Assert.IsNotNull(items[1], "Next failed to set second item with celt at max.");

            enumerator.Reset();

            items[0]   = items[1] = items[2] = null;
            fetched[0] = 0;
            hr         = enumerator.Next(1, items, fetched);
            Assert.AreEqual(VSConstants.S_OK, hr, "Next returned wrong hresult with celt lower than max.");
            Assert.AreEqual((uint)1, fetched[0], "Next returned wrong value for fetched with celt lower than max.");
            Assert.IsNotNull(items[0], "Next failed to set first item with celt lower than max.");
            Assert.IsNull(items[1], "Next set second item with celt lower than max.");

            enumerator.Reset();

            items[0]   = items[1] = items[2] = null;
            fetched[0] = 1;
            hr         = enumerator.Next(0, items, fetched);
            Assert.AreEqual(VSConstants.S_OK, hr, "Next returned wrong hresult with celt = 0.");
            Assert.AreEqual((uint)0, fetched[0], "Next returned wrong value for fetched with celt = 0.");
            Assert.IsNull(items[0], "Next set first item with celt = 0.");

            enumerator.Reset();

            hr = enumerator.Skip(0);
            Assert.AreEqual(VSConstants.S_OK, hr, "Skip(0) returned wrong hresult.");

            hr = enumerator.Skip(1);
            Assert.AreEqual(VSConstants.S_OK, hr, "Skip(1) returned wrong hresult.");

            hr = enumerator.Skip(2);
            Assert.AreEqual(VSConstants.S_FALSE, hr, "Skip(2) returned wrong hresult.");

            List <IVsTaskItem> tasks = Utilities.TasksFromEnumerator(enumerator);

            IVsEnumTaskItems enumerator2 = null;

            hr = enumerator.Clone(out enumerator2);
            Assert.AreEqual(VSConstants.S_OK, hr, "Clone returned wrong hresult.");

            List <IVsTaskItem> tasks2 = Utilities.TasksFromEnumerator(enumerator2);

            Assert.IsTrue(CodeSweep.Utilities.OrderedCollectionsAreEqual(tasks, tasks2), "Clone did not produce an equivalent collection.");
        }
Esempio n. 5
0
        public void AddDuplicateTermsAndVerifyWarningAppearsOnce()
        {
            CodeSweep.VSPackage.TaskProvider_Accessor accessor = new CodeSweep.VSPackage.TaskProvider_Accessor(_serviceProvider);

            MockTermTable  table      = new MockTermTable("termtable.xml");
            MockTerm       term0      = new MockTerm("dupText", 0, "term0Class", "term0Comment", "term0recommended", table);
            MockTerm       term1      = new MockTerm("dupText", 3, "term1Class", "term1Comment", "term1recommended", table);
            MockTerm       term2      = new MockTerm("term2Text", 2, "term2Class", "term2Comment", "term2recommended", table);
            MockScanHit    hit0       = new MockScanHit("file0", 1, 10, "line text", term0, "warning 1");
            MockScanHit    hit1       = new MockScanHit("file1", 4, 1, "line text 2", term1, "warning 2");
            MockScanHit    hit2       = new MockScanHit("file2", 3, 2, "line text 3", term2, "warning 3");
            MockScanResult scanResult = new MockScanResult("file0", new IScanHit[] { hit0, hit1, hit2 }, true);

            accessor.AddResult(scanResult, "c:\\projFile");

            IVsEnumTaskItems enumerator;
            int hr = accessor.EnumTaskItems(out enumerator);

            Assert.AreEqual(VSConstants.S_OK, hr, "EnumTaskItems returned wrong hresult.");

            // Verify there are three hits plus two warnings.
            List <IVsTaskItem> tasks = Utilities.TasksFromEnumerator(enumerator);

            Assert.AreEqual(5, tasks.Count, "EnumTaskItems did not enumerate correct number of tasks.");

            string[] termValues = new string[5] {
                "dupText", "dupText", "dupText", "term2Text", "term2Text"
            };
            int[] priorityValues = new int[5] {
                0, 0, 3, 2, 2
            };
            string[] classValues = new string[5] {
                "term0Class", "term0Class", "term1Class", "term2Class", "term2Class"
            };
            string[] replacementValues = new string[5] {
                "", "term0recommended", "term1recommended", "", "term2recommended"
            };
            string[] commentValues = new string[5] {
                "warning 1", "term0Comment", "term1Comment", "warning 3", "term2Comment"
            };
            string[] fileValues = new string[5] {
                "", "file0", "file1", "", "file2"
            };

            for (int taskIndex = 0; taskIndex < tasks.Count; ++taskIndex)
            {
                uint   type;
                object val;
                uint   flags;
                string acc;

                hr = (tasks[taskIndex] as IVsTaskItem3).GetColumnValue((int)TaskFields.Term, out type, out flags, out val, out acc);
                Assert.AreEqual(VSConstants.S_OK, hr);
                Assert.AreEqual(__VSTASKVALUETYPE.TVT_TEXT, (__VSTASKVALUETYPE)type, "Task " + taskIndex.ToString() + " term type is wrong.");
                Assert.AreEqual(termValues[taskIndex], (string)val, "Task " + taskIndex.ToString() + " term text is wrong.");

                hr = (tasks[taskIndex] as IVsTaskItem3).GetColumnValue((int)TaskFields.Comment, out type, out flags, out val, out acc);
                Assert.AreEqual(VSConstants.S_OK, hr);
                Assert.AreEqual(__VSTASKVALUETYPE.TVT_LINKTEXT, (__VSTASKVALUETYPE)type, "Task " + taskIndex.ToString() + " comment type is wrong.");
                Assert.AreEqual(commentValues[taskIndex], (string)val, "Task " + taskIndex.ToString() + " comment text is wrong.");

                hr = (tasks[taskIndex] as IVsTaskItem3).GetColumnValue((int)TaskFields.Replacement, out type, out flags, out val, out acc);
                Assert.AreEqual(VSConstants.S_OK, hr);
                Assert.AreEqual(__VSTASKVALUETYPE.TVT_TEXT, (__VSTASKVALUETYPE)type, "Task " + taskIndex.ToString() + " replacement type is wrong.");
                Assert.AreEqual(replacementValues[taskIndex], (string)val, "Task " + taskIndex.ToString() + " replacement text is wrong.");
            }
        }