예제 #1
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.");
        }
예제 #2
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.");
        }
예제 #3
0
 public void GetBuildTaskWithNullArg()
 {
     CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);
     accessor.GetBuildTask(null, false);
 }