public void ProjectPropertyManager_GetBooleanProperty() { // Arrange var project = new ProjectMock("foo.proj"); ProjectPropertyManager testSubject = this.CreateTestSubject(); // Test case 1: no property -> null // Arrange project.ClearBuildProperty(TestPropertyName); // Act + Assert testSubject.GetBooleanProperty(project, TestPropertyName).Should().BeNull("Expected null for missing property value"); // Test case 2: bad property -> null // Arrange project.SetBuildProperty(TestPropertyName, "NotABool"); // Act + Assert testSubject.GetBooleanProperty(project, TestPropertyName).Should().BeNull("Expected null for bad property value"); // Test case 3: true property -> true // Arrange project.SetBuildProperty(TestPropertyName, true.ToString()); // Act + Assert testSubject.GetBooleanProperty(project, TestPropertyName).Value.Should().BeTrue("Expected true for 'true' property value"); // Test case 4: false property -> false // Arrange project.SetBuildProperty(TestPropertyName, false.ToString()); // Act + Assert testSubject.GetBooleanProperty(project, TestPropertyName).Value.Should().BeFalse("Expected true for 'true' property value"); }
public void Language_ForProject_KnownLanguage_ReturnsCorrectLanguage() { // Test case 1: Unknown // Setup var otherProject = new ProjectMock("other.proj"); // Act var otherProjectLanguage = Language.ForProject(otherProject); // Verify Assert.AreEqual(Language.Unknown, otherProjectLanguage, "Unexpected Language for unknown project"); // Test case 2: C# // Setup var csProject = new ProjectMock("cs1.csproj"); csProject.SetCSProjectKind(); // Act var csProjectLanguage = Language.ForProject(csProject); // Verify Assert.AreEqual(Language.CSharp, csProjectLanguage, "Unexpected Language for C# project"); // Test case 3: VB // Setup var vbNetProject = new ProjectMock("vb1.vbproj"); vbNetProject.SetVBProjectKind(); // Act var vbNetProjectLanguage = Language.ForProject(vbNetProject); // Verify Assert.AreEqual(Language.VBNET, vbNetProjectLanguage, "Unexpected Language for C# project"); }
public void ProjectSystemHelper_GetFilteredSolutionProjects() { ProjectMock csProject = this.solutionMock.AddOrGetProject("c#"); csProject.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, csProject); csProject.ProjectKind = ProjectSystemHelper.CSharpProjectKind; ProjectMock vbProject = this.solutionMock.AddOrGetProject("vb.net"); vbProject.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, vbProject); vbProject.ProjectKind = ProjectSystemHelper.VbProjectKind; ProjectMock otherProject = this.solutionMock.AddOrGetProject("other"); otherProject.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, otherProject); otherProject.ProjectKind = "other"; ProjectMock erronousProject = this.solutionMock.AddOrGetProject("err"); erronousProject.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, null); erronousProject.ProjectKind = ProjectSystemHelper.VbProjectKind; // Filter out C#, keep VB projectFilter.MatchingProjects.Add(vbProject); // Act var actual = this.testSubject.GetFilteredSolutionProjects().ToArray(); // Verify CollectionAssert.AreEqual(new[] { vbProject }, actual, "Unexpected projects: {0}", string.Join(", ", actual.Select(p => p.Name))); }
public void ProjectPropertyManager_SetBooleanProperty() { // Setup var project = new ProjectMock("foo.proj"); ProjectPropertyManager testSubject = this.CreateTestSubject(); // Test case 1: true -> property is set true // Setup testSubject.SetBooleanProperty(project, TestPropertyName, true); // Act + Verify Assert.AreEqual(true.ToString(), project.GetBuildProperty(TestPropertyName), ignoreCase: true, message: "Expected property value true for property true"); // Test case 2: false -> property is set false // Setup testSubject.SetBooleanProperty(project, TestPropertyName, false); // Act + Verify Assert.AreEqual(false.ToString(), project.GetBuildProperty(TestPropertyName), ignoreCase: false, message: "Expected property value true for property true"); // Test case 3: null -> property is cleared // Setup testSubject.SetBooleanProperty(project, TestPropertyName, null); // Act + Verify Assert.IsNull(project.GetBuildProperty(TestPropertyName), "Expected property value null for property false"); }
public void GetBindingLanguages_IfCppIsDetected_ThenCIsReturnedToo() { // Arrange var testSubject = this.CreateTestSubject(); var project1 = new ProjectMock("cs1.csproj"); project1.ProjectKind = ProjectSystemHelper.CppProjectKind; var projects = new[] { project1, }; testSubject.InternalState.BindingProjects.AddRange(projects); this.host.SupportedPluginLanguages.Add(Language.Cpp); this.host.SupportedPluginLanguages.Add(Language.C); // Act var actualLanguages = testSubject.GetBindingLanguages(); // Assert var expectedLanguages = new[] { Language.Cpp, Language.C }; CollectionAssert.AreEquivalent(expectedLanguages, actualLanguages.ToArray()); }
public void ProjectSystemHelper_GetSolutionProjects_ReturnsOnlyKnownLanguages() { // Arrange ProjectMock csProject = this.solutionMock.AddOrGetProject("c#"); csProject.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, csProject); csProject.ProjectKind = ProjectSystemHelper.CSharpProjectKind; ProjectMock vbProject = this.solutionMock.AddOrGetProject("vb.net"); vbProject.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, vbProject); vbProject.ProjectKind = ProjectSystemHelper.VbProjectKind; ProjectMock otherProject = this.solutionMock.AddOrGetProject("other"); otherProject.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, otherProject); otherProject.ProjectKind = "other"; ProjectMock erronousProject = this.solutionMock.AddOrGetProject("err"); erronousProject.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, null); erronousProject.ProjectKind = ProjectSystemHelper.VbProjectKind; // Act var actual = this.testSubject.GetSolutionProjects().ToArray(); // Assert CollectionAssert.AreEqual(new[] { csProject, vbProject }, actual, "Unexpected projects: {0}", string.Join(", ", actual.Select(p => p.Name))); }
public void SolutionBindingSerializer_WriteSolutionBinding_AddConfigFileToSolutionItemsFolder() { // Arrange SolutionBindingSerializer testSubject = this.CreateTestSubject(); var serverUri = new Uri("http://xxx.www.zzz/yyy:9000"); var creds = new BasicAuthCredentials("user", "pwd".ToSecureString()); var projectKey = "MyProject Key"; var toWrite = new BoundSonarQubeProject(serverUri, projectKey, "projectName", creds); ProjectMock solutionProject = (ProjectMock)this.projectSystemHelper.SolutionItemsProject; // Act string output = testSubject.WriteSolutionBinding(toWrite); // Assert that not actually done anything until the pending files were written this.store.data.Should().NotContainKey(serverUri); solutionProject.Files.ContainsKey(output).Should().BeFalse("Not expected to be added to solution items folder just yet"); // Act (write pending) this.sourceControlledFileSystem.WritePendingNoErrorsExpected(); // Assert this.store.data.Should().ContainKey(serverUri); solutionProject.Files.ContainsKey(output).Should().BeTrue("File {0} was not added to project", output); // Act (write again) string output2 = testSubject.WriteSolutionBinding(toWrite); this.sourceControlledFileSystem.WritePendingNoErrorsExpected(); // Assert output2.Should().Be(output, "Should be the same file"); this.store.data.Should().ContainKey(serverUri); solutionProject.Files.ContainsKey(output).Should().BeTrue("File {0} should remain in the project", output); }
public void DiscoverProjects_AddsMatchingProjectsToBinding() { // Arrange ThreadHelper.SetCurrentThreadAsUIThread(); var csProject1 = new ProjectMock("cs1.csproj"); var csProject2 = new ProjectMock("cs2.csproj"); csProject1.SetCSProjectKind(); csProject2.SetCSProjectKind(); var matchingProjects = new[] { csProject1, csProject2 }; this.projectSystemHelper.FilteredProjects = matchingProjects; var testSubject = this.CreateTestSubject(); this.host.SupportedPluginLanguages.UnionWith(new[] { Language.CSharp }); // Act var result = testSubject.DiscoverProjects(); // Assert result.Should().BeTrue(); CollectionAssert.AreEqual(matchingProjects, testSubject.InternalState.BindingProjects.ToArray(), "Unexpected projects selected for binding"); }
public void BindingWorkflow_InstallPackages_MoreNugetPackagesThanLanguageCount() { // Arrange var testSubject = this.CreateTestSubject(); var progressEvents = new ConfigurableProgressStepExecutionEvents(); ProjectMock project1 = new ProjectMock("project1") { ProjectKind = ProjectSystemHelper.CSharpProjectKind }; var nugetPackage1 = new PackageName("mypackage1", new SemanticVersion("1.1.0")); var nugetPackage2 = new PackageName("mypackage2", new SemanticVersion("1.1.1")); var nugetPackages = new[] { nugetPackage1, nugetPackage2 }; var packages = new Dictionary <Language, IEnumerable <PackageName> >(); packages.Add(Language.CSharp, nugetPackages); ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages, project1); // Act testSubject.InstallPackages(new ConfigurableProgressController(), CancellationToken.None, progressEvents); // Assert packageInstaller.AssertInstalledPackages(project1, nugetPackages); this.outputWindowPane.AssertOutputStrings(4); this.outputWindowPane.AssertOutputStrings( string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackages[0].Id, ((Project)project1).Name)), string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackages[0].Id, ((Project)project1).Name)), string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackages[1].Id, ((Project)project1).Name)), string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackages[1].Id, ((Project)project1).Name)) ); progressEvents.AssertProgress(.5, 1.0); }
public void BindingWorkflow_InstallPackages_Succeeds_SuccessPropertyIsFalse() { // Arrange var bindingArgs = new BindCommandArgs("projectKey", "projectName", new ConnectionInformation(new Uri("http://connected"))); var slnBindOpMock = new Mock <ISolutionBindingOperation>(); var nugetMock = new Mock <INuGetBindingOperation>(); nugetMock.Setup(x => x.InstallPackages(It.IsAny <ISet <Project> >(), It.IsAny <IProgressController>(), It.IsAny <IProgressStepExecutionEvents>(), It.IsAny <CancellationToken>())).Returns(false); var testSubject = new BindingWorkflow(this.host, bindingArgs, slnBindOpMock.Object, nugetMock.Object); ProjectMock project1 = new ProjectMock("project1") { ProjectKind = ProjectSystemHelper.CSharpProjectKind }; testSubject.BindingProjects.Clear(); testSubject.BindingProjects.Add(project1); var progressEvents = new ConfigurableProgressStepExecutionEvents(); var cts = new CancellationTokenSource(); testSubject.BindingOperationSucceeded = true; // Act testSubject.InstallPackages(new ConfigurableProgressController(), progressEvents, cts.Token); // Assert testSubject.BindingOperationSucceeded.Should().BeFalse(); }
public void BindingWorkflow_DiscoverProjects_AddsMatchingProjectsToBinding() { // Arrange ThreadHelper.SetCurrentThreadAsUIThread(); var controller = new ConfigurableProgressController(); var progressEvents = new ConfigurableProgressStepExecutionEvents(); var csProject1 = new ProjectMock("cs1.csproj"); var csProject2 = new ProjectMock("cs2.csproj"); csProject1.SetCSProjectKind(); csProject2.SetCSProjectKind(); var matchingProjects = new[] { csProject1, csProject2 }; this.projectSystemHelper.FilteredProjects = matchingProjects; var testSubject = this.CreateTestSubject(); this.host.SupportedPluginLanguages.UnionWith(new[] { Language.CSharp }); // Act testSubject.DiscoverProjects(controller, progressEvents); // Assert CollectionAssert.AreEqual(matchingProjects, testSubject.BindingProjects.ToArray(), "Unexpected projects selected for binding"); progressEvents.AssertProgressMessages(Strings.DiscoveringSolutionProjectsProgressMessage); }
public void EnumerateProjectProperties_WithConfiguration_MultipleMatches() { // Arrange var project = new ProjectMock("projectfile.proj"); project.Properties.RegisterKnownProperty("no match1").Value = "value1"; project.Properties.RegisterKnownProperty("no match2").Value = "value2"; // Expected results CreatePropertyForConfiguration(project, "config1", "prop1", "config1 prop1"); CreatePropertyForConfiguration(project, "config2", "prop1", "config2 prop1"); CreatePropertyForConfiguration(project, "config4", "prop1", "config4 prop1"); // Additional non-matching properties CreatePropertyForConfiguration(project, "config1", "prop2", "config1 prop2"); CreatePropertyForConfiguration(project, "config2", "propXXX", "config2 propXXX"); CreatePropertyForConfiguration(project, "config3", "prop1aa", "config3 prop1aa"); // Act var result = VsShellUtils.GetProjectProperties(project, "prop1"); // Assert result.Should().NotBeNull(); result.Count().Should().Be(3); result.Select(p => p.Value).Should().BeEquivalentTo( new string[] { "config1 prop1", "config2 prop1", "config4 prop1" }); }
private static ProjectMock CreateCsProject(string projectName) { var project = new ProjectMock(projectName); project.SetCSProjectKind(); return(project); }
public void ProjectPropertyManager_SetBooleanProperty() { // Arrange var project = new ProjectMock("foo.proj"); ProjectPropertyManager testSubject = this.CreateTestSubject(); // Test case 1: true -> property is set true // Arrange testSubject.SetBooleanProperty(project, TestPropertyName, true); // Act + Assert project.GetBuildProperty(TestPropertyName).Should().Be(true.ToString(), "Expected property value true for property true"); // Test case 2: false -> property is set false // Arrange testSubject.SetBooleanProperty(project, TestPropertyName, false); // Act + Assert project.GetBuildProperty(TestPropertyName).Should().Be(false.ToString(), "Expected property value true for property true"); // Test case 3: null -> property is cleared // Arrange testSubject.SetBooleanProperty(project, TestPropertyName, null); // Act + Assert project.GetBuildProperty(TestPropertyName).Should().BeNull("Expected property value null for property false"); }
private void SetFilteredProjects(params Language[] languages) { this.projectSystem.FilteredProjects = languages.Select((language, i) => { var project = new ProjectMock($"validProject{i}.csproj"); project.SetProjectKind(language.ProjectType); return(project); }); }
private static PropertyMock CreateProperty(ProjectMock project, string configurationName, object propertyValue, string propertyName = Constants.CodeAnalysisRuleSetPropertyKey) { ConfigurationMock config = GetOrCreateConfiguration(project, configurationName); var prop = config.Properties.RegisterKnownProperty(propertyName); prop.Value = propertyValue; return(prop); }
private void SetFilteredProjects(params string[] projectKinds) { this.projectSystem.FilteredProjects = projectKinds.Select((projectKind, i) => { var project = new ProjectMock($"validProject{i}.csproj"); project.SetProjectKind(new Guid(projectKind)); return(project); }); }
private void BindingWorkflow_DiscoverProjects_GenericPart(ConfigurableProgressController controller, ConfigurableProgressStepExecutionEvents progressEvents, int numberOfProjectsToCreate, int numberOfProjectsToInclude) { // Arrange List <Project> projects = new List <Project>(); for (int i = 0; i < numberOfProjectsToCreate; i++) { var project = new ProjectMock($"cs{i}.csproj"); project.SetCSProjectKind(); projects.Add(project); } this.projectSystemHelper.FilteredProjects = projects.Take(numberOfProjectsToInclude); this.projectSystemHelper.Projects = projects; var testSubject = this.CreateTestSubject(); this.host.SupportedPluginLanguages.UnionWith(new[] { Language.CSharp }); // Act testSubject.DiscoverProjects(controller, progressEvents); // Assert testSubject.BindingProjects.Should().HaveCount(numberOfProjectsToInclude, "Expected " + numberOfProjectsToInclude + " project(s) selected for binding"); progressEvents.AssertProgressMessages(Strings.DiscoveringSolutionProjectsProgressMessage); this.outputWindowPane.AssertOutputStrings(1); // Returns expected output message var expectedOutput = new StringBuilder(); expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, Strings.DiscoveringSolutionIncludedProjectsHeader).AppendLine(); if (numberOfProjectsToInclude > 0) { this.projectSystemHelper.FilteredProjects.ToList().ForEach(p => expectedOutput.AppendFormat(" * {0}\r\n", p.Name)); } else { var msg = string.Format(Strings.DiscoveredIncludedOrExcludedProjectFormat, Strings.NoProjectsExcludedFromBinding); expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, msg).AppendLine(); } expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, Strings.DiscoveringSolutionExcludedProjectsHeader).AppendLine(); if (numberOfProjectsToCreate - numberOfProjectsToInclude > 0) { this.projectSystemHelper.Projects.Except(this.projectSystemHelper.FilteredProjects) .ToList() .ForEach(p => expectedOutput.AppendFormat(" * {0}\r\n", p.Name)); } else { var msg = string.Format(Strings.DiscoveredIncludedOrExcludedProjectFormat, Strings.NoProjectsExcludedFromBinding); expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, msg).AppendLine(); } expectedOutput.AppendFormat(Strings.SubTextPaddingFormat, Strings.FilteredOutProjectFromBindingEnding); this.outputWindowPane.AssertOutputStrings(expectedOutput.ToString()); }
public void ProjectPropertyManager_GetBooleanProperty_NullArgChecks() { // Setup var project = new ProjectMock("foo.proj"); ProjectPropertyManager testSubject = this.CreateTestSubject(); // Act + Verify Exceptions.Expect <ArgumentNullException>(() => testSubject.GetBooleanProperty(null, "prop")); Exceptions.Expect <ArgumentNullException>(() => testSubject.GetBooleanProperty(project, null)); }
public void ProjectPropertyManager_SetBooleanProperty_NullArgChecks() { // Arrange var project = new ProjectMock("foo.proj"); ProjectPropertyManager testSubject = this.CreateTestSubject(); // Act + Assert Exceptions.Expect <ArgumentNullException>(() => testSubject.SetBooleanProperty(null, "prop", true)); Exceptions.Expect <ArgumentNullException>(() => testSubject.SetBooleanProperty(project, null, true)); }
public ProjectItemsMock(ProjectMock parent, params ProjectItem[] items) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } this.Project = parent; this.items.AddRange(items); }
public void ProjectSystemHelper_SetProjectProperty_PropertyDoesNotExist_AddsPropertyWithValue() { // Setup ProjectMock project = this.solutionMock.AddOrGetProject("my.proj"); // Act testSubject.SetProjectProperty(project, "myprop", "myval"); // Verify Assert.AreEqual("myval", project.GetBuildProperty("myprop"), "Unexpected property value"); }
public void ProjectSystemHelper_GetProjectProperty_PropertyDoesNotExist_ReturnsNull() { // Setup ProjectMock project = this.solutionMock.AddOrGetProject("my.proj"); // Act var actualValue = testSubject.GetProjectProperty(project, "myprop"); // Verify Assert.IsNull(actualValue, "Expected no property value to be returned"); }
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 IEnumerable <Guid> GetAggregateProjectKinds(IVsHierarchy hierarchy) { ProjectMock dteProject = hierarchy as ProjectMock; if (dteProject == null) { Assert.Inconclusive($"Only expecting {nameof(ProjectMock)} type"); } return(dteProject.GetAggregateProjectTypeGuids()); }
public void InstallPackages_FailureOnOneProject_Continues() { // Arrange const string failureMessage = "Failure for project1"; const string project1Name = "project1"; const string project2Name = "project2"; var testSubject = this.CreateTestSubject(); var progressEvents = new ConfigurableProgressStepExecutionEvents(); var progressAdapter = new FixedStepsProgressAdapter(progressEvents); var cts = new CancellationTokenSource(); ProjectMock project1 = new ProjectMock(project1Name) { ProjectKind = ProjectSystemHelper.CSharpProjectKind }; ProjectMock project2 = new ProjectMock(project2Name) { ProjectKind = ProjectSystemHelper.CSharpProjectKind }; var projectsToBind = new HashSet <Project> { project1, project2 }; var nugetPackage = new PackageName("mypackage", new SemanticVersion("1.1.0")); var packages = new[] { nugetPackage }; var nugetPackages = new Dictionary <Language, IEnumerable <PackageName> >(); nugetPackages.Add(Language.CSharp, packages); ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, nugetPackages); packageInstaller.InstallPackageAction = (p) => { packageInstaller.InstallPackageAction = null; throw new Exception(failureMessage); }; // Act testSubject.InstallPackages(projectsToBind, progressAdapter, cts.Token); // Assert packageInstaller.AssertNoInstalledPackages(project1); packageInstaller.AssertInstalledPackages(project2, packages); this.logger.AssertOutputStrings(4); this.logger.AssertOutputStrings( string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, project1Name)), string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.FailedDuringNuGetPackageInstall, nugetPackage.Id, project1Name, failureMessage)), string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, project2Name)), string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.SuccessfullyInstalledNugetPackageForProject, nugetPackage.Id, project2Name)) ); progressEvents.AssertProgress(.5, 1.0); }
public void Mapper_ForProject_UnknownLanguage_ReturnsUnknown() { // Arrange var otherProject = new ProjectMock("other.proj"); // Act var otherProjectLanguage = ProjectToLanguageMapper.GetLanguageForProject(otherProject); // Assert otherProjectLanguage.Should().Be(Language.Unknown, "Unexpected Language for unknown project"); }
public IEnumerable <Guid> GetAggregateProjectKinds(IVsHierarchy hierarchy) { ProjectMock dteProject = hierarchy as ProjectMock; if (dteProject == null) { FluentAssertions.Execution.Execute.Assertion.FailWith($"Only expecting {nameof(ProjectMock)} type"); } return(dteProject.GetAggregateProjectTypeGuids()); }
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")); var outputWindow = new ConfigurableVsOutputWindow(); this.outputPane = outputWindow.GetOrCreateSonarLintPane(); this.serviceProvider.RegisterService(typeof(SVsOutputWindow), outputWindow); }
public void ProjectSystemHelper_GetProjectProperty_PropertyDoesNotExist_ReturnsNull() { // Arrange ProjectMock project = this.solutionMock.AddOrGetProject("my.proj"); // Act var actualValue = testSubject.GetProjectProperty(project, "myprop"); // Assert actualValue.Should().BeNull("Expected no property value to be returned"); }
public void ProjectSystemHelper_SetProjectProperty_PropertyDoesNotExist_AddsPropertyWithValue() { // Arrange ProjectMock project = this.solutionMock.AddOrGetProject("my.proj"); // Act testSubject.SetProjectProperty(project, "myprop", "myval"); // Assert project.GetBuildProperty("myprop").Should().Be("myval", "Unexpected property value"); }
private static ConfigurationMock GetOrCreateConfiguration(ProjectMock project, string configurationName) { ConfigurationMock config = project.ConfigurationManager.Configurations.SingleOrDefault(c => c.ConfigurationName == configurationName); if (config == null) { config = new ConfigurationMock(configurationName); project.ConfigurationManager.Configurations.Add(config); } return(config); }
public void ProjectPropertyManager_GetSelectedProjects_HasSelectedProjects_ReturnsProjects() { // Setup var p1 = new ProjectMock("p1.proj"); var p2 = new ProjectMock("p2.proj"); var p3 = new ProjectMock("p3.proj"); p1.SetCSProjectKind(); p2.SetVBProjectKind(); // p3 is unknown kind var expectedProjects = new ProjectMock[] { p1, p2, p3 }; this.projectSystem.SelectedProjects = expectedProjects; ProjectPropertyManager testSubject = this.CreateTestSubject(); // Act Project[] actualProjects = testSubject.GetSelectedProjects().ToArray(); // Verify CollectionAssert.AreEquivalent(expectedProjects, actualProjects, "Unexpected selected projects"); }
public void BindingWorkflow_InstallPackages_Cancellation() { // Setup var testSubject = this.CreateTestSubject(); var progressEvents = new ConfigurableProgressStepExecutionEvents(); var cts = new CancellationTokenSource(); ProjectMock project1 = new ProjectMock("project1"); ProjectMock project2 = new ProjectMock("project2"); var nugetPackage = new PackageName("mypackage", new SemanticVersion("1.1.0")); var packages = new[] { nugetPackage }; ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages, project1, project2); packageInstaller.InstallPackageAction = (p) => { cts.Cancel(); // Cancel the next one (should complete the first one) }; // Act testSubject.InstallPackages(new ConfigurableProgressController(), cts.Token, progressEvents); // Verify packageInstaller.AssertInstalledPackages(project1, packages); packageInstaller.AssertNoInstalledPackages(project2); }
private static PropertyMock CreateProperty(ProjectMock project, string configurationName, object propertyValue, string propertyName = Constants.CodeAnalysisRuleSetPropertyKey) { ConfigurationMock config = GetOrCreateConfiguration(project, configurationName); var prop = config.Properties.RegisterKnownProperty(propertyName); prop.Value = propertyValue; return prop; }
private void SetValidFilteredProjects() { var project1 = new ProjectMock(@"c:\SolutionRoot\Project1\Project1.csproj"); project1.SetCSProjectKind(); var project2 = new ProjectMock(@"c:\SolutionRoot\Project2\project2.csproj"); project2.SetCSProjectKind(); this.projectSystemHelper.FilteredProjects = new Project[] { project1, project2 }; this.projectSystemHelper.Projects = new Project[] { new ProjectMock(@"c:\SolutionRoot\excluded.csproj") }; this.ruleSetInfoProvider.SolutionRootFolder = @"c:\SolutionRoot"; this.SetValidProjectConfiguration(project1); this.SetValidProjectConfiguration(project2); }
private void SetValidProjectConfiguration(ProjectMock project, string configurationName = "Configuration") { var configuration = new ConfigurationMock(configurationName); project.ConfigurationManager.Configurations.Add(configuration); PropertyMock ruleSetProperty = configuration.Properties.RegisterKnownProperty(Constants.CodeAnalysisRuleSetPropertyKey); ruleSetProperty.Value = project.FilePath.ToUpperInvariant(); // Catch cases where file paths are compared without OrdinalIgnoreCase this.ruleSetInfoProvider.RegisterProjectInfo(project, new RuleSetDeclaration[] { new RuleSetDeclaration(project, ruleSetProperty, (string)ruleSetProperty.Value, configurationName) }); }
public void ProjectSystemHelper_GetAggregateProjectKinds_HasGoodAndBadGuids_ReturnsSuccessfullyParsedGuidsOnly() { // Setup string guidString = ";;;F602148F607646F88F7772CC9C49BC3F;;__BAD__;;__BADGUID__;0BA323B301614B1C80D74607B7EB7F5A;;;__FOO__;;;"; Guid[] expectedGuids = new[] { new Guid("F602148F607646F88F7772CC9C49BC3F"), new Guid("0BA323B301614B1C80D74607B7EB7F5A"), }; var project = new ProjectMock("my.project"); project.SetAggregateProjectTypeString(guidString); // Act Guid[] actualGuids = this.testSubject.GetAggregateProjectKinds(project).ToArray(); // Verify CollectionAssert.AreEquivalent(expectedGuids, actualGuids, "Unexpected project kind GUIDs returned"); }
public void ProjectPropertyManager_GetBooleanProperty() { // Setup var project = new ProjectMock("foo.proj"); ProjectPropertyManager testSubject = this.CreateTestSubject(); // Test case 1: no property -> null // Setup project.ClearBuildProperty(TestPropertyName); // Act + Verify Assert.IsNull(testSubject.GetBooleanProperty(project, TestPropertyName), "Expected null for missing property value"); // Test case 2: bad property -> null // Setup project.SetBuildProperty(TestPropertyName, "NotABool"); // Act + Verify Assert.IsNull(testSubject.GetBooleanProperty(project, TestPropertyName), "Expected null for bad property value"); // Test case 3: true property -> true // Setup project.SetBuildProperty(TestPropertyName, true.ToString()); // Act + Verify Assert.IsTrue(testSubject.GetBooleanProperty(project, TestPropertyName).Value, "Expected true for 'true' property value"); // Test case 4: false property -> false // Setup project.SetBuildProperty(TestPropertyName, false.ToString()); // Act + Verify Assert.IsFalse(testSubject.GetBooleanProperty(project, TestPropertyName).Value, "Expected true for 'true' property value"); }
public void ProjectSystemHelper_GetSelectedProjects_ReturnsActiveProjects() { // Setup var dte = new DTEMock(); this.serviceProvider.RegisterService(typeof(DTE), dte); var p1 = new ProjectMock("p1.proj"); var p2 = new ProjectMock("p1.proj"); var expectedProjects = new Project[] { p1, p2 }; dte.ActiveSolutionProjects = expectedProjects; // Act Project[] actualProjects = testSubject.GetSelectedProjects().ToArray(); // Verify CollectionAssert.AreEquivalent(expectedProjects, actualProjects, "Unexpected projects"); }
public void ProjectSystemHelper_GetAggregateProjectKinds_NoGuids_ReturnsEmpty() { // Setup var project = new ProjectMock("my.project"); project.SetAggregateProjectTypeString(string.Empty); // Act Guid[] actualGuids = this.testSubject.GetAggregateProjectKinds(project).ToArray(); // Verify Assert.IsFalse(actualGuids.Any(), "Expected no GUIDs returned"); }
public void BindingWorkflow_DiscoverProjects_AddsMatchingProjectsToBinding() { // Setup ThreadHelper.SetCurrentThreadAsUIThread(); var controller = new ConfigurableProgressController(); var progressEvents = new ConfigurableProgressStepExecutionEvents(); var csProject1 = new ProjectMock("cs1.csproj"); var csProject2 = new ProjectMock("cs2.csproj"); csProject1.SetCSProjectKind(); csProject2.SetCSProjectKind(); var matchingProjects = new[] { csProject1, csProject2 }; this.projectSystemHelper.FilteredProjects = matchingProjects; var testSubject = this.CreateTestSubject(); // Act testSubject.DiscoverProjects(controller, progressEvents); // Verify CollectionAssert.AreEqual(matchingProjects, testSubject.BindingProjects.ToArray(), "Unexpected projects selected for binding"); progressEvents.AssertProgressMessages(Strings.DiscoveringSolutionProjectsProgressMessage); }
public void ProjectPropertyManager_SetBooleanProperty_NullArgChecks() { // Setup var project = new ProjectMock("foo.proj"); ProjectPropertyManager testSubject = this.CreateTestSubject(); // Act + Verify Exceptions.Expect<ArgumentNullException>(() => testSubject.SetBooleanProperty(null, "prop", true)); Exceptions.Expect<ArgumentNullException>(() => testSubject.SetBooleanProperty(project, null, true)); }
public void BindingWorkflow_GetBindingLanguages_ReturnsDistinctLanguagesForProjects() { // Setup var testSubject = this.CreateTestSubject(); var csProject1 = new ProjectMock("cs1.csproj"); var csProject2 = new ProjectMock("cs2.csproj"); var csProject3 = new ProjectMock("cs3.csproj"); csProject1.SetCSProjectKind(); csProject2.SetCSProjectKind(); csProject3.SetCSProjectKind(); var vbNetProject1 = new ProjectMock("vb1.vbproj"); var vbNetProject2 = new ProjectMock("vb2.vbproj"); vbNetProject1.SetVBProjectKind(); vbNetProject2.SetVBProjectKind(); var projects = new[] { csProject1, csProject2, vbNetProject1, csProject3, vbNetProject2 }; testSubject.BindingProjects.AddRange(projects); var expectedLanguages = new[] { Language.CSharp, Language.VBNET }; // Act var actualLanguages = testSubject.GetBindingLanguages(); // Verify CollectionAssert.AreEquivalent(expectedLanguages, actualLanguages.ToArray(), "Unexpected languages for binding projects"); }
public void BindingWorkflow_InstallPackages_FailureOnOneProject_Continues() { // Setup const string failureMessage = "Failure for project1"; const string project1Name = "project1"; const string project2Name = "project2"; var testSubject = this.CreateTestSubject(); var progressEvents = new ConfigurableProgressStepExecutionEvents(); var cts = new CancellationTokenSource(); ProjectMock project1 = new ProjectMock(project1Name); ProjectMock project2 = new ProjectMock(project2Name); var nugetPackage = new PackageName("mypackage", new SemanticVersion("1.1.0")); var packages = new[] { nugetPackage }; ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages, project1, project2); packageInstaller.InstallPackageAction = (p) => { packageInstaller.InstallPackageAction = null; throw new Exception(failureMessage); }; // Act testSubject.InstallPackages(new ConfigurableProgressController(), cts.Token, progressEvents); // Verify packageInstaller.AssertNoInstalledPackages(project1); packageInstaller.AssertInstalledPackages(project2, packages); outputWindowPane.AssertOutputStrings(string.Format(CultureInfo.CurrentCulture, Strings.FailedDuringNuGetPackageInstall, nugetPackage.Id, project1Name, failureMessage)); }
private static RuleSetDeclaration CreateDeclaration(ProjectMock project, string ruleSetValue) { return new RuleSetDeclaration(project, new PropertyMock("never mind", null), ruleSetValue, "Configuration"); }
public void SolutionRuleSetsInformationProvider_TryGetProjectRuleSetFilePath() { // Setup var testSubject = new SolutionRuleSetsInformationProvider(this.serviceProvider); var fileSystem = new ConfigurableFileSystem(); this.serviceProvider.RegisterService(typeof(IFileSystem), fileSystem); ProjectMock project = new ProjectMock(@"c:\Solution\Project\Project1.myProj"); RuleSetDeclaration declaration; string ruleSetPath; // Case 1: Declaration has an full path which exists on disk declaration = CreateDeclaration(project, @"c:\RuleSet.ruleset"); fileSystem.RegisterFile(declaration.RuleSetPath); // Act Assert.IsTrue(testSubject.TryGetProjectRuleSetFilePath(project, declaration, out ruleSetPath)); // Verify Assert.AreEqual(@"c:\RuleSet.ruleset", ruleSetPath); // Case 2: Declaration is relative to project and on disk fileSystem.ClearFiles(); declaration = CreateDeclaration(project, @"..\RuleSet.ruleset"); fileSystem.RegisterFile(@"c:\Solution\RuleSet.ruleset"); // Act Assert.IsTrue(testSubject.TryGetProjectRuleSetFilePath(project, declaration, out ruleSetPath)); // Verify Assert.AreEqual(@"c:\Solution\RuleSet.ruleset", ruleSetPath); // Case 3: File doesn't exist fileSystem.ClearFiles(); declaration = CreateDeclaration(project, "MyFile.ruleset"); // Act Assert.IsFalse(testSubject.TryGetProjectRuleSetFilePath(project, declaration, out ruleSetPath)); // Verify Assert.IsNull(ruleSetPath); }
public void BindingWorkflow_InstallPackages() { // Setup var testSubject = this.CreateTestSubject(); var progressEvents = new ConfigurableProgressStepExecutionEvents(); ProjectMock project1 = new ProjectMock("project1"); ProjectMock project2 = new ProjectMock("project2"); var nugetPackage = new PackageName("mypackage", new SemanticVersion("1.1.0")); var packages = new[] { nugetPackage }; ConfigurablePackageInstaller packageInstaller = this.PrepareInstallPackagesTest(testSubject, packages, project1, project2); // Act testSubject.InstallPackages(new ConfigurableProgressController(), CancellationToken.None, progressEvents); // Verify packageInstaller.AssertInstalledPackages(project1, packages); packageInstaller.AssertInstalledPackages(project2, packages); progressEvents.AssertProgressMessages( string.Format(CultureInfo.CurrentCulture, Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, ((Project)project1).Name), string.Empty, string.Format(CultureInfo.CurrentCulture, Strings.EnsuringNugetPackagesProgressMessage, nugetPackage.Id, ((Project)project2).Name), string.Empty); progressEvents.AssertProgress( 0, .5, .5, 1.0); }
private void SetFilteredProjects(params Language[] languages) { this.projectSystem.FilteredProjects = languages.Select((language, i) => { var project = new ProjectMock($"validProject{i}.csproj"); project.SetProjectKind(language.ProjectType); return project; }); }
private static ConfigurationMock GetOrCreateConfiguration(ProjectMock project, string configurationName) { ConfigurationMock config = project.ConfigurationManager.Configurations.SingleOrDefault(c => c.ConfigurationName == configurationName); if (config == null) { config = new ConfigurationMock(configurationName); project.ConfigurationManager.Configurations.Add(config); } return config; }
public void ErrorListInfoBarController_CurrentBackgroundProcessorCancellation() { // Setup this.IsActiveSolutionBound = true; var testSubject = new ErrorListInfoBarController(this.host); this.ConfigureLoadedSolution(hasUnboundProject: false); var projectSystem = new ConfigurableVsProjectSystemHelper(this.serviceProvider); this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), projectSystem); var project = new ProjectMock("project.proj"); project.SetCSProjectKind(); projectSystem.FilteredProjects = new[] { project }; this.solutionBindingSerializer.CurrentBinding.Profiles = new Dictionary<Language, Persistence.ApplicableQualityProfile>(); this.solutionBindingSerializer.CurrentBinding.Profiles[Language.CSharp] = new Persistence.ApplicableQualityProfile { ProfileKey = "Profile", ProfileTimestamp = DateTime.Now }; var sqService = new ConfigurableSonarQubeServiceWrapper(); this.host.SonarQubeService = sqService; sqService.ReturnProfile[Language.CSharp] = new QualityProfile(); // Act testSubject.ProcessSolutionBinding(); // Verify Assert.IsNotNull(testSubject.CurrentBackgroundProcessor?.BackgroundTask, "Background task is expected"); Assert.IsTrue(testSubject.CurrentBackgroundProcessor.BackgroundTask.Wait(TimeSpan.FromSeconds(2)), "Timeout waiting for the background task"); this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); // Act (refresh again and let the blocked UI thread run to completion) testSubject.ProcessSolutionBinding(); DispatcherHelper.DispatchFrame(DispatcherPriority.Normal); this.IsActiveSolutionBound = false; // Verify that no info bar was added (due to the last action in which the state will not cause the info bar to appear) this.infoBarManager.AssertHasNoAttachedInfoBar(ErrorListInfoBarController.ErrorListToolWindowGuid); }