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 IsBindingRequired_ProjectHasTwoLanguages_ReturnsIfAllLanguagesHaveConfigFiles(bool isFirstLanguageBound, bool isSecondLanguageBound, bool expectedResult) { var projectMock = new ProjectMock("c:\\test.csproj"); projectMock.SetProjectKind(new Guid(ProjectSystemHelper.CppProjectKind)); var bindingConfiguration = new BindingConfiguration(new BoundSonarQubeProject(new Uri("http://test.com"), "key", "name"), SonarLintMode.Connected, "c:\\"); var cppFilePath = bindingConfiguration.BuildPathUnderConfigDirectory(Language.Cpp.FileSuffixAndExtension); var cFilePath = bindingConfiguration.BuildPathUnderConfigDirectory(Language.C.FileSuffixAndExtension); fileSystemMock .Setup(x => x.File.Exists(cppFilePath)) .Returns(isFirstLanguageBound); if (isFirstLanguageBound) { fileSystemMock .Setup(x => x.File.Exists(cFilePath)) .Returns(isSecondLanguageBound); } var result = testSubject.IsBindingRequired(bindingConfiguration, projectMock); result.Should().Be(expectedResult); fileSystemMock.VerifyAll(); }
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 BindingController_BindCommand_Status_VsState() { // Arrange BindCommandArgs bindArgs = CreateBindingArguments("proj1", "name1", "http://localhost:9000"); BindingController testSubject = this.PrepareCommandForExecution(); ProjectMock project1 = this.solutionMock.Projects.Single(); // Case 1: SolutionExistsAndFullyLoaded is not active this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid, false); // Act + Assert testSubject.BindCommand.CanExecute(bindArgs).Should().BeFalse("No UI context: SolutionExistsAndFullyLoaded"); // Case 2: SolutionExistsAndNotBuildingAndNotDebugging is not active this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid, true); this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid, false); // Act + Assert testSubject.BindCommand.CanExecute(bindArgs).Should().BeFalse("No UI context: SolutionExistsAndNotBuildingAndNotDebugging"); // Case 3: Non-managed project kind this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid, true); this.projectSystemHelper.Projects = null; // Act + Assert testSubject.BindCommand.CanExecute(bindArgs).Should().BeFalse("No managed projects"); // Case 4: No projects at all solutionMock.RemoveProject(project1); // Act + Assert testSubject.BindCommand.CanExecute(bindArgs).Should().BeFalse("No projects"); }
public void TestInitialize() { fileSystem = new MockFileSystem(); this.dte = new DTEMock(); this.serviceProvider = new ConfigurableServiceProvider(); this.solutionMock = new SolutionMock(dte, Path.Combine(SolutionRoot, "xxx.sln")); this.projectMock = this.solutionMock.AddOrGetProject(Path.Combine(SolutionRoot, @"Project\project.proj")); this.outputPane = new ConfigurableVsOutputWindowPane(); this.serviceProvider.RegisterService(typeof(SVsGeneralOutputWindowPane), this.outputPane); this.projectSystemHelper = new ConfigurableVsProjectSystemHelper(this.serviceProvider); this.sccFileSystem = new ConfigurableSourceControlledFileSystem(fileSystem); this.ruleSetFS = new ConfigurableRuleSetSerializer(fileSystem); this.serviceProvider.RegisterService(typeof(ISourceControlledFileSystem), this.sccFileSystem); this.serviceProvider.RegisterService(typeof(IRuleSetSerializer), this.ruleSetFS); this.serviceProvider.RegisterService(typeof(ISolutionRuleSetsInformationProvider), new SolutionRuleSetsInformationProvider(this.serviceProvider, new Mock <ILogger>().Object, new MockFileSystem())); this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper); var coreRuleSet = new FilePathAndContent <CoreRuleSet>(@"c:\Solution\sln.ruleset", new CoreRuleSet()); var vsRuleSet = new VsRuleSet("VS ruleset"); var additionalFile = new FilePathAndContent <SonarLintConfiguration>(@"c:\Solution\additionalFile.txt", new SonarLintConfiguration()); cSharpVBBindingConfig = new CSharpVBBindingConfig(coreRuleSet, additionalFile); ruleSetFS.RegisterRuleSet(vsRuleSet, coreRuleSet.Path); additionalFileConflictChecker = new Mock <IAdditionalFileConflictChecker>(); ruleSetReferenceChecker = new Mock <IRuleSetReferenceChecker>(); }
public void TestInitialize() { this.dte = new DTEMock(); this.serviceProvider = new ConfigurableServiceProvider(); this.solutionMock = new SolutionMock(dte, Path.Combine(SolutionRoot, "xxx.sln")); this.outputPane = new ConfigurableVsOutputWindowPane(); this.serviceProvider.RegisterService(typeof(SVsGeneralOutputWindowPane), this.outputPane); this.projectSystemHelper = new ConfigurableVsProjectSystemHelper(this.serviceProvider); this.solutionItemsProject = this.solutionMock.AddOrGetProject("Solution items"); this.projectSystemHelper.SolutionItemsProject = this.solutionItemsProject; this.projectSystemHelper.CurrentActiveSolution = this.solutionMock; this.fileSystem = new MockFileSystem(); this.sccFileSystem = new ConfigurableSourceControlledFileSystem(fileSystem); this.ruleFS = new ConfigurableRuleSetSerializer(fileSystem); this.ruleSetInfo = new ConfigurableSolutionRuleSetsInformationProvider { SolutionRootFolder = SolutionRoot }; this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper); this.serviceProvider.RegisterService(typeof(ISourceControlledFileSystem), this.sccFileSystem); this.serviceProvider.RegisterService(typeof(IRuleSetSerializer), this.ruleFS); this.serviceProvider.RegisterService(typeof(ISolutionRuleSetsInformationProvider), this.ruleSetInfo); projectBinderFactoryMock = new Mock <IProjectBinderFactory>(); }
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 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_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 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 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 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 BindingController_BindCommand_Status_VsState() { // Setup ProjectViewModel projectVM = CreateProjectViewModel(); BindingController testSubject = this.PrepareCommandForExecution(); ProjectMock project1 = this.solutionMock.Projects.Single(); // Case 1: SolutionExistsAndFullyLoaded is not active this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid, false); // Act + Verify Assert.IsFalse(testSubject.BindCommand.CanExecute(projectVM), "No UI context: SolutionExistsAndFullyLoaded"); // Case 2: SolutionExistsAndNotBuildingAndNotDebugging is not active this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid, true); this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid, false); // Act + Verify Assert.IsFalse(testSubject.BindCommand.CanExecute(projectVM), "No UI context: SolutionExistsAndNotBuildingAndNotDebugging"); // Case 3: Non-managed project kind this.monitorSelection.SetContext(VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid, true); this.projectSystemHelper.Projects = null; // Act + Verify Assert.IsFalse(testSubject.BindCommand.CanExecute(projectVM), "No managed projects"); // Case 4: No projects at all solutionMock.RemoveProject(project1); // Act + Verify Assert.IsFalse(testSubject.BindCommand.CanExecute(projectVM), "No projects"); }
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 ProjectMock AddFilteredProject(string projectKind) { var project = new ProjectMock("any.proj"); project.ProjectKind = projectKind; projects.Add(project); return(project); }
public void IProjectSystemHelperExtensions_IsKnownTestProject_IsNotTestProject_ReturnsFalse() { // Arrange var vsProject = new ProjectMock("myproject.proj"); // Act + Assert IProjectSystemHelperExtensions.IsKnownTestProject(this.projectSystem, vsProject).Should().BeFalse("Expected project without test project kind NOT to be known test project"); }
public void TestInitialize() { logger = new Mock <ILogger>(); fileSystem = new Mock <IFileSystem>(); project = new ProjectMock("test.csproj"); testSubject = new ServiceGuidTestProjectIndicator(logger.Object, fileSystem.Object); }
public void IsTestProject_ProjectHasNoCapabilities_Null() { var projectMock = new ProjectMock("csproj.csproj"); var actual = testSubject.IsTestProject(projectMock); actual.Should().BeNull(); }
public void IProjectSystemHelperExtensions_IsKnownTestProject_IsNotTestProject_ReturnsFalse() { // Setup var vsProject = new ProjectMock("myproject.proj"); // Act + Verify Assert.IsFalse(IProjectSystemHelperExtensions.IsKnownTestProject(this.projectSystem, vsProject), "Expected project without test project kind NOT to be known test project"); }
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"); }
public void IProjectSystemHelperExtensions_IsKnownTestProject_ArgChecks() { // Setup IVsHierarchy vsProject = new ProjectMock("myproject.proj"); // Act + Verify Exceptions.Expect <ArgumentNullException>(() => IProjectSystemHelperExtensions.IsKnownTestProject(null, vsProject)); Exceptions.Expect <ArgumentNullException>(() => IProjectSystemHelperExtensions.IsKnownTestProject(this.projectSystem, null)); }
public void IProjectSystemHelperExtensions_IsKnownTestProject_ArgChecks() { // Setup IVsHierarchy vsProject = new ProjectMock("myproject.proj"); // Act + Verify Exceptions.Expect<ArgumentNullException>(() => IProjectSystemHelperExtensions.IsKnownTestProject(null, vsProject)); Exceptions.Expect<ArgumentNullException>(() => IProjectSystemHelperExtensions.IsKnownTestProject(this.projectSystem, null)); }
public void IProjectSystemHelperExtensions_IsKnownTestProject_IsNotTestProject_ReturnsFalse() { // Setup var vsProject = new ProjectMock("myproject.proj"); // Act + Verify Assert.IsFalse(IProjectSystemHelperExtensions.IsKnownTestProject(this.projectSystem, vsProject), "Expected project without test project kind NOT to be known test project"); }
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"); }
public void IProjectSystemHelperExtensions_IsKnownTestProject_IsTestProject_ReturnsTrue() { // Setup var vsProject = new ProjectMock("myproject.proj"); vsProject.SetAggregateProjectTypeGuids(ProjectSystemHelper.TestProjectKindGuid); // Act + Verify Assert.IsTrue(IProjectSystemHelperExtensions.IsKnownTestProject(this.projectSystem, vsProject), "Expected project with test project kind to be known test project"); }
public static IEnumerable <object[]> GetInvalidEmails() { yield return(new object[] { "", "*****@*****.**", "assunto", ProjectMock.GetProject() }); yield return(new object[] { "*****@*****.**", "", "assunto", ProjectMock.GetProject() }); yield return(new object[] { "*****@*****.**", "*****@*****.**", "", ProjectMock.GetProject() }); yield return(new object[] { "*****@*****.**", "*****@*****.**", "assunto", null }); }
public void IsTestProject_ProjectHasNonTestCapability_Null() { var projectMock = new ProjectMock("csproj.csproj"); SetCapability(projectMock, "some other capability"); var actual = testSubject.IsTestProject(projectMock); actual.Should().BeNull(); }
public void IProjectSystemHelperExtensions_IsKnownTestProject_IsTestProject_ReturnsTrue() { // Arrange var vsProject = new ProjectMock("myproject.proj"); vsProject.SetAggregateProjectTypeGuids(ProjectSystemHelper.TestProjectKindGuid); // Act + Assert IProjectSystemHelperExtensions.IsKnownTestProject(this.projectSystem, vsProject).Should().BeTrue("Expected project with test project kind to be known test project"); }
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(); }
public void IsTestProject_ProjectHasTestCapability_True() { var projectMock = new ProjectMock("csproj.csproj"); SetCapability(projectMock, TestCapability); var actual = testSubject.IsTestProject(projectMock); actual.Should().BeTrue(); }
public void ProjectSystemFilter_IsAccepted_SupportedProject_ProjectExcludedViaProjectProperty() { // Setup var testSubject = this.CreateTestSubject(); var project = new ProjectMock("supported.csproj"); 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 SetExcludeProperty(ProjectMock project, bool?value) { if (value.GetValueOrDefault(false)) { project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, value.Value.ToString()); } else { project.ClearBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey); } }
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"); }
public void IsAccepted_ProjectLanguageUnsupported_False() { var project = new ProjectMock("unsupported.proj") { ProjectKind = null }; var actual = testSubject.IsAccepted(project); actual.Should().BeFalse(); }
private Mock <ProjectItem> CreateProjectItemWithProject(string projectName) { var projectItemMock = new Mock <ProjectItem>(); var projectMock = new ProjectMock(projectName); projectItemMock.Setup(i => i.ContainingProject).Returns(projectMock); projectItemMock.Setup(i => i.ConfigurationManager).Returns(projectMock.ConfigurationManager); projectMock.ConfigurationManager.ActiveConfiguration = new ConfigurationMock("dummy config"); return(projectItemMock); }
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"); }
public void TestInitialize() { this.dte = new DTEMock(); this.serviceProvider = new ConfigurableServiceProvider(); this.solutionMock = new SolutionMock(dte, Path.Combine(SolutionRoot, "xxx.sln")); this.projectMock = this.solutionMock.AddOrGetProject(Path.Combine(SolutionRoot, @"Project\project.proj")); this.outputPane = new ConfigurableVsOutputWindowPane(); this.serviceProvider.RegisterService(typeof(SVsGeneralOutputWindowPane), this.outputPane); this.projectSystemHelper = new ConfigurableVsProjectSystemHelper(this.serviceProvider); this.ruleStore = new ConfigurableSolutionRuleStore(); this.sccFileSystem = new ConfigurableSourceControlledFileSystem(); this.ruleSetFS = new ConfigurableRuleSetSerializer(this.sccFileSystem); this.serviceProvider.RegisterService(typeof(ISourceControlledFileSystem), this.sccFileSystem); this.serviceProvider.RegisterService(typeof(IRuleSetSerializer), this.ruleSetFS); this.serviceProvider.RegisterService(typeof(ISolutionRuleSetsInformationProvider), new SolutionRuleSetsInformationProvider(this.serviceProvider)); }
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 TestInitialize() { this.dte = new DTEMock(); this.serviceProvider = new ConfigurableServiceProvider(); this.solutionMock = new SolutionMock(dte, Path.Combine(SolutionRoot, "xxx.sln")); this.outputPane = new ConfigurableVsOutputWindowPane(); this.serviceProvider.RegisterService(typeof(SVsGeneralOutputWindowPane), this.outputPane); this.projectSystemHelper = new ConfigurableVsProjectSystemHelper(this.serviceProvider); this.projectFilter = new ConfigurableProjectSystemFilter(); this.solutionItemsProject = this.solutionMock.AddOrGetProject("Solution items"); this.projectSystemHelper.SolutionItemsProject = this.solutionItemsProject; this.projectSystemHelper.CurrentActiveSolution = this.solutionMock; this.sccFileSystem = new ConfigurableSourceControlledFileSystem(); this.ruleFS = new ConfigurableRuleSetSerializer(this.sccFileSystem); this.solutionBinding = new ConfigurableSolutionBindingSerializer(); this.ruleSetInfo = new ConfigurableSolutionRuleSetsInformationProvider(); this.ruleSetInfo.SolutionRootFolder = SolutionRoot; this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper); this.serviceProvider.RegisterService(typeof(ISourceControlledFileSystem), this.sccFileSystem); this.serviceProvider.RegisterService(typeof(IRuleSetSerializer), this.ruleFS); this.serviceProvider.RegisterService(typeof(ISolutionRuleSetsInformationProvider), this.ruleSetInfo); }
private void SetExcludeProperty(ProjectMock project, bool? value) { if (value.GetValueOrDefault(false)) { project.SetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey, value.Value.ToString()); } else { project.ClearBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey); } }
private bool? GetExcludeProperty(ProjectMock project) { string valueString = project.GetBuildProperty(Constants.SonarQubeExcludeBuildPropertyKey); bool value; if (bool.TryParse(valueString, out value)) { return value; } return null; }
private void VerifyExcludeProperty(ProjectMock project, bool? expected) { bool? actual = this.GetExcludeProperty(project); Assert.AreEqual(expected, actual); }
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 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 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_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_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_QueryStatus_SingleProject_UnsupportedProject_IsDisabledIsHidden() { // Setup OleMenuCommand command = CommandHelper.CreateRandomOleMenuCommand(); var testSubject = new ProjectExcludePropertyToggleCommand(serviceProvider); var project = new ProjectMock("mcproject.csproj"); this.projectSystem.SelectedProjects = new[] { project }; // 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_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_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 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_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"); }
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"); }
private static PropertyMock CreateProperty(ProjectMock project, string configurationName, object propertyValue) { ConfigurationMock config = project.ConfigurationManager.Configurations.SingleOrDefault(c => c.ConfigurationName == configurationName); if (config == null) { config = new ConfigurationMock(configurationName); project.ConfigurationManager.Configurations.Add(config); } var prop = config.Properties.RegisterKnownProperty(Constants.CodeAnalysisRuleSetPropertyKey); prop.Value = propertyValue; return prop; }