Пример #1
0
        public void AllItemsInProjectTest()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            Microsoft.Build.Evaluation.Project project = Utilities.SetupMSBuildProject();
            string projectFolder = Path.GetDirectoryName(project.FullPath);

            project.Xml.AddItem("foo", "blah.txt");
            project.Xml.AddItem("bar", "blah2.cs");
            project.Xml.AddItem("bar", "My.Namespace.Etc");
            project.Xml.AddItem("bar", "blah3.vsmdi");

            // Create the files on disk, otherwise AllItemsInProject will exclude them.
            File.WriteAllText(projectFolder + "\\blah.txt", "");
            File.WriteAllText(projectFolder + "\\blah2.cs", "");
            File.WriteAllText(projectFolder + "\\blah3.vsmdi", "");

            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            string projectDir = Path.GetDirectoryName(project.FullPath);

            List <string> items = Utilities.ListFromEnum(accessor.AllItemsInProject(vsProject));

            Assert.AreEqual(3, items.Count, "AllItemsInProject returned wrong number of items.");
            CollectionAssert.Contains(items, projectDir + "\\blah.txt", "AllItemsInProject did not return blah.txt.");
            CollectionAssert.Contains(items, projectDir + "\\blah2.cs", "AllItemsInProject did not return blah2.cs.");
            CollectionAssert.Contains(items, projectDir + "\\blah3.vsmdi", "AllItemsInProject did not return blah3.vsmdi.");
            CollectionAssert.DoesNotContain(items, "My.Namespace.Etc", "AllItemsInProject returned Reference entry.");
        }
Пример #2
0
        public void ScanStopsWhenBuildBegins()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            accessor.IsListeningToBuildEvents = true;

            string firstFile  = Utilities.CreateBigFile();
            string secondFile = Utilities.CreateTempTxtFile("bar bar bar floop doop bar");
            string termTable  = Utilities.CreateTermTable(new string[] { "foo", "bar" });

            Microsoft.Build.Evaluation.Project project = Utilities.SetupMSBuildProject(new string[] { firstFile, secondFile }, new string[] { termTable });
            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            // Start a background scan.
            CodeSweep.VSPackage.IBackgroundScanner_Accessor scannerAccessor = CodeSweep.VSPackage.Factory_Accessor.GetBackgroundScanner();

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

            // 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.IsFalse(scannerAccessor.IsRunning, "Background scan did not stop when build began.");
            }
            finally
            {
                buildEvents.FireOnBuildDone(vsBuildScope.vsBuildScopeProject, vsBuildAction.vsBuildActionBuild);
                accessor.IsListeningToBuildEvents = false;
            }
        }
Пример #3
0
        public void ProgressShowsInStatusBar()
        {
            CodeSweep.VSPackage.BackgroundScanner_Accessor accessor = GetScanner();

            bool          inProgress = false;
            string        label      = null;
            uint          complete   = 0;
            uint          total      = 0;
            MockStatusBar statusBar  = _serviceProvider.GetService(typeof(SVsStatusbar)) as MockStatusBar;

            statusBar.OnProgress += delegate(object sender, MockStatusBar.ProgressArgs args)
            {
                inProgress = (args.InProgress == 0) ? false : true;
                label      = args.Label;
                complete   = args.Complete;
                total      = args.Total;
            };

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

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

            Assert.IsTrue(inProgress, "Start did not show progress in status bar.");
            Assert.AreEqual((uint)0, complete, "Scan did not start with zero complete.");

            // TODO: if time allows: scan several files, detect (by task list updates) when each one is done, and check to make sure the status bar has been updated accordingly.

            Utilities.WaitForStop(accessor);

            Assert.IsFalse(inProgress, "Progress bar not cleared when scan ends.");
        }
Пример #4
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);
        }
Пример #5
0
        public void UnderlinedIfIgnored()
        {
            Microsoft.Build.Evaluation.Project msbuildProj = Utilities.SetupMSBuildProject();

            // Set up a project so the project column can be populated.
            MockSolution   solution = _serviceProvider.GetService(typeof(SVsSolution)) as MockSolution;
            MockIVsProject project  = new MockIVsProject(msbuildProj.FullPath);

            solution.AddProject(project);

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

            string projectDrive = Path.GetPathRoot(msbuildProj.FullPath);

            CodeSweep.VSPackage.Task_Accessor accessor = new CodeSweep.VSPackage.Task_Accessor("term", 1, "class", "comment", "replacement", projectDrive + "\\dir\\file.ext", 2, 3, msbuildProj.FullPath, "full line text", providerAccessor, null);

            accessor.Ignored = true;

            uint   type;
            uint   flags;
            object val;
            string accName;

            foreach (object fieldObj in Enum.GetValues(typeof(TaskFields)))
            {
                accessor.GetColumnValue((int)fieldObj, out type, out flags, out val, out accName);
                Assert.IsTrue((flags & (int)__VSTASKVALUEFLAGS.TVF_STRIKETHROUGH) != 0, "Strikethrough flag not set for ignored task field " + (int)fieldObj);
            }
        }
Пример #6
0
        public int GetUniqueUINameOfProject(IVsHierarchy pHierarchy, out string pbstrUniqueName)
        {
            MockIVsProject project = pHierarchy as MockIVsProject;

            pbstrUniqueName = "Unique name of " + project.FullPath;
            return(VSConstants.S_OK);
        }
Пример #7
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.");
        }
Пример #8
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.");
        }
Пример #9
0
        public void RepeatLastWhenAlreadyRunning()
        {
            CodeSweep.VSPackage.BackgroundScanner_Accessor accessor = GetScanner();

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

            accessor.Start(new IVsProject[] { vsProject });
            accessor.RepeatLast();
        }
Пример #10
0
 public void AddProject(MockIVsProject project)
 {
     _projects.Add(project);
     foreach (IVsSolutionEvents sink in _eventSinks)
     {
         if (sink != null)
         {
             sink.OnAfterOpenProject(project, 1);
         }
     }
 }
Пример #11
0
        public void SetPropertyTest()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            Microsoft.Build.Evaluation.Project project = Utilities.SetupMSBuildProject();
            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            accessor.SetProperty(vsProject, "foo", "bar");
            Assert.AreEqual("bar", accessor.GetProperty(vsProject, "foo"), "SetProperty did not set value correctly.");

            accessor.SetProperty(vsProject, "foo", "");
            Assert.AreEqual("", accessor.GetProperty(vsProject, "foo"), "SetProperty did not set value correctly (2).");
        }
Пример #12
0
        public void StartOnProjectWithoutScannerTask()
        {
            CodeSweep.VSPackage.BackgroundScanner_Accessor accessor = GetScanner();

            Project        project   = Utilities.SetupMSBuildProject();
            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            // TODO: if we could, it would be good to make sure the Started event isn't fired --
            // but apparently the VS test framework doesn't support events.

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

            Assert.IsFalse(accessor.IsRunning, "IsRunning returned true after Start() called with project that does not contain a scanner config.");
        }
Пример #13
0
        public void GetPropertyTest()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            Microsoft.Build.Evaluation.Project project = Utilities.SetupMSBuildProject();

            ProjectPropertyGroupElement group = project.Xml.AddPropertyGroup();

            group.AddProperty("foo", "bar");

            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            Assert.IsNull(accessor.GetProperty(vsProject, "blah"), "GetProperty did not return null with invalid name.");
            Assert.AreEqual("bar", accessor.GetProperty(vsProject, "foo"), "GetProperty did not return correct value.");
        }
        public void HasConfiguration()
        {
            MockSolution   solution  = _serviceProvider.GetService(typeof(SVsSolution)) as MockSolution;
            MockIVsProject vsProject = new MockIVsProject("c:\\temp.proj");

            solution.AddProject(vsProject);

            CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor accessor = new CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor(vsProject, _serviceProvider);

            Assert.IsFalse(accessor.HasConfiguration, "HasConfiguration was true for a new project.");

            accessor.CreateDefaultConfiguration();

            Assert.IsTrue(accessor.HasConfiguration, "HasConfiguration was false after CreateDefaultConfiguration.");
        }
        internal static MockIVsProject RegisterProjectWithMocks(Project project, IServiceProvider serviceProvider)
        {
            MockSolution   solution  = serviceProvider.GetService(typeof(SVsSolution)) as MockSolution;
            MockIVsProject vsProject = new MockIVsProject(project.FullPath);

            foreach (ProjectItemGroupElement itemGroup in project.Xml.ItemGroups)
            {
                foreach (ProjectItemElement item in itemGroup.Items)
                {
                    vsProject.AddItem(item.Include);
                }
            }

            solution.AddProject(vsProject);

            return(vsProject);
        }
Пример #16
0
        public void GetPropertyWithInvalidArgs()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            bool thrown = Utilities.HasFunctionThrown <ArgumentNullException>(delegate { accessor.GetProperty(null, "foo"); });

            Assert.IsTrue(thrown, "GetProperty did not throw ArgumentNullException with null project arg.");

            Microsoft.Build.Evaluation.Project project = Utilities.SetupMSBuildProject();

            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            thrown = Utilities.HasFunctionThrown <ArgumentNullException>(delegate { accessor.GetProperty(vsProject, null); });
            Assert.IsTrue(thrown, "GetProperty did not throw ArgumentNullException with null name arg.");

            thrown = Utilities.HasFunctionThrown <ArgumentException>(delegate { accessor.GetProperty(vsProject, ""); });
            Assert.IsTrue(thrown, "GetProperty did not throw ArgumentException with empty name arg.");
        }
Пример #17
0
        public void GetBuildTaskWithCreation()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            // Create a project without a build task.
            Microsoft.Build.Evaluation.Project project = Utilities.SetupMSBuildProject();

            project.Xml.AddItem("foo", "blah.txt");
            project.Xml.AddItem("bar", "blah2.cs");
            project.Xml.AddItem("Reference", "My.Namespace.Etc");

            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            ProjectTaskElement task = accessor.GetBuildTask(vsProject, true);

            Assert.IsNotNull(task, "GetBuildTask did not create task.");
            Assert.AreEqual("false", task.ContinueOnError, "ContinueOnError is wrong.");
            Assert.AreEqual("Exists('" + Utilities.GetTargetsPath() + "') and '$(RunCodeSweepAfterBuild)' == 'true'", task.Condition, "Condition is wrong.");
            Assert.AreEqual("@(foo);@(bar)", task.GetParameter("FilesToScan"), "FilesToScan property is wrong.");
            Assert.AreEqual("$(MSBuildProjectFullPath)", task.GetParameter("Project"), "Project property is wrong.");

            string projectFolder     = Path.GetDirectoryName(project.FullPath);
            string expectedTermTable = CodeSweep.Utilities.RelativePathFromAbsolute(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\CodeSweep\\sample_term_table.xml", projectFolder);

            Assert.AreEqual(expectedTermTable, task.GetParameter("TermTables"), "TermTables property is wrong.");

            // Ensure the task is in the AfterBuild target.
            bool found = false;

            foreach (ProjectTaskElement thisTask in project.Xml.Targets.FirstOrDefault(target => target.Name == "AfterBuild").Tasks)
            {
                if (thisTask == task)
                {
                    found = true;
                    break;
                }
            }
            Assert.IsTrue(found, "The task was not in the AfterBuild target.");

            ProjectImportElement import = GetImport(project, Utilities.GetTargetsPath());

            Assert.IsNotNull(import, "GetBuildTask did not create Import.");
        }
        public void TermTables()
        {
            MockSolution   solution  = _serviceProvider.GetService(typeof(SVsSolution)) as MockSolution;
            MockIVsProject vsProject = new MockIVsProject("c:\\temp.proj");

            solution.AddProject(vsProject);

            CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor accessor = new CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor(vsProject, _serviceProvider);

            Assert.AreEqual(0, accessor.TermTableFiles.Count, "TermTableFiles not initially empty.");

            accessor.CreateDefaultConfiguration();

            Assert.AreEqual(1, accessor.TermTableFiles.Count, "TermTableFiles wrong size after CreateDefaultConfiguration.");

            MockDTE        dte     = _serviceProvider.GetService(typeof(DTE)) as MockDTE;
            MockDTEGlobals globals = dte.Solution.Projects.Item(0).Globals as MockDTEGlobals;

            globals.ClearNonPersistedVariables();

            // Create a new proj config store to see if the change was persisted.
            CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor accessor2 = new CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor(vsProject, _serviceProvider);

            Assert.AreEqual(1, accessor2.TermTableFiles.Count, "CreateDefaultConfiguration changes did not persist.");

            accessor.TermTableFiles.Remove(Utilities.ListFromEnum(accessor.TermTableFiles)[0]);
            globals.ClearNonPersistedVariables();

            // Create a new proj config store to see if the change was persisted.
            CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor accessor3 = new CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor(vsProject, _serviceProvider);

            Assert.AreEqual(0, accessor3.TermTableFiles.Count, "Deletion did not persist.");

            accessor.TermTableFiles.Add("c:\\foo");
            accessor.TermTableFiles.Add("c:\\bar");
            globals.ClearNonPersistedVariables();

            // Create a new proj config store to see if the change was persisted.
            CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor accessor4 = new CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor(vsProject, _serviceProvider);

            Assert.AreEqual(2, accessor4.TermTableFiles.Count, "Additions did not persist.");
        }
Пример #19
0
        public void GetBuildTaskWithNoCreation()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            // Create a project without a build task.
            Microsoft.Build.Evaluation.Project project1 = Utilities.SetupMSBuildProject();
            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project1, _serviceProvider);

            Assert.IsNull(accessor.GetBuildTask(vsProject, false), "GetBuildTask did not return null for project without a ScannerTask.");

            // Create a project with a build task.
            string scanFile  = Utilities.CreateTempTxtFile("foo abc foo def foo");
            string termTable = Utilities.CreateTermTable(new string[] { "foo", "bar" });

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

            Microsoft.Build.Construction.ProjectTaskElement existingTask = Utilities.GetScannerTask(project2);

            vsProject = Utilities.RegisterProjectWithMocks(project2, _serviceProvider);

            Assert.AreEqual(existingTask, accessor.GetBuildTask(vsProject, false), "GetBuildTask did not return expected task object.");
            Assert.IsNull(GetImport(project2, Utilities.GetTargetsPath()), "GetBuildTask created Import unexpected.");
        }
Пример #20
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.");
        }
Пример #21
0
        public void StartWhenAlreadyRunning()
        {
            CodeSweep.VSPackage.BackgroundScanner_Accessor accessor = GetScanner();

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

            bool thrown = false;

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

            try
            {
                accessor.Start(new IVsProject[] { new MockIVsProject(project.FullPath) });
            }
            catch (InvalidOperationException)
            {
                thrown = true;
            }

            Utilities.WaitForStop(accessor);

            Assert.IsTrue(thrown, "Start did not throw InvalidOperationException with scan already running.");
        }
Пример #22
0
        public void GetColumnValueTest()
        {
            Microsoft.Build.Evaluation.Project msbuildProj = Utilities.SetupMSBuildProject();

            // Set up a project so the project column can be populated.
            MockSolution   solution = _serviceProvider.GetService(typeof(SVsSolution)) as MockSolution;
            MockIVsProject project  = new MockIVsProject(msbuildProj.FullPath);

            solution.AddProject(project);

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

            CodeSweep.VSPackage.Task_Accessor accessor = new CodeSweep.VSPackage.Task_Accessor("term", 1, "class", "comment with link:  http://www.microsoft.com", "replacement", "z:\\dir\\file.ext", 2, 3, msbuildProj.FullPath, "full line text", providerAccessor, null);

            uint   type;
            uint   flags;
            object val;
            string accName;

            int hr = accessor.GetColumnValue((int)TaskFields.Priority, out type, out flags, out val, out accName);

            Assert.AreEqual(VSConstants.S_OK, hr, "GetColumnValue did not return S_OK for the Priority column.");
            Assert.AreEqual(__VSTASKVALUETYPE.TVT_IMAGE, (__VSTASKVALUETYPE)type, "Type of Priority column is incorrect.");
            Assert.AreEqual(__VSTASKVALUEFLAGS.TVF_HORZ_CENTER, (__VSTASKVALUEFLAGS)flags, "Flags for Priority column are incorrect.");
            Assert.AreEqual(typeof(int), val.GetType(), "Value of Priority column has wrong type.");
            Assert.IsTrue((int)val >= 0 && (int)val <= 2, "Image index for Priority column is out of range.");
            string[] imageAccText = new string[] { "High", "Medium", "Low" };
            Assert.AreEqual(imageAccText[(int)val], accName, "Accessibility text of Priority column is incorrect.");

            hr = accessor.GetColumnValue((int)TaskFields.PriorityNumber, out type, out flags, out val, out accName);

            Assert.AreEqual(VSConstants.S_OK, hr, "GetColumnValue did not return S_OK for the PriorityNumber column.");
            Assert.AreEqual(__VSTASKVALUETYPE.TVT_BASE10, (__VSTASKVALUETYPE)type, "Type of PriorityNumber column is incorrect.");
            Assert.AreEqual(0, (int)flags, "Flags for PriorityNumber column are incorrect.");
            Assert.AreEqual(typeof(int), val.GetType(), "Value of PriorityNumber column has wrong type.");
            Assert.AreEqual(1, (int)val, "Value of PriorityNumber column is incorrect.");
            Assert.AreEqual("", accName, "Accessibility text of PriorityNumber column is incorrect.");

            hr = accessor.GetColumnValue((int)TaskFields.Term, out type, out flags, out val, out accName);

            Assert.AreEqual(VSConstants.S_OK, hr, "GetColumnValue did not return S_OK for the Term column.");
            Assert.AreEqual(__VSTASKVALUETYPE.TVT_TEXT, (__VSTASKVALUETYPE)type, "Type of Term column is incorrect.");
            Assert.AreEqual(0, (int)flags, "Flags for Term column are incorrect.");
            Assert.AreEqual(typeof(string), val.GetType(), "Value of Term column has wrong type.");
            Assert.AreEqual("term", (string)val, "Value of Term column is incorrect.");
            Assert.AreEqual("", accName, "Accessibility text of Term column is incorrect.");

            hr = accessor.GetColumnValue((int)TaskFields.Class, out type, out flags, out val, out accName);

            Assert.AreEqual(VSConstants.S_OK, hr, "GetColumnValue did not return S_OK for the Class column.");
            Assert.AreEqual(__VSTASKVALUETYPE.TVT_TEXT, (__VSTASKVALUETYPE)type, "Type of Class column is incorrect.");
            Assert.AreEqual(0, (int)flags, "Flags for Class column are incorrect.");
            Assert.AreEqual(typeof(string), val.GetType(), "Value of Class column has wrong type.");
            Assert.AreEqual("class", (string)val, "Value of Class column is incorrect.");
            Assert.AreEqual("", accName, "Accessibility text of Class column is incorrect.");

            hr = accessor.GetColumnValue((int)TaskFields.Replacement, out type, out flags, out val, out accName);

            Assert.AreEqual(VSConstants.S_OK, hr, "GetColumnValue did not return S_OK for the Replacement column.");
            Assert.AreEqual(__VSTASKVALUETYPE.TVT_TEXT, (__VSTASKVALUETYPE)type, "Type of Replacement column is incorrect.");
            Assert.AreEqual(0, (int)flags, "Flags for Replacement column are incorrect.");
            Assert.AreEqual(typeof(string), val.GetType(), "Value of Replacement column has wrong type.");
            Assert.AreEqual("replacement", (string)val, "Value of Replacement column is incorrect.");
            Assert.AreEqual("", accName, "Accessibility text of Replacement column is incorrect.");

            hr = accessor.GetColumnValue((int)TaskFields.Comment, out type, out flags, out val, out accName);

            Assert.AreEqual(VSConstants.S_OK, hr, "GetColumnValue did not return S_OK for the Comment column.");
            Assert.AreEqual(__VSTASKVALUETYPE.TVT_LINKTEXT, (__VSTASKVALUETYPE)type, "Type of Comment column is incorrect.");
            Assert.AreEqual(0, (int)flags, "Flags for Comment column are incorrect.");
            Assert.AreEqual(typeof(string), val.GetType(), "Value of Comment column has wrong type.");
            Assert.AreEqual("comment with link:  @http://www.microsoft.com@", (string)val, "Value of Comment column is incorrect.");
            Assert.AreEqual("", accName, "Accessibility text of Comment column is incorrect.");

            hr = accessor.GetColumnValue((int)TaskFields.File, out type, out flags, out val, out accName);

            Assert.AreEqual(VSConstants.S_OK, hr, "GetColumnValue did not return S_OK for the File column.");
            Assert.AreEqual(__VSTASKVALUETYPE.TVT_TEXT, (__VSTASKVALUETYPE)type, "Type of File column is incorrect.");
            Assert.AreEqual(__VSTASKVALUEFLAGS.TVF_FILENAME, (__VSTASKVALUEFLAGS)flags, "Flags for File column are incorrect.");
            Assert.AreEqual(typeof(string), val.GetType(), "Value of File column has wrong type.");
            Assert.AreEqual("z:\\dir\\file.ext", (string)val, "Value of File column is incorrect.");
            Assert.AreEqual("", accName, "Accessibility text of File column is incorrect.");

            hr = accessor.GetColumnValue((int)TaskFields.Line, out type, out flags, out val, out accName);

            Assert.AreEqual(VSConstants.S_OK, hr, "GetColumnValue did not return S_OK for the Line column.");
            Assert.AreEqual(__VSTASKVALUETYPE.TVT_BASE10, (__VSTASKVALUETYPE)type, "Type of Line column is incorrect.");
            Assert.AreEqual(0, (int)flags, "Flags for Line column are incorrect.");
            Assert.AreEqual(typeof(int), val.GetType(), "Value of Line column has wrong type.");
            Assert.AreEqual(3, (int)val, "Value of Line column is incorrect.");
            Assert.AreEqual("", accName, "Accessibility text of Line column is incorrect.");

            hr = accessor.GetColumnValue((int)TaskFields.Project, out type, out flags, out val, out accName);

            Assert.AreEqual(VSConstants.S_OK, hr, "GetColumnValue did not return S_OK for the Project column.");
            Assert.AreEqual(__VSTASKVALUETYPE.TVT_TEXT, (__VSTASKVALUETYPE)type, "Type of Project column is incorrect.");
            Assert.AreEqual(0, (int)flags, "Flags for Project column are incorrect.");
            Assert.AreEqual(typeof(string), val.GetType(), "Value of Project column has wrong type.");
            string uniqueName;

            solution.GetUniqueUINameOfProject(project, out uniqueName);
            Assert.AreEqual(uniqueName, (string)val, "Value of Project column is incorrect.");
            Assert.AreEqual("", accName, "Accessibility text of Project column is incorrect.");
        }
 public MockDTEProject(MockIVsProject project)
 {
     _project = project;
 }