예제 #1
0
        [WorkItem(50)] // Regression test for Bug 50:MSBuild projects with missing ProjectGuids cause the build to fail
        public void WriteProjectInfoFile_MissingProjectGuid()
        {
            // Arrange
            var testFolder = TestUtils.CreateTestSpecificFolder(TestContext);

            var task = new WriteProjectInfoFile
            {
                FullProjectPath = "c:\\fullPath\\project.proj",
                IsTest          = true,
                OutputFolder    = testFolder,
                ProjectName     = "ProjectWithoutProjectGuid",
                ProjectLanguage = "C#"
            };
            // No analysis results are supplied

            // Act
            var engine = new DummyBuildEngine();

            task.BuildEngine = engine;
            var success = task.Execute();

            // Assert
            success.Should().BeTrue("Not expecting the task to fail as this would fail the build");
            engine.AssertNoErrors();
            engine.Warnings.Should().HaveCount(1, "Expecting a build warning as the ProjectGuid is missing");

            var firstWarning = engine.Warnings[0];

            firstWarning.Message.Should().NotBeNull("Warning message should not be null");

            var projectInfoFilePath = Path.Combine(testFolder, ExpectedProjectInfoFileName);

            File.Exists(projectInfoFilePath).Should().BeTrue("Expecting the project info file to have been created");
        }
예제 #2
0
        [WorkItem(50)] // Regression test for Bug 50:MSBuild projects with missing ProjectGuids cause the build to fail
        public void WriteProjectInfoFile_MissingProjectGuid()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            WriteProjectInfoFile task = new WriteProjectInfoFile
            {
                FullProjectPath = "c:\\fullPath\\project.proj",
                IsTest          = true,
                OutputFolder    = testFolder,
                ProjectName     = "ProjectWithoutProjectGuid",
                ProjectLanguage = "C#"
            };
            // No analysis results are supplied

            // Act
            DummyBuildEngine engine = new DummyBuildEngine();

            task.BuildEngine = engine;
            bool success = task.Execute();

            // Assert
            Assert.IsTrue(success, "Not expecting the task to fail as this would fail the build");
            engine.AssertNoErrors();
            Assert.AreEqual(1, engine.Warnings.Count, "Expecting a build warning as the ProjectGuid is missing");

            BuildWarningEventArgs firstWarning = engine.Warnings[0];

            Assert.IsNotNull(firstWarning.Message, "Warning message should not be null");

            string projectInfoFilePath = Path.Combine(testFolder, ExpectedProjectInfoFileName);

            Assert.IsFalse(File.Exists(projectInfoFilePath), "Not expecting the project info file to have been created");
        }
예제 #3
0
        public void WriteProjectInfoFile_UseSolutionProjectGuid()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            Guid projectGuid = Guid.NewGuid();

            WriteProjectInfoFile task = new WriteProjectInfoFile
            {
                FullProjectPath = "c:\\fullPath\\project.proj",
                SolutionConfigurationContents = @"<SolutionConfiguration>
                <ProjectConfiguration Project=""{FOO}"" AbsolutePath=""c:\fullPath\foo.proj"" BuildProjectInSolution=""True""> Debug | AnyCPU </ProjectConfiguration>
                <ProjectConfiguration Project=""{" + projectGuid + @"}"" AbsolutePath=""c:\fullPath\project.proj"" BuildProjectInSolution=""True""> Debug | AnyCPU </ProjectConfiguration>
               </SolutionConfiguration >",
                IsTest          = true,
                OutputFolder    = testFolder,
                ProjectName     = "ProjectWithoutProjectGuid",
                ProjectLanguage = "C#"
            };

            // Act
            ProjectInfo reloadedProjectInfo = ExecuteAndCheckSucceeds(task, testFolder);

            // Addition assertions
            ProjectInfoAssertions.AssertExpectedValues(
                "c:\\fullPath\\project.proj",
                ProjectLanguages.CSharp,
                ProjectType.Test,
                projectGuid,
                "ProjectWithoutProjectGuid",
                false, // IsExcluded
                reloadedProjectInfo);
        }
        public void WriteProjectInfoFile_FileCreated()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            Guid projectGuid = Guid.NewGuid();

            WriteProjectInfoFile task = new WriteProjectInfoFile();
            task.FullProjectPath = "c:\\fullPath\\project.proj";
            task.ProjectLanguage = "cs";
            task.IsTest = true;
            task.IsExcluded = false;
            task.OutputFolder = testFolder;
            task.ProjectGuid = projectGuid.ToString("B");
            task.ProjectName = "MyProject";
            task.ProjectLanguage = ProjectLanguages.CSharp;
            // No analysis results are supplied

            // Act
            ProjectInfo reloadedProjectInfo = ExecuteAndCheckSucceeds(task, testFolder);

            // Addition assertions
            ProjectInfoAssertions.AssertExpectedValues(
                "c:\\fullPath\\project.proj",
                ProjectLanguages.CSharp,
                ProjectType.Test,
                projectGuid,
                "MyProject",
                false, // IsExcluded
                reloadedProjectInfo);
        }
예제 #5
0
        public void WriteProjectInfoFile_UnrecognisedLanguages()
        {
            // Arrange
            WriteProjectInfoFile task = new WriteProjectInfoFile
            {
                FullProjectPath = "c:\\fullPath\\project.proj",
                IsTest          = true,
                ProjectName     = "UnrecognisedLanguageProject",
                ProjectGuid     = Guid.NewGuid().ToString("B"),

                // 1. Null language
                ProjectLanguage = null,
                OutputFolder    = TestUtils.CreateTestSpecificFolder(this.TestContext, "null.language")
            };

            ProjectInfo actual = ExecuteAndCheckSucceeds(task, task.OutputFolder);

            Assert.IsNull(actual.ProjectLanguage, "Expecting the language to be null");

            // 2. Unrecognized language
            task.ProjectLanguage = "unrecognized language";
            task.OutputFolder    = TestUtils.CreateTestSpecificFolder(this.TestContext, "unrecog.language");

            actual = ExecuteAndCheckSucceeds(task, task.OutputFolder);
            Assert.AreEqual("unrecognized language", actual.ProjectLanguage, "Unexpected value for project language");
        }
예제 #6
0
        public void WriteProjectInfoFile_FileCreated()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            Guid projectGuid = Guid.NewGuid();

            WriteProjectInfoFile task = new WriteProjectInfoFile
            {
                FullProjectPath = "c:\\fullPath\\project.proj",
                ProjectLanguage = "cs",
                IsTest          = true,
                IsExcluded      = false,
                OutputFolder    = testFolder,
                ProjectGuid     = projectGuid.ToString("B"),
                ProjectName     = "MyProject"
            };

            task.ProjectLanguage = ProjectLanguages.CSharp;
            // No analysis results are supplied

            // Act
            ProjectInfo reloadedProjectInfo = ExecuteAndCheckSucceeds(task, testFolder);

            // Addition assertions
            ProjectInfoAssertions.AssertExpectedValues(
                "c:\\fullPath\\project.proj",
                ProjectLanguages.CSharp,
                ProjectType.Test,
                projectGuid,
                "MyProject",
                false, // IsExcluded
                reloadedProjectInfo);
        }
예제 #7
0
        public void WriteProjectInfoFile_UseSolutionProjectGuid()
        {
            // Arrange
            var testFolder = TestUtils.CreateTestSpecificFolder(TestContext);

            var projectGuid = Guid.NewGuid();

            var task = new WriteProjectInfoFile
            {
                FullProjectPath = "c:\\fullPath\\project.proj",
                SolutionConfigurationContents = @"<SolutionConfiguration>
                <ProjectConfiguration Project=""{FOO}"" AbsolutePath=""c:\fullPath\foo.proj"" BuildProjectInSolution=""True""> Debug | AnyCPU </ProjectConfiguration>
                <ProjectConfiguration Project=""{" + projectGuid + @"}"" AbsolutePath=""c:\fullPath\project.proj"" BuildProjectInSolution=""True""> Debug | AnyCPU </ProjectConfiguration>
               </SolutionConfiguration >",
                IsTest          = true,
                OutputFolder    = testFolder,
                ProjectName     = "ProjectWithoutProjectGuid",
                ProjectLanguage = "C#"
            };

            // Act
            var reloadedProjectInfo = ExecuteAndCheckSucceeds(task, testFolder);

            // Addition assertions
            reloadedProjectInfo.Should().NotBeNull("Supplied ProjectInfo should not be null");
            reloadedProjectInfo.FullPath.Should().Be("c:\\fullPath\\project.proj", "Unexpected FullPath");
            reloadedProjectInfo.ProjectLanguage.Should().Be(ProjectLanguages.CSharp, "Unexpected ProjectLanguage");
            reloadedProjectInfo.ProjectType.Should().Be(ProjectType.Test, "Unexpected ProjectType");
            reloadedProjectInfo.ProjectGuid.Should().Be(projectGuid, "Unexpected ProjectGuid");
            reloadedProjectInfo.ProjectName.Should().Be("ProjectWithoutProjectGuid", "Unexpected ProjectName");
            reloadedProjectInfo.IsExcluded.Should().BeFalse("Unexpected IsExcluded");
            reloadedProjectInfo.Configuration.Should().BeNull();
            reloadedProjectInfo.Platform.Should().BeNull();
            reloadedProjectInfo.TargetFramework.Should().BeNull();
        }
예제 #8
0
        public void GetProjectGuid_WhenProjectGuidHasValue_ReturnsProjectGuid()
        {
            // Arrange
            var expectedGuid = Guid.Empty.ToString();
            var testSubject  = new WriteProjectInfoFile {
                ProjectGuid = expectedGuid, SolutionConfigurationContents = null
            };

            // Act
            var actual = testSubject.GetProjectGuid();

            // Assert
            actual.Should().Be(expectedGuid);
        }
예제 #9
0
        private void AssertProjectGuidIsNull(string projectGuid, string solutionConfigurationContents)
        {
            // Arrange
            var testSubject = new WriteProjectInfoFile
            {
                ProjectGuid = projectGuid,
                SolutionConfigurationContents = solutionConfigurationContents
            };

            // Act
            var actual = testSubject.GetProjectGuid();

            // Assert
            actual.Should().BeNull();
        }
예제 #10
0
        private ProjectInfo WriteProjectInfoFile_ExecuteAndReturn(IEncodingProvider encodingProvider, decimal?codePage, string projectLanguage, string folderName)
        {
            // Arrange
            WriteProjectInfoFile task = new WriteProjectInfoFile(encodingProvider);

            task.FullProjectPath = "c:\\fullPath\\project.proj";
            task.IsTest          = true;
            task.ProjectName     = "Foo";
            task.ProjectGuid     = Guid.NewGuid().ToString("B");
            task.ProjectLanguage = projectLanguage;
            task.CodePage        = codePage.ToString();
            task.OutputFolder    = TestUtils.CreateTestSpecificFolder(this.TestContext, folderName);

            // Act
            return(ExecuteAndCheckSucceeds(task, task.OutputFolder));
        }
예제 #11
0
        public void WriteProjectInfoFile_AnalysisResults()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            Guid projectGuid = Guid.NewGuid();

            WriteProjectInfoFile task = new WriteProjectInfoFile
            {
                BuildEngine     = new DummyBuildEngine(),
                FullProjectPath = "x:\\a.csproj",
                IsTest          = false,
                OutputFolder    = testFolder,
                ProjectGuid     = projectGuid.ToString("B"),
                ProjectName     = "MyProject",
                ProjectLanguage = "C#"
            };

            List <ITaskItem> resultInputs = new List <ITaskItem>
            {
                // Add invalid task items
                // Note: the TaskItem class won't allow the item spec or metadata values to be null,
                // so we aren't testing those
                CreateMetadataItem("itemSpec1", "abc", "def"),                        // Id field is missing
                CreateAnalysisResultTaskItem("\r", "should be ignored - whitespace"), // whitespace id
                CreateAnalysisResultTaskItem("should be ignored - whitespace", " "),  // whitespace location

                // Add valid task items
                CreateAnalysisResultTaskItem("id1", "location1"),
                CreateAnalysisResultTaskItem("id2", "location2", "md1", "md1 value", "md2", "md2 value") // valid but with extra metadata
            };

            task.AnalysisResults = resultInputs.ToArray();

            // Act
            ProjectInfo createdProjectInfo;

            using (new AssertIgnoreScope()) // We've deliberately created task items with unexpected item names that will cause assertions
            {
                createdProjectInfo = ExecuteAndCheckSucceeds(task, testFolder);
            }

            // Assert
            AssertAnalysisResultExists(createdProjectInfo, "id1", "location1");
            AssertAnalysisResultExists(createdProjectInfo, "id2", "location2");
            AssertExpectedAnalysisResultCount(2, createdProjectInfo);
        }
예제 #12
0
        private ProjectInfo WriteProjectInfoFile_ExecuteAndReturn(IEncodingProvider encodingProvider, decimal?codePage, string projectLanguage, string folderName)
        {
            // Arrange
            var task = new WriteProjectInfoFile(encodingProvider)
            {
                FullProjectPath = "c:\\fullPath\\project.proj",
                IsTest          = true,
                ProjectName     = "Foo",
                ProjectGuid     = Guid.NewGuid().ToString("B"),
                ProjectLanguage = projectLanguage,
                CodePage        = codePage.ToString(),
                OutputFolder    = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext, folderName)
            };

            // Act
            return(ExecuteAndCheckSucceeds(task, task.OutputFolder));
        }
예제 #13
0
        public void GetProjectGuid_WhenSolutionConfigurationContentsHasNoAbsolutePathAttribute_ReturnsNull()
        {
            // Arrange
            var testSubject = new WriteProjectInfoFile
            {
                ProjectGuid     = null,
                FullProjectPath = @"C:\NetStdApp\NetStdApp.csproj",
                SolutionConfigurationContents = @"<SolutionConfiguration>
  <ProjectConfiguration Project=""{10F2915F-4AB3-4269-BC2B-4F72C6DE87C8}"" BuildProjectInSolution=""True"">Debug|AnyCPU</ProjectConfiguration>
</SolutionConfiguration>"
            };

            // Act
            var actual = testSubject.GetProjectGuid();

            // Assert
            actual.Should().BeNull();
        }
        public void GetProjectGuid_WhenSolutionConfigurationContentsHasNoProjectAttribute_ReturnsNull()
        {
            // Arrange
            var testSubject = new WriteProjectInfoFile
            {
                ProjectGuid     = null,
                FullProjectPath = @"C:\NetStdApp\NetStdApp.csproj",
                SolutionConfigurationContents = @"<SolutionConfiguration>
  <ProjectConfiguration AbsolutePath=""C:\NetStdApp\NetStdApp.csproj"" BuildProjectInSolution=""True"">Debug|AnyCPU</ProjectConfiguration>
</SolutionConfiguration>"
            };

            // Act
            var actual = testSubject.GetProjectGuid();

            // Assert
            Assert.AreEqual(null, actual);
        }
        public void WriteProjectInfoFile_AnalysisResults()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            Guid projectGuid = Guid.NewGuid();

            WriteProjectInfoFile task = new WriteProjectInfoFile();
            task.BuildEngine = new DummyBuildEngine();
            task.FullProjectPath = "x:\\a.csproj";
            task.IsTest = false;
            task.OutputFolder = testFolder;
            task.ProjectGuid = projectGuid.ToString("B");
            task.ProjectName = "MyProject";
            task.ProjectLanguage = "C#";

            List<ITaskItem> resultInputs = new List<ITaskItem>();

            // Add invalid task items
            // Note: the TaskItem class won't allow the item spec or metadata values to be null,
            // so we aren't testing those
            resultInputs.Add(CreateMetadataItem("itemSpec1", "abc", "def")); // Id field is missing
            resultInputs.Add(CreateAnalysisResultTaskItem("\r", "should be ignored - whitespace")); // whitespace id
            resultInputs.Add(CreateAnalysisResultTaskItem("should be ignored - whitespace", " ")); // whitespace location

            // Add valid task items
            resultInputs.Add(CreateAnalysisResultTaskItem("id1", "location1"));
            resultInputs.Add(CreateAnalysisResultTaskItem("id2", "location2", "md1", "md1 value", "md2", "md2 value")); // valid but with extra metadata

            task.AnalysisResults = resultInputs.ToArray();

            // Act
            ProjectInfo createdProjectInfo;
            using (new AssertIgnoreScope()) // We've deliberately created task items with unexpected item names that will cause assertions
            {
                createdProjectInfo = ExecuteAndCheckSucceeds(task, testFolder);
            }

            // Assert
            AssertAnalysisResultExists(createdProjectInfo, "id1", "location1");
            AssertAnalysisResultExists(createdProjectInfo, "id2", "location2");
            AssertExpectedAnalysisResultCount(2, createdProjectInfo);
        }
예제 #16
0
        private void AssertThatSolutionProjectGuidIsExpected(string fullProjectPath, string solutionProjectPath)
        {
            // Arrange
            var expectedGuid = "{10F2915F-4AB3-4269-BC2B-4F72C6DE87C8}";
            var testSubject  = new WriteProjectInfoFile
            {
                ProjectGuid     = null,
                FullProjectPath = fullProjectPath,
                SolutionConfigurationContents = @"<SolutionConfiguration>
  <ProjectConfiguration Project=""" + expectedGuid + @""" AbsolutePath=""" + solutionProjectPath + @""" BuildProjectInSolution=""True"">Debug|AnyCPU</ProjectConfiguration>
</SolutionConfiguration>"
            };

            // Act
            var actual = testSubject.GetProjectGuid();

            // Assert
            actual.Should().Be(expectedGuid);
        }
예제 #17
0
        public void GetProjectGuid_WhenSolutionConfigurationContentsHasMultipleMatch_ReturnsFirstGuid()
        {
            // Arrange
            var expectedGuid = "{10F2915F-4AB3-4269-BC2B-4F72C6DE87C8}";
            var testSubject  = new WriteProjectInfoFile
            {
                ProjectGuid     = null,
                FullProjectPath = @"C:\NetStdApp\NetStdApp.csproj",
                SolutionConfigurationContents = $@"<SolutionConfiguration>
  <ProjectConfiguration Project=""{expectedGuid}"" AbsolutePath=""C:\NetStdApp\NetStdApp.csproj"" BuildProjectInSolution=""True"">Debug|AnyCPU</ProjectConfiguration>
  <ProjectConfiguration Project=""{Guid.NewGuid()}"" AbsolutePath=""C:\NetStdApp\NetStdApp.csproj"" BuildProjectInSolution=""True"">Debug|AnyCPU</ProjectConfiguration>
</SolutionConfiguration>"
            };

            // Act
            var actual = testSubject.GetProjectGuid();

            // Assert
            actual.Should().Be(expectedGuid);
        }
예제 #18
0
        private void AssertProjectGuidIsRandomlyGenerated(string projectGuid, string solutionConfigurationContents, string fullProjectPath)
        {
            // Arrange
            var testSubject = new WriteProjectInfoFile
            {
                FullProjectPath = fullProjectPath,
                ProjectGuid     = projectGuid,
                SolutionConfigurationContents = solutionConfigurationContents
            };

            var engine = new DummyBuildEngine();

            testSubject.BuildEngine = engine;

            // Act
            var actual = testSubject.GetProjectGuid();

            // Assert
            actual.Should().NotBeNullOrEmpty();
            actual.Should().NotBe(Guid.Empty.ToString());
        }
예제 #19
0
        public void WriteProjectInfoFile_FileCreated()
        {
            // Arrange
            var testFolder = TestUtils.CreateTestSpecificFolder(TestContext);

            var projectGuid = Guid.NewGuid();

            var task = new WriteProjectInfoFile
            {
                FullProjectPath = "c:\\fullPath\\project.proj",
                ProjectLanguage = "cs",
                IsTest          = true,
                IsExcluded      = false,
                OutputFolder    = testFolder,
                ProjectGuid     = projectGuid.ToString("B"),
                ProjectName     = "MyProject",
                Configuration   = "conf-1",
                Platform        = "plat-1",
                TargetFramework = "target-1",
            };

            task.ProjectLanguage = ProjectLanguages.CSharp;
            // No analysis results are supplied

            // Act
            var reloadedProjectInfo = ExecuteAndCheckSucceeds(task, testFolder);

            // Addition assertions
            reloadedProjectInfo.Should().NotBeNull("Supplied ProjectInfo should not be null");
            reloadedProjectInfo.FullPath.Should().Be("c:\\fullPath\\project.proj", "Unexpected FullPath");
            reloadedProjectInfo.ProjectLanguage.Should().Be(ProjectLanguages.CSharp, "Unexpected ProjectLanguage");
            reloadedProjectInfo.ProjectType.Should().Be(ProjectType.Test, "Unexpected ProjectType");
            reloadedProjectInfo.ProjectGuid.Should().Be(projectGuid, "Unexpected ProjectGuid");
            reloadedProjectInfo.ProjectName.Should().Be("MyProject", "Unexpected ProjectName");
            reloadedProjectInfo.IsExcluded.Should().BeFalse("Unexpected IsExcluded");
            reloadedProjectInfo.Configuration.Should().Be("conf-1");
            reloadedProjectInfo.Platform.Should().Be("plat-1");
            reloadedProjectInfo.TargetFramework.Should().Be("target-1");
        }
        public void WriteProjectInfoFile_AnalysisSettings()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            Guid projectGuid = Guid.NewGuid();

            WriteProjectInfoFile task = new WriteProjectInfoFile();

            DummyBuildEngine buildEngine = new DummyBuildEngine();
            task.BuildEngine = buildEngine;
            task.FullProjectPath = "x:\\analysisSettings.csproj";
            task.IsTest = false;
            task.OutputFolder = testFolder;
            task.ProjectGuid = projectGuid.ToString("B");
            task.ProjectName = "MyProject";
            task.ProjectLanguage = "C#";

            // Example of a valid setting:
            // <SonarQubeSetting Include="sonar.resharper.projectname">
            //    <Value>C:\zzz\reportlocation.xxx</Value>
            // </SonarQubeSetting>                

            List<ITaskItem> settingsInputs = new List<ITaskItem>();

            // Add invalid task items
            // Note: the TaskItem class won't allow the item spec or metadata values to be null,
            // so we aren't testing those
            settingsInputs.Add(CreateMetadataItem("invalid.missing.value.metadata", "NotValueMetadata", "missing value 1")); // value field is missing
            settingsInputs.Add(CreateAnalysisSettingTaskItem(" ", "should be ignored - key is whitespace only")); // whitespace key
            settingsInputs.Add(CreateAnalysisSettingTaskItem("invalid spaces in key", "spaces.in.key")); // spaces in key
            settingsInputs.Add(CreateAnalysisSettingTaskItem(" invalid.key.has.leading.whitespace", "leading whitespace in key"));
            settingsInputs.Add(CreateAnalysisSettingTaskItem("invalid.key.has.trailing.whitespace ", "trailing whitespace in key"));
            settingsInputs.Add(CreateAnalysisSettingTaskItem(".invalid.non.alpha.first.character", "non alpha first character"));

            // Add valid task items
            settingsInputs.Add(CreateAnalysisSettingTaskItem("valid.setting.1", @"c:\dir1\dir2\file.txt"));
            settingsInputs.Add(CreateAnalysisSettingTaskItem("valid.value.is.whitespace.only", " "));
            settingsInputs.Add(CreateMetadataItem("valid.metadata.name.is.case.insensitive", BuildTaskConstants.SettingValueMetadataName.ToUpperInvariant(), "uppercase metadata name")); // metadata name is in the wrong case
            settingsInputs.Add(CreateAnalysisSettingTaskItem("valid.value.has.whitespace", "valid setting with whitespace"));
            settingsInputs.Add(CreateAnalysisSettingTaskItem("X", "single character key"));
            settingsInputs.Add(CreateAnalysisSettingTaskItem("Y...", "single character followed by periods"));
            settingsInputs.Add(CreateAnalysisSettingTaskItem("7B3B7244-5031-4D74-9BBD-3316E6B5E7D5.sonar.projectName", "guid followed by key"));

            task.AnalysisSettings = settingsInputs.ToArray();

            // Act
            ProjectInfo createdProjectInfo;
            createdProjectInfo = ExecuteAndCheckSucceeds(task, testFolder);

            // Assert
            buildEngine.AssertSingleWarningExists("invalid.missing.value.metadata");
            // Can't easily check for the message complaining against the empty key
            buildEngine.AssertSingleWarningExists("invalid spaces in key");
            buildEngine.AssertSingleWarningExists(" invalid.key.has.leading.whitespace");
            buildEngine.AssertSingleWarningExists("invalid.key.has.trailing.whitespace ");
            buildEngine.AssertSingleWarningExists(".invalid.non.alpha.first.character");

            AssertAnalysisSettingExists(createdProjectInfo, "valid.setting.1", @"c:\dir1\dir2\file.txt");
            AssertAnalysisSettingExists(createdProjectInfo, "valid.value.is.whitespace.only", null);
            AssertAnalysisSettingExists(createdProjectInfo, "valid.value.has.whitespace", "valid setting with whitespace");
            AssertAnalysisSettingExists(createdProjectInfo, "valid.metadata.name.is.case.insensitive", "uppercase metadata name");
            AssertAnalysisSettingExists(createdProjectInfo, "X", "single character key");
            AssertAnalysisSettingExists(createdProjectInfo, "Y...", "single character followed by periods");
            AssertAnalysisSettingExists(createdProjectInfo, "7B3B7244-5031-4D74-9BBD-3316E6B5E7D5.sonar.projectName", "guid followed by key");

            AssertExpectedAnalysisSettingsCount(7, createdProjectInfo);
        }
        [WorkItem(50)] // Regression test for Bug 50:MSBuild projects with missing ProjectGuids cause the build to fail
        public void WriteProjectInfoFile_MissingProjectGuid()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            WriteProjectInfoFile task = new WriteProjectInfoFile();
            task.FullProjectPath = "c:\\fullPath\\project.proj";
            task.IsTest = true;
            task.OutputFolder = testFolder;
            task.ProjectName = "ProjectWithoutProjectGuid";
            task.ProjectLanguage = "C#";
            // No analysis results are supplied

            // Act
            DummyBuildEngine engine = new DummyBuildEngine();
            task.BuildEngine = engine;
            bool success = task.Execute();

            // Assert
            Assert.IsTrue(success, "Not expecting the task to fail as this would fail the build");
            engine.AssertNoErrors();
            Assert.AreEqual(1, engine.Warnings.Count, "Expecting a build warning as the ProjectGuid is missing");

            BuildWarningEventArgs firstWarning = engine.Warnings[0];
            Assert.IsNotNull(firstWarning.Message, "Warning message should not be null");

            string projectInfoFilePath = Path.Combine(testFolder, ExpectedProjectInfoFileName);
            Assert.IsFalse(File.Exists(projectInfoFilePath), "Not expecting the project info file to have been created");
        }
        public void WriteProjectInfoFile_UnrecognisedLanguages()
        {
            // Arrange
            WriteProjectInfoFile task = new WriteProjectInfoFile();
            task.FullProjectPath = "c:\\fullPath\\project.proj";
            task.IsTest = true;
            task.ProjectName = "UnrecognisedLanguageProject";
            task.ProjectGuid = Guid.NewGuid().ToString("B");
           
            // 1. Null language
            task.ProjectLanguage = null;
            task.OutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "null.language");

            ProjectInfo actual = ExecuteAndCheckSucceeds(task, task.OutputFolder);
            Assert.IsNull(actual.ProjectLanguage, "Expecting the language to be null");
        
            // 2. Unrecognised language
            task.ProjectLanguage = "unrecognised language";
            task.OutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "unrecog.language");

            actual = ExecuteAndCheckSucceeds(task, task.OutputFolder);
            Assert.AreEqual("unrecognised language", actual.ProjectLanguage, "Unexpected value for project language");
        }
예제 #23
0
        public void WriteProjectInfoFile_AnalysisSettings()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            Guid projectGuid = Guid.NewGuid();

            WriteProjectInfoFile task = new WriteProjectInfoFile();

            DummyBuildEngine buildEngine = new DummyBuildEngine();

            task.BuildEngine     = buildEngine;
            task.FullProjectPath = "x:\\analysisSettings.csproj";
            task.IsTest          = false;
            task.OutputFolder    = testFolder;
            task.ProjectGuid     = projectGuid.ToString("B");
            task.ProjectName     = "MyProject";
            task.ProjectLanguage = "C#";

            // Example of a valid setting:
            // <SonarQubeSetting Include="sonar.resharper.projectname">
            //    <Value>C:\zzz\reportlocation.xxx</Value>
            // </SonarQubeSetting>

            List <ITaskItem> settingsInputs = new List <ITaskItem>
            {
                // Add invalid task items
                // Note: the TaskItem class won't allow the item spec or metadata values to be null,
                // so we aren't testing those
                CreateMetadataItem("invalid.missing.value.metadata", "NotValueMetadata", "missing value 1"), // value field is missing
                CreateAnalysisSettingTaskItem(" ", "should be ignored - key is whitespace only"),            // whitespace key
                CreateAnalysisSettingTaskItem("invalid spaces in key", "spaces.in.key"),                     // spaces in key
                CreateAnalysisSettingTaskItem(" invalid.key.has.leading.whitespace", "leading whitespace in key"),
                CreateAnalysisSettingTaskItem("invalid.key.has.trailing.whitespace ", "trailing whitespace in key"),
                CreateAnalysisSettingTaskItem(".invalid.non.alpha.first.character", "non alpha first character"),

                // Add valid task items
                CreateAnalysisSettingTaskItem("valid.setting.1", @"c:\dir1\dir2\file.txt"),
                CreateAnalysisSettingTaskItem("valid.value.is.whitespace.only", " "),
                CreateMetadataItem("valid.metadata.name.is.case.insensitive", BuildTaskConstants.SettingValueMetadataName.ToUpperInvariant(), "uppercase metadata name"), // metadata name is in the wrong case
                CreateAnalysisSettingTaskItem("valid.value.has.whitespace", "valid setting with whitespace"),
                CreateAnalysisSettingTaskItem("X", "single character key"),
                CreateAnalysisSettingTaskItem("Y...", "single character followed by periods"),
                CreateAnalysisSettingTaskItem("7B3B7244-5031-4D74-9BBD-3316E6B5E7D5.sonar.projectName", "guid followed by key")
            };

            task.AnalysisSettings = settingsInputs.ToArray();

            // Act
            ProjectInfo createdProjectInfo;

            createdProjectInfo = ExecuteAndCheckSucceeds(task, testFolder);

            // Assert
            buildEngine.AssertSingleWarningExists("invalid.missing.value.metadata");
            // Can't easily check for the message complaining against the empty key
            buildEngine.AssertSingleWarningExists("invalid spaces in key");
            buildEngine.AssertSingleWarningExists(" invalid.key.has.leading.whitespace");
            buildEngine.AssertSingleWarningExists("invalid.key.has.trailing.whitespace ");
            buildEngine.AssertSingleWarningExists(".invalid.non.alpha.first.character");

            AssertAnalysisSettingExists(createdProjectInfo, "valid.setting.1", @"c:\dir1\dir2\file.txt");
            AssertAnalysisSettingExists(createdProjectInfo, "valid.value.is.whitespace.only", null);
            AssertAnalysisSettingExists(createdProjectInfo, "valid.value.has.whitespace", "valid setting with whitespace");
            AssertAnalysisSettingExists(createdProjectInfo, "valid.metadata.name.is.case.insensitive", "uppercase metadata name");
            AssertAnalysisSettingExists(createdProjectInfo, "X", "single character key");
            AssertAnalysisSettingExists(createdProjectInfo, "Y...", "single character followed by periods");
            AssertAnalysisSettingExists(createdProjectInfo, "7B3B7244-5031-4D74-9BBD-3316E6B5E7D5.sonar.projectName", "guid followed by key");

            AssertExpectedAnalysisSettingsCount(7, createdProjectInfo);
        }