Example #1
0
        public void StopStopsScanBeforeNextFile()
        {
            CodeSweep.VSPackage.BackgroundScanner_Accessor accessor = GetScanner();

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

            taskList.OnRefreshTasks +=
                delegate(object sender, MockTaskList.RefreshTasksArgs args)
            {
                ++refreshes;
            };

            string         firstFile  = Utilities.CreateBigFile();
            string         secondFile = Utilities.CreateTempTxtFile("bar bar bar floop doop bar");
            string         termTable  = Utilities.CreateTermTable(new string[] { "foo", "bar" });
            Project        project    = Utilities.SetupMSBuildProject(new string[] { firstFile, secondFile }, new string[] { termTable });
            MockIVsProject vsProject  = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            accessor.Start(new IVsProject[] { vsProject });
            accessor.StopIfRunning(true);

            // There should be one update, when the task list was initially cleared.
            Assert.AreEqual(1, refreshes, "Stop did not stop scan before next file.");
        }
Example #2
0
        public void TaskListIsUpdated()
        {
            CodeSweep.VSPackage.BackgroundScanner_Accessor accessor = GetScanner();

            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);
            };

            string         firstFile  = Utilities.CreateTempTxtFile("foo abc foo def foo");
            string         secondFile = Utilities.CreateTempTxtFile("bar bar bar floop doop bar");
            string         termTable1 = Utilities.CreateTermTable(new string[] { "foo", "bar" });
            string         termTable2 = Utilities.CreateTermTable(new string[] { "floop" });
            Project        project1   = Utilities.SetupMSBuildProject(new string[] { firstFile, secondFile }, new string[] { termTable1, termTable2 });
            MockIVsProject vsProject1 = Utilities.RegisterProjectWithMocks(project1, _serviceProvider);

            string         thirdFile  = Utilities.CreateTempTxtFile("blarg");
            string         termTable3 = Utilities.CreateTermTable(new string[] { "blarg" });
            Project        project2   = Utilities.SetupMSBuildProject(new string[] { thirdFile }, new string[] { termTable3 });
            MockIVsProject vsProject2 = Utilities.RegisterProjectWithMocks(project2, _serviceProvider);

            accessor.Start(new IVsProject[] { vsProject1, vsProject2 });

            Utilities.WaitForStop(accessor);

            Assert.AreEqual(4, resultCounts.Count, "Task list did not recieve correct number of updates.");
            Assert.AreEqual(0, resultCounts[0], "Number of hits in first update is wrong.");
            Assert.AreEqual(3, resultCounts[1], "Number of hits in second update is wrong.");
            Assert.AreEqual(3 + 5, resultCounts[2], "Number of hits in third update is wrong.");
            Assert.AreEqual(3 + 5 + 1, resultCounts[3], "Number of hits in fourth update is wrong.");
        }
Example #3
0
        public void StartUpdatesTaskList()
        {
            CodeSweep.VSPackage.BackgroundScanner_Accessor accessor = GetScanner();

            // Set up events so we know when the task list is called.
            Guid         activeProvider = Guid.Empty;
            MockTaskList taskList       = _serviceProvider.GetService(typeof(SVsTaskList)) as MockTaskList;

            taskList.OnSetActiveProvider += delegate(object sender, MockTaskList.SetActiveProviderArgs args) { activeProvider = args.ProviderGuid; };

            bool      cmdPosted = false;
            MockShell shell     = _serviceProvider.GetService(typeof(SVsUIShell)) as MockShell;

            shell.OnPostExecCommand += delegate(object sender, MockShell.PostExecCommandArgs args)
            {
                if (args.Group == VSConstants.GUID_VSStandardCommandSet97 && args.ID == (uint)VSConstants.VSStd97CmdID.TaskListWindow)
                {
                    cmdPosted = true;
                }
            };

            Project        project   = Utilities.SetupMSBuildProject(new string[] { Utilities.CreateBigFile() }, new string[] { CreateMinimalTermTableFile() });
            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            accessor.Start(new IVsProject[] { vsProject });

            Assert.IsTrue(cmdPosted, "Start did not activate the task list.");
            Assert.AreEqual(new Guid("{9ACC41B7-15B4-4dd7-A0F3-0A935D5647F3}"), activeProvider, "Start did not select the correct task bucket.");

            Utilities.WaitForStop(accessor);
        }
Example #4
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.");
        }
Example #5
0
        public void TestRegistrationAndUnregistration()
        {
            List <uint> registered   = new List <uint>();
            List <uint> unregistered = new List <uint>();

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

            taskList.OnRegisterTaskProvider +=
                delegate(object sender, MockTaskList.RegisterTaskProviderArgs args)
            {
                registered.Add(args.Cookie);
            };
            taskList.OnUnregisterTaskProvider +=
                delegate(object sender, MockTaskList.UnregisterTaskProviderArgs args)
            {
                unregistered.Add(args.Cookie);
            };

            CodeSweep.VSPackage.TaskProvider_Accessor accessor = new CodeSweep.VSPackage.TaskProvider_Accessor(_serviceProvider);

            Assert.AreEqual(1, registered.Count, "Task provider did not register itself when created.");

            accessor.OnTaskListFinalRelease(taskList);

            Assert.AreEqual(1, unregistered.Count, "Task provider did not unregister itself from OnTaskListFinalRelease.");
            Assert.AreEqual(registered[0], unregistered[0], "Cookies did not match.");
        }
Example #6
0
        public void MyTestCleanup()
        {
            Utilities.CleanUpTempFiles();
            Utilities.RemoveCommandHandlers(_serviceProvider);

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

            taskList.Clear();

            CodeSweep.VSPackage.Factory_Accessor._taskProvider = null;
        }
Example #7
0
        public void TestBuildBegin()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            accessor.IsListeningToBuildEvents = true;

            // Listen for task list refresh events.
            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);
            };

            // Create multiple projects with ScannerTask tasks.
            string scanFile  = Utilities.CreateTempTxtFile("foo abc foo def foo");
            string termTable = Utilities.CreateTermTable(new string[] { "foo", "bar" });

            Microsoft.Build.Evaluation.Project project1 = Utilities.SetupMSBuildProject(new string[] { scanFile }, new string[] { termTable });
            Microsoft.Build.Evaluation.Project project2 = Utilities.SetupMSBuildProject(new string[] { scanFile }, new string[] { termTable });

            Utilities.RegisterProjectWithMocks(project1, _serviceProvider);
            Utilities.RegisterProjectWithMocks(project2, _serviceProvider);

            // Fire the build begin event.
            MockDTE         dte         = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as MockDTE;
            MockBuildEvents buildEvents = dte.Events.BuildEvents as MockBuildEvents;

            buildEvents.FireOnBuildBegin(vsBuildScope.vsBuildScopeProject, vsBuildAction.vsBuildActionBuild);

            try
            {
                Assert.IsNotNull(ProjectCollection.GlobalProjectCollection.HostServices.GetHostObject(project1.FullPath, "AfterBuild", "ScannerTask"), "Host object for task in first project not set.");
                Assert.IsNotNull(ProjectCollection.GlobalProjectCollection.HostServices.GetHostObject(project2.FullPath, "AfterBuild", "ScannerTask"), "Host object for task in second project not set.");

                Assert.AreEqual(1, resultCounts.Count, "Task list recieved wrong number of refresh requests.");
                Assert.AreEqual(0, resultCounts[0], "Task list was not cleared.");
            }
            finally
            {
                buildEvents.FireOnBuildDone(vsBuildScope.vsBuildScopeProject, vsBuildAction.vsBuildActionBuild);
            }
        }
        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.");
        }
Example #9
0
        public void IsRunning()
        {
            CodeSweep.VSPackage.BackgroundScanner_Accessor accessor = GetScanner();

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

            taskList.OnRefreshTasks += delegate(object sender, MockTaskList.RefreshTasksArgs args) { ++refreshes; };

            string         firstFile  = Utilities.CreateBigFile();
            string         secondFile = Utilities.CreateTempTxtFile("bar bar bar floop doop bar");
            string         termTable  = Utilities.CreateTermTable(new string[] { "foo", "bar" });
            Project        project    = Utilities.SetupMSBuildProject(new string[] { firstFile, secondFile }, new string[] { termTable });
            MockIVsProject vsProject  = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            accessor.Start(new IVsProject[] { vsProject });

            Assert.IsTrue(accessor.IsRunning, "IsRunning was not true after Start.");

            accessor.StopIfRunning(false);

            Assert.IsTrue(accessor.IsRunning, "IsRunning was not true after Stop called while scan is still running.");
        }