Пример #1
0
        private void IsAccepted_SupportedProject_ProjectExcludedViaProjectProperty_Impl(string projectTypeGuid)
        {
            // Arrange
            var project = new ProjectMock("supported.proj")
            {
                ProjectKind = projectTypeGuid
            };

            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "False"); // Should not matter

            // Test case 1: missing property-> is accepted
            // Act
            var result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Project with missing property SonarQubeExclude should be accepted");

            // Test case 2: property non-bool -> is accepted
            // Arrange
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, string.Empty);

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Project with non-bool property SonarQubeExclude should be accepted");

            // Test case 3: property non-bool, non-empty -> is accepted
            // Arrange
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "abc");

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Project with non-bool property SonarQubeExclude should be accepted");

            // Test case 4: property true -> not accepted
            // Arrange
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "true");

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeFalse("Project with property SonarQubeExclude=false should NOT be accepted");

            // Test case 5: property false -> is accepted
            // Arrange
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "false");

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Project with property SonarQubeExclude=true should be accepted");
        }
Пример #2
0
        private void ProjectSystemFilter_IsAccepted_SupportedProject_ProjectExcludedViaProjectProperty(string projectExtension)
        {
            // Setup
            var testSubject = this.CreateTestSubject();
            var project     = new ProjectMock("supported" + projectExtension);

            project.SetCSProjectKind();
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "False"); // Should not matter

            // Test case 1: missing property-> is accepted
            // Act
            var result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with missing property SonarQubeExclude should be accepted");

            // Test case 2: property non-bool -> is accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, string.Empty);

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with non-bool property SonarQubeExclude should be accepted");

            // Test case 3: property non-bool, non-empty -> is accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "abc");

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with non-bool property SonarQubeExclude should be accepted");

            // Test case 4: property true -> not accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "true");

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsFalse(result, "Project with property SonarQubeExclude=false should NOT be accepted");

            // Test case 5: property false -> is accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "false");

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with property SonarQubeExclude=true should be accepted");
        }
Пример #3
0
        private void ProjectSystemFilter_IsAccepted_SupportedNotExcludedProject_TestProjectExcludedViaProjectProperty(string projectExtension)
        {
            // Arrange
            var testSubject = this.CreateTestSubject();

            var project = new ProjectMock("supported" + projectExtension);

            project.SetCSProjectKind();
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "false"); // Should evaluate test projects even if false

            // Test case 1: missing property -> accepted
            // Act
            var result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Project with missing property SonarQubeTestProject should be accepted");

            // Test case 2: empty -> accepted
            // Arrange
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, string.Empty);

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Project with non-bool property SonarQubeTestProject should be accepted");

            // Test case 3: non-bool, non-empty -> not accepted
            // Arrange
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "123");

            // Act
            result = testSubject.IsAccepted(project);

            // Test case 4: property true -> not accepted
            // Arrange
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "true");

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeFalse("Project with property SonarQubeTestProject=false should NOT be accepted");

            // Test case 5: property false -> is accepted
            // Arrange
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "false");

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Project with property SonarQubeTestProject=true should be accepted");
        }
Пример #4
0
        private void ProjectSystemFilter_IsAccepted_SupportedNotExcludedProject_IsKnownTestProject(string projectExtension)
        {
            // Arrange
            var testSubject = this.CreateTestSubject();

            var project = new ProjectMock("knownproject" + projectExtension);

            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "false"); // Should evaluate test projects even if false
            project.SetCSProjectKind();

            // Case 1: Test not test project kind, test project exclude not set
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, ""); // Should not continue with evaluation if has boolean value

            // Act
            bool result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Project not a known test project");

            // Case 2: Test project kind, test project exclude not set
            project.SetTestProject();

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeFalse("Project of known test project type should NOT be accepted");

            // Case 3: SonarQubeTestProjectBuildPropertyKey == false, should take precedence over project kind condition
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "false");
            project.ClearProjectKind();

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Should be accepted since test project is explicitly not-excluded");

            // Case 4: SonarQubeTestProjectBuildPropertyKey == true, should take precedence over project kind condition
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "true");
            project.ClearProjectKind();

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeFalse("Should not be accepted since test project is excluded");
        }
Пример #5
0
        private void ProjectSystemFilter_IsAccepted_SupportedNotExcludedProject_NotExcludedTestProject_EvaluateRegex(string projectExtension)
        {
            // Arrange
            var testSubject = this.CreateTestSubject();
            var project     = new ProjectMock("foobarfoobar" + projectExtension);

            project.SetCSProjectKind();

            // Case 1: Regex match
            testSubject.SetTestRegex(new Regex(".*barfoo.*", RegexOptions.None, TimeSpan.FromSeconds(1)));

            // Act
            var result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeFalse("Project with name that matches test regex should NOT be accepted");

            // Case 2: Regex doesn't match
            testSubject.SetTestRegex(new Regex(".*notfound.*", RegexOptions.None, TimeSpan.FromSeconds(1)));

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Project with name that does not match test regex should be accepted");

            // Case 3: SonarQubeTestProjectBuildPropertyKey == false, should take precedence over regex condition
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "false");

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeTrue("Should be accepted since test project is explicitly not-excluded");

            // Case 4: SonarQubeTestProjectBuildPropertyKey == true, should take precedence over regex condition
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "true");
            project.ClearProjectKind();

            // Act
            result = testSubject.IsAccepted(project);

            // Assert
            result.Should().BeFalse("Should not be accepted since test project is excluded");
        }
Пример #6
0
        public void IsAccepted_UnrecognisedProjectType_ReturnsFalse()
        {
            // Arrange
            var project = new ProjectMock("unsupported.vcxproj");

            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "False"); // Should not matter

            // Act and Assert
            testSubject.IsAccepted(project).Should().BeFalse();
        }
        private void ProjectSystemFilter_IsAccepted_SupportedProject_ProjectExcludedViaProjectProperty(string projectExtension)
        {
            // Setup
            var testSubject = this.CreateTestSubject();
            var project = new ProjectMock("supported" + projectExtension);
            project.SetCSProjectKind();
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "False"); // Should not matter

            // Test case 1: missing property-> is accepted
            // Act
            var result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with missing property SonarQubeExclude should be accepted");

            // Test case 2: property non-bool -> is accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, string.Empty);

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with non-bool property SonarQubeExclude should be accepted");

            // Test case 3: property non-bool, non-empty -> is accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "abc");

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with non-bool property SonarQubeExclude should be accepted");

            // Test case 4: property true -> not accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "true");

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsFalse(result, "Project with property SonarQubeExclude=false should NOT be accepted");

            // Test case 5: property false -> is accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "false");

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with property SonarQubeExclude=true should be accepted");
        }
Пример #8
0
 private void SetExcludeProperty(ProjectMock project, bool?value)
 {
     if (value.GetValueOrDefault(false))
     {
         project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, value.Value.ToString());
     }
     else
     {
         project.ClearBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey);
     }
 }
 private void SetTestProperty(ProjectMock project, bool?value)
 {
     if (value.HasValue)
     {
         project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, value.Value.ToString());
     }
     else
     {
         project.ClearBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey);
     }
 }
        public void ProjectSystemFilter_IsAccepted_NoSupportedProject()
        {
            // Setup
            var testSubject = this.CreateTestSubject();

            var project = new ProjectMock("unsupported.vbproj");
            project.SetVBProjectKind(); // VB is not supported
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "False"); // Should not matter

            // Act
            var result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsFalse(result, "Project of unsupported language type should not be accepted");
        }
Пример #11
0
        public void IsAccepted_UnknownIfTestProject_ReturnsTrue()
        {
            // Arrange
            var project = new ProjectMock("supported.proj")
            {
                ProjectKind = ProjectSystemHelper.CSharpCoreProjectKind
            };

            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "False"); // Should not matter

            testProjectIndicatorMock.Setup(x => x.IsTestProject(project)).Returns((bool?)null);

            // Act and Assert
            testSubject.IsAccepted(project).Should().BeTrue();
        }
 private void SetExcludeProperty(ProjectMock project, bool? value)
 {
     if (value.GetValueOrDefault(false))
     {
         project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, value.Value.ToString());
     }
     else
     {
         project.ClearBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey);
     }
 }
        public void ProjectSystemFilter_IsAccepted_SupportedNotExcludedProject_NotExcludedTestProject_EvaluateRegex()
        {
            // Setup
            var testSubject = this.CreateTestSubject();
            var project = new ProjectMock("foobarfoobar.csproj");
            project.SetCSProjectKind();

            // Case 1: Regex match
            testSubject.SetTestRegex(new Regex(".*barfoo.*", RegexOptions.None, TimeSpan.FromSeconds(1)));

            // Act
            var result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsFalse(result, "Project with name that matches test regex should NOT be accepted");

            // Case 2: Regex doesn't match
            testSubject.SetTestRegex(new Regex(".*notfound.*", RegexOptions.None, TimeSpan.FromSeconds(1)));

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with name that does not match test regex should be accepted");

            // Case 3: SonarQubeTestProjectBuildPropertyKey == false, should take precedence over regex condition
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "false");

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Should be accepted since test project is explicitly not-excluded");

            // Case 4: SonarQubeTestProjectBuildPropertyKey == true, should take precedence over regex condition
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "true");
            project.ClearProjectKind();

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsFalse(result, "Should not be accepted since test project is excluded");
        }
        public void ProjectSystemFilter_IsAccepted_SupportedNotExcludedProject_IsKnownTestProject()
        {
            // Setup
            var testSubject = this.CreateTestSubject();

            var project = new ProjectMock("knownproject.csproj");
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "false"); // Should evaluate test projects even if false
            project.SetCSProjectKind();

            // Case 1: Test not test project kind, test project exclude not set
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, ""); // Should not continue with evaluation if has boolean value

            // Act
            bool result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project not a known test project");

            // Case 2: Test project kind, test project exclude not set
            project.SetTestProject();

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsFalse(result, "Project of known test project type should NOT be accepted");

            // Case 3: SonarQubeTestProjectBuildPropertyKey == false, should take precedence over project kind condition
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "false");
            project.ClearProjectKind();

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Should be accepted since test project is explicitly not-excluded");

            // Case 4: SonarQubeTestProjectBuildPropertyKey == true, should take precedence over project kind condition
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "true");
            project.ClearProjectKind();

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsFalse(result, "Should not be accepted since test project is excluded");
        }
        public void ProjectSystemFilter_IsAccepted_SupportedNotExcludedProject_TestProjectExcludedViaProjectProperty()
        {
            // Setup
            var testSubject = this.CreateTestSubject();

            var project = new ProjectMock("supported.csproj");
            project.SetCSProjectKind();
            project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, "false"); // Should evaluate test projects even if false

            // Test case 1: missing property -> accepted
            // Act
            var result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with missing property SonarQubeTestProject should be accepted");

            // Test case 2: empty -> accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, string.Empty);

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with non-bool property SonarQubeTestProject should be accepted");

            // Test case 3: non-bool, non-empty -> not accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "123");

            // Act
            result = testSubject.IsAccepted(project);

            // Test case 4: property true -> not accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "true");

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsFalse(result, "Project with property SonarQubeTestProject=false should NOT be accepted");

            // Test case 5: property false -> is accepted
            // Setup
            project.SetBuildProperty(Constants.SonarQubeTestProjectBuildPropertyKey, "false");

            // Act
            result = testSubject.IsAccepted(project);

            // Verify
            Assert.IsTrue(result, "Project with property SonarQubeTestProject=true should be accepted");
        }