예제 #1
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);
            }
        }
        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);
        }
        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.");
        }
예제 #5
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.");
        }