private void ProjectSystemFilter_IsAccepted_SupportedNotExcludedProject_IsKnownTestProject(string projectExtension) { // Arrange var testSubject = this.CreateTestSubject(); var project = new LegacyProjectMock("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"); }
private void ProjectSystemFilter_IsAccepted_SupportedNotExcludedProject_NotExcludedTestProject_EvaluateRegex(string projectExtension) { // Arrange var testSubject = this.CreateTestSubject(); var project = new LegacyProjectMock("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"); }