public void ProjectExcludePropertyToggleCommand_QueryStatus_SingleProject_CheckedStateReflectsValues() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.propertyManager); var project = new ProjectMock("face.proj"); project.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { project }; // Test case 1: no property -> not checked // Act testSubject.QueryStatus(command, null); // Assert command.Checked.Should().BeFalse("Expected command to be unchecked"); // Test case 1: true -> is checked this.SetExcludeProperty(project, true); // Act testSubject.QueryStatus(command, null); // Assert command.Checked.Should().BeTrue("Expected command to be checked"); }
public void IsBindingRequired_ProjectDoesNotReferenceSolutionRuleset_True() { var bindingConfiguration = GetBindingConfiguration(); var projectMock = new ProjectMock("c:\\test.csproj"); projectMock.SetCSProjectKind(); var solutionAdditionalFilePath = GetSolutionAdditionalFilePath(bindingConfiguration); fileSystemMock.Setup(x => x.File.Exists(solutionAdditionalFilePath)).Returns(true); additionalFileReferenceCheckerMock .Setup(x => x.IsReferenced(projectMock, solutionAdditionalFilePath)) .Returns(true); var solutionRuleSetFilePath = SetupSolutionRulesetExists(bindingConfiguration, isRuleSetLoadable: true); rulesetReferenceCheckerMock .Setup(x => x.IsReferencedByAllDeclarations(projectMock, solutionRuleSetFilePath)) .Returns(false); var result = testSubject.IsBindingRequired(bindingConfiguration, projectMock); result.Should().BeTrue(); additionalFileReferenceCheckerMock.VerifyAll(); rulesetReferenceCheckerMock.VerifyAll(); }
public void ProjectExcludePropertyToggleCommand_Invoke_SingleProject_TogglesValue() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); command.Enabled = true; var testSubject = new ProjectExcludePropertyToggleCommand(propertyManager); var project = new ProjectMock("projecty.csproj"); project.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { project }; // Test case 1: true --toggle--> clears property this.SetExcludeProperty(project, true); // Act testSubject.Invoke(command, null); // Assert this.VerifyExcludeProperty(project, null); // Test case 2: no property --toggle--> true this.SetExcludeProperty(project, null); // Act testSubject.Invoke(command, null); // Assert this.VerifyExcludeProperty(project, true); }
public void ProjectExcludePropertyToggleCommand_Invoke_SingleProject_TogglesValue() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); command.Enabled = true; var testSubject = new ProjectExcludePropertyToggleCommand(serviceProvider); var project = new ProjectMock("projecty.csproj"); project.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { project }; // Test case 1: true --toggle--> clears property this.SetExcludeProperty(project, true); // Act testSubject.Invoke(command, null); // Verify this.VerifyExcludeProperty(project, null); // Test case 2: no property --toggle--> true this.SetExcludeProperty(project, null); // Act testSubject.Invoke(command, null); // Verify this.VerifyExcludeProperty(project, true); }
public void ProjectTestPropertySetCommand_QueryStatus_MultipleProjects_MixedPropValues_IsUnchecked() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); var p3 = new ProjectMock("good3.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); p3.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2, p3 }; this.SetTestProperty(p1, true); this.SetTestProperty(p2, null); this.SetTestProperty(p3, false); foreach (ProjectTestPropertySetCommand testSubject in this.CreateCommands()) { // Act testSubject.QueryStatus(command, null); // Assert command.Checked.Should().BeFalse($"Expected command[{testSubject.CommandPropertyValue}] to be unchecked"); } }
public void ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_ConsistentPropValues_CheckedStateReflectsValues() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.propertyManager); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2 }; // Test case 1: no property -> not checked // Act testSubject.QueryStatus(command, null); // Assert command.Checked.Should().BeFalse("Expected command to be unchecked"); // Test case 2: all true -> is checked this.SetExcludeProperty(p1, true); this.SetExcludeProperty(p2, true); // Act testSubject.QueryStatus(command, null); // Assert command.Checked.Should().BeTrue("Expected command to be checked"); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_MixedPropValues_IsUnchecked() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.propertyManager); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); var p3 = new ProjectMock("good3.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); p3.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2, p3 }; this.SetExcludeProperty(p1, true); this.SetExcludeProperty(p2, null); this.SetExcludeProperty(p3, false); // Act testSubject.QueryStatus(command, null); // Assert command.Checked.Should().BeFalse("Expected command to be unchecked"); }
public void BindingUtilities_IsProjectLevelBindingRequired() { // 1. C# -> binding is required var csProject = new ProjectMock("c:\\foo.proj"); csProject.SetCSProjectKind(); BindingRefactoringDumpingGround.IsProjectLevelBindingRequired(csProject).Should().BeTrue(); // 2. VB.NET -> binding is required var vbProject = new ProjectMock("c:\\foo.proj"); vbProject.SetVBProjectKind(); BindingRefactoringDumpingGround.IsProjectLevelBindingRequired(vbProject).Should().BeTrue(); // 3. Cpp -> binding is required var cppProject = new ProjectMock("c:\\foo.proj"); cppProject.ProjectKind = ProjectSystemHelper.CppProjectKind; BindingRefactoringDumpingGround.IsProjectLevelBindingRequired(cppProject).Should().BeFalse(); // 4. Other -> binding is not required var otherProject = new ProjectMock("c:\\foo.proj"); otherProject.ProjectKind = "{" + Guid.NewGuid().ToString() + "}"; BindingRefactoringDumpingGround.IsProjectLevelBindingRequired(otherProject).Should().BeFalse(); }
public void ProjectExcludePropertyToggleCommand_Invoke_MultipleProjects_MixedPropValues_SetIsExcludedTrue() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); command.Enabled = true; var testSubject = new ProjectExcludePropertyToggleCommand(this.propertyManager); var p1 = new ProjectMock("trueProj.proj"); var p2 = new ProjectMock("nullProj.proj"); var p3 = new ProjectMock("trueProj.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); p3.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2, p3 }; this.SetExcludeProperty(p1, true); this.SetExcludeProperty(p2, null); this.SetExcludeProperty(p3, false); // Act testSubject.Invoke(command, null); // Assert this.VerifyExcludeProperty(p1, true); this.VerifyExcludeProperty(p2, true); this.VerifyExcludeProperty(p3, true); }
public void ProjectBindingOperation_Prepare_AdditionalFileAlreadyReferenced_AdditionalFileConflictNotChecked() { var testSubject = CreateTestSubject(); projectMock.SetCSProjectKind(); testSubject.Initialize(); projectSystemHelper.IsFileInProjectAction = (project, s) => project == projectMock && s == cSharpVBBindingConfig.AdditionalFile.Path; testSubject.Prepare(CancellationToken.None); additionalFileConflictChecker.VerifyNoOtherCalls(); }
private void ProjectSystemFilter_IsAccepted_SupportedProject_ProjectExcludedViaProjectProperty(string projectExtension) { // Arrange 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); // 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"); }
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"); }
private void ProjectSystemFilter_IsAccepted_SupportedNotExcludedProject_TestProjectExcludedViaProjectProperty(string projectExtension) { // Setup 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); // 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"); }
public void Get_CSharpProject_CSharpVBProjectBinderReturned() { var project = new ProjectMock("c:\\foo.proj"); project.SetCSProjectKind(); using (new AssertIgnoreScope()) { var configProjectBinder = testSubject.Get(project); configProjectBinder.Should().BeOfType <CSharpVBProjectBinder>(); } }
public void IsAccepted_SharedProject_ReturnsFalse() { // Arrange var project = new ProjectMock("shared1.shproj"); project.SetCSProjectKind(); project = new ProjectMock("shared1.SHPROJ"); project.SetCSProjectKind(); // Act and Assert testSubject.IsAccepted(project).Should().BeFalse(); }
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"); }
public void IsBindingRequired_ProjectLanguageIsNotSupported_False() { var projectMock = new ProjectMock("c:\\test.csproj"); projectMock.SetCSProjectKind(); var bindingConfiguration = new BindingConfiguration(new BoundSonarQubeProject(new Uri("http://test.com"), "key", "name"), SonarLintMode.Connected, "c:\\"); var result = testSubject.IsBindingRequired(bindingConfiguration, projectMock); result.Should().Be(false); solutionRuleSetsInformationProviderMock.VerifyNoOtherCalls(); fileSystemMock.VerifyNoOtherCalls(); }
public void ProjectTestPropertySetCommand_QueryStatus_MultipleProjects_ConsistentPropValues_CheckedStateReflectsValues() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2 }; foreach (ProjectTestPropertySetCommand testSubject in this.CreateCommands()) { // Test case 1: properties are both null // Arrange this.SetTestProperty(p1, null); this.SetTestProperty(p2, null); // Act testSubject.QueryStatus(command, null); // Assert this.VerifyCommandCheckedStatus(command, testSubject, null); // Test case 2: properties are both true this.SetTestProperty(p1, true); this.SetTestProperty(p2, true); // Act testSubject.QueryStatus(command, null); // Assert this.VerifyCommandCheckedStatus(command, testSubject, true); // Test case 3: properties are both false this.SetTestProperty(p1, false); this.SetTestProperty(p2, false); // Act testSubject.QueryStatus(command, null); // Assert this.VerifyCommandCheckedStatus(command, testSubject, false); } }
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"); }
public void IsBindingRequired_SolutionHasRulesetButFileFailsToLoad_True() { var bindingConfiguration = GetBindingConfiguration(); var projectMock = new ProjectMock("c:\\test.csproj"); projectMock.SetCSProjectKind(); SetupSolutionAdditionalFileExists(bindingConfiguration); SetupSolutionRulesetExists(bindingConfiguration, isRuleSetLoadable: false); var result = testSubject.IsBindingRequired(bindingConfiguration, projectMock); result.Should().BeTrue(); ruleSetSerializerMock.VerifyAll(); VerifyProjectAdditionalFileNotChecked(); VerifyProjectRulesetsNotChecked(); }
public void ProjectTestPropertySetCommand_QueryStatus_SingleProject_CheckedStateReflectsValues() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var project = new ProjectMock("face.proj"); project.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { project }; foreach (ProjectTestPropertySetCommand testSubject in this.CreateCommands()) { // Test case 1: property is null // Arrange this.SetTestProperty(project, null); // Act testSubject.QueryStatus(command, null); // Assert this.VerifyCommandCheckedStatus(command, testSubject, null); // Test case 2: property is true this.SetTestProperty(project, true); // Act testSubject.QueryStatus(command, null); // Assert this.VerifyCommandCheckedStatus(command, testSubject, true); // Test case 3: property is false this.SetTestProperty(project, false); // Act testSubject.QueryStatus(command, null); // Assert this.VerifyCommandCheckedStatus(command, testSubject, false); } }
public void ProjectSonarLintMenuCommand_QueryStatus_HasUnsupportedProject_IsDisabledIsHidden() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectSonarLintMenuCommand(serviceProvider); var p1 = new ProjectMock("cs.proj"); p1.SetCSProjectKind(); var p2 = new ProjectMock("cpp.proj"); this.projectSystem.SelectedProjects = new[] { p1, p2 }; // Act testSubject.QueryStatus(command, null); // Verify Assert.IsFalse(command.Enabled, "Expected command to be disabled"); Assert.IsFalse(command.Visible, "Expected command to be hidden"); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_SingleProject_SupportedProject_IsEnabledIsVisible() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(serviceProvider); var project = new ProjectMock("mcproject.csproj"); project.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { project }; // Act testSubject.QueryStatus(command, null); // Verify Assert.IsTrue(command.Enabled, "Expected command to be enabled"); Assert.IsTrue(command.Visible, "Expected command to be visible"); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_SingleProject_SupportedProject_IsEnabledIsVisible() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(propertyManager); var project = new ProjectMock("mcproject.csproj"); project.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { project }; // Act testSubject.QueryStatus(command, null); // Assert command.Enabled.Should().BeTrue("Expected command to be enabled"); command.Visible.Should().BeTrue("Expected command to be visible"); }
public void IsBindingRequired_SolutionHasNoAdditionalFile_True() { var bindingConfiguration = GetBindingConfiguration(); var projectMock = new ProjectMock("c:\\test.csproj"); projectMock.SetCSProjectKind(); var mockAdditionalFilePath = GetSolutionAdditionalFilePath(bindingConfiguration); fileSystemMock.Setup(x => x.File.Exists(mockAdditionalFilePath)).Returns(false); var result = testSubject.IsBindingRequired(bindingConfiguration, projectMock); result.Should().BeTrue(); fileSystemMock.VerifyAll(); VerifySolutionRulesetNotChecked(bindingConfiguration); VerifyProjectAdditionalFileNotChecked(); VerifyProjectRulesetsNotChecked(); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_MixedSupportedProject_IsDisabledIsHidden() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.propertyManager); var unsupportedProject = new ProjectMock("bad.proj"); var supportedProject = new ProjectMock("good.proj"); supportedProject.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { unsupportedProject, supportedProject }; // Act testSubject.QueryStatus(command, null); // Assert command.Enabled.Should().BeFalse("Expected command to be disabled"); command.Visible.Should().BeFalse("Expected command to be hidden"); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_MixedSupportedProject_IsDisabledIsHidden() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.serviceProvider); var unsupportedProject = new ProjectMock("bad.proj"); var supportedProject = new ProjectMock("good.proj"); supportedProject.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { unsupportedProject, supportedProject }; // Act testSubject.QueryStatus(command, null); // Verify Assert.IsFalse(command.Enabled, "Expected command to be disabled"); Assert.IsFalse(command.Visible, "Expected command to be hidden"); }
public void ProjectSonarLintMenuCommand_QueryStatus_HasUnsupportedProject_IsDisabledIsHidden() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectSonarLintMenuCommand(serviceProvider); var p1 = new ProjectMock("cs.proj"); p1.SetCSProjectKind(); var p2 = new ProjectMock("cpp.proj"); this.projectSystem.SelectedProjects = new[] { p1, p2 }; // Act testSubject.QueryStatus(command, null); // Assert command.Enabled.Should().BeFalse("Expected command to be disabled"); command.Visible.Should().BeFalse("Expected command to be hidden"); }
public void ProjectTestPropertySetCommand_Invoke_SingleProject_SetsValue() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); command.Enabled = true; var project = new ProjectMock("project.csproj"); project.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { project }; // Test case 1: test (true) // Arrange var testSubject1 = new ProjectTestPropertySetCommand(propertyManager, true); // Act testSubject1.Invoke(command, null); // Assert this.VerifyTestProperty(project, true); // Test case 2: non-test (false) var testSubject2 = new ProjectTestPropertySetCommand(propertyManager, false); // Act testSubject2.Invoke(command, null); // Assert this.VerifyTestProperty(project, false); // Test case 3: auto detect (null) var testSubject3 = new ProjectTestPropertySetCommand(propertyManager, null); // Act testSubject3.Invoke(command, null); // Assert this.VerifyTestProperty(project, null); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_AllSupportedProjects_IsEnabledIsVisible() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.serviceProvider); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); this.projectSystem.SelectedProjects = new [] { p1, p2 }; // Act testSubject.QueryStatus(command, null); // Verify Assert.IsTrue(command.Enabled, "Expected command to be enabled"); Assert.IsTrue(command.Visible, "Expected command to be visible"); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_AllSupportedProjects_IsEnabledIsVisible() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.propertyManager); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); this.projectSystem.SelectedProjects = new [] { p1, p2 }; // Act testSubject.QueryStatus(command, null); // Assert command.Enabled.Should().BeTrue("Expected command to be enabled"); command.Visible.Should().BeTrue("Expected command to be visible"); }
public void ProjectSonarLintMenuCommand_QueryStatus_AllSupportedProjects_IsEnabledIsVisible() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectSonarLintMenuCommand(serviceProvider); var p1 = new ProjectMock("cs1.proj"); p1.SetCSProjectKind(); var p2 = new ProjectMock("cs2.proj"); p2.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2 }; // Act testSubject.QueryStatus(command, null); // Assert command.Enabled.Should().BeTrue("Expected command to be enabled"); command.Visible.Should().BeTrue("Expected command to be visible"); }
public void ProjectExcludePropertyToggleCommand_Invoke_MultipleProjects_ConsistentPropValues_TogglesValues() { // Arrange OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); command.Enabled = true; var testSubject = new ProjectExcludePropertyToggleCommand(this.propertyManager); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2 }; // Test case 1: all not set --toggle--> all true // Act testSubject.Invoke(command, null); // Assert this.VerifyExcludeProperty(p1, true); this.VerifyExcludeProperty(p2, true); // Test case 2: all true --toggle--> all not set // Arrange this.SetExcludeProperty(p1, true); this.SetExcludeProperty(p2, true); // Act testSubject.Invoke(command, null); // Assert this.VerifyExcludeProperty(p1, null); this.VerifyExcludeProperty(p2, null); }
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"); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_SingleProject_CheckedStateReflectsValues() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.serviceProvider); var project = new ProjectMock("face.proj"); project.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { project }; // Test case 1: no property -> not checked // Act testSubject.QueryStatus(command, null); // Verify Assert.IsFalse(command.Checked, "Expected command to be unchecked"); // Test case 1: true -> is checked this.SetExcludeProperty(project, true); // Act testSubject.QueryStatus(command, null); // Verify Assert.IsTrue(command.Checked, "Expected command to be checked"); }
public void ProjectExcludePropertyToggleCommand_Invoke_MultipleProjects_ConsistentPropValues_TogglesValues() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); command.Enabled = true; var testSubject = new ProjectExcludePropertyToggleCommand(this.serviceProvider); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2 }; // Test case 1: all not set --toggle--> all true // Act testSubject.Invoke(command, null); // Verify this.VerifyExcludeProperty(p1, true); this.VerifyExcludeProperty(p2, true); // Test case 2: all true --toggle--> all not set // Setup this.SetExcludeProperty(p1, true); this.SetExcludeProperty(p2, true); // Act testSubject.Invoke(command, null); // Verify this.VerifyExcludeProperty(p1, null); this.VerifyExcludeProperty(p2, null); }
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 ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_MixedSupportedProject_IsDisabledIsHidden() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.serviceProvider); var unsupportedProject = new ProjectMock("bad.proj"); var supportedProject = new ProjectMock("good.proj"); supportedProject.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { unsupportedProject, supportedProject }; // Act testSubject.QueryStatus(command, null); // Verify Assert.IsFalse(command.Enabled, "Expected command to be disabled"); Assert.IsFalse(command.Visible, "Expected command to be hidden"); }
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 ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_AllSupportedProjects_IsEnabledIsVisible() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.serviceProvider); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); this.projectSystem.SelectedProjects = new [] { p1, p2 }; // Act testSubject.QueryStatus(command, null); // Verify Assert.IsTrue(command.Enabled, "Expected command to be enabled"); Assert.IsTrue(command.Visible, "Expected command to be visible"); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_MixedPropValues_IsUnchecked() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.serviceProvider); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); var p3 = new ProjectMock("good3.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); p3.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2, p3 }; this.SetExcludeProperty(p1, true); this.SetExcludeProperty(p2, null); this.SetExcludeProperty(p3, false); // Act testSubject.QueryStatus(command, null); // Verify Assert.IsFalse(command.Checked, "Expected command to be unchecked"); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_MultipleProjects_ConsistentPropValues_CheckedStateReflectsValues() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(this.serviceProvider); var p1 = new ProjectMock("good1.proj"); var p2 = new ProjectMock("good2.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2 }; // Test case 1: no property -> not checked // Act testSubject.QueryStatus(command, null); // Verify Assert.IsFalse(command.Checked, "Expected command to be unchecked"); // Test case 2: all true -> is checked this.SetExcludeProperty(p1, true); this.SetExcludeProperty(p2, true); // Act testSubject.QueryStatus(command, null); // Verify Assert.IsTrue(command.Checked, "Expected command to be checked"); }
public void ProjectExcludePropertyToggleCommand_Invoke_MultipleProjects_MixedPropValues_SetIsExcludedTrue() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); command.Enabled = true; var testSubject = new ProjectExcludePropertyToggleCommand(this.serviceProvider); var p1 = new ProjectMock("trueProj.proj"); var p2 = new ProjectMock("nullProj.proj"); var p3 = new ProjectMock("trueProj.proj"); p1.SetCSProjectKind(); p2.SetCSProjectKind(); p3.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { p1, p2, p3 }; this.SetExcludeProperty(p1, true); this.SetExcludeProperty(p2, null); this.SetExcludeProperty(p3, false); // Act testSubject.Invoke(command, null); // Verify this.VerifyExcludeProperty(p1, true); this.VerifyExcludeProperty(p2, true); this.VerifyExcludeProperty(p3, true); }
public void ProjectExcludePropertyToggleCommand_QueryStatus_SingleProject_SupportedProject_IsEnabledIsVisible() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(serviceProvider); var project = new ProjectMock("mcproject.csproj"); project.SetCSProjectKind(); this.projectSystem.SelectedProjects = new[] { project }; // Act testSubject.QueryStatus(command, null); // Verify Assert.IsTrue(command.Enabled, "Expected command to be enabled"); Assert.IsTrue(command.Visible, "Expected command to be visible"); }