コード例 #1
0
        public void ImportsBefore_MissingAnalysisTargets()
        {
            // 1. Prebuild
            // Arrange
            WellKnownProjectProperties preImportProperties = new WellKnownProjectProperties();

            preImportProperties.RunSonarQubeAnalysis          = "true";
            preImportProperties.MSBuildExtensionsPath         = "nonExistentPath";
            preImportProperties.TeamBuild2105BuildDirectory   = "";
            preImportProperties.TeamBuildLegacyBuildDirectory = "";

            // Act
            ProjectInstance projectInstance = this.CreateAndEvaluateProject(preImportProperties);

            // Assert
            BuildAssertions.AssertPropertyDoesNotExist(projectInstance, TargetProperties.SonarQubeTargetsPath); // path doesn't have a default value
            BuildAssertions.AssertPropertyExists(projectInstance, TargetProperties.SonarQubeTargetFilePath);    // ... but the target file path does

            BuildAssertions.AssertExpectedPropertyValue(projectInstance, TargetProperties.SonarQubeTargetFilePath, "\\" + TargetConstants.AnalysisTargetFile);
            AssertAnalysisTargetsAreNotImported(projectInstance); // Targets do not exist at that location so they should not be imported


            // 2. Now build -> fails with an error message
            BuildLogger logger = new BuildLogger();

            BuildResult result = BuildUtilities.BuildTargets(projectInstance, logger);

            BuildAssertions.AssertTargetFailed(result, TargetConstants.DefaultBuildTarget);
            logger.AssertTargetExecuted(TargetConstants.ImportBeforeInfoTarget);
            logger.AssertExpectedErrorCount(1);

            string projectName = Path.GetFileName(projectInstance.FullPath);

            Assert.IsTrue(logger.Errors[0].Message.Contains(projectName), "Expecting the error message to contain the project file name");
        }