public async Task BindingWorkflow_DownloadQualityProfile_WhenQualityProfileIsNotAvailable_Fails() { // Arrange BindingWorkflow testSubject = this.CreateTestSubject(); ConfigurableProgressController controller = new ConfigurableProgressController(); var notifications = new ConfigurableProgressStepExecutionEvents(); var language = Language.CSharp; this.ConfigureProfileExport(null, Language.VBNET, ""); // Act await testSubject.DownloadQualityProfileAsync(controller, notifications, new[] { language }, CancellationToken.None); // Assert testSubject.Rulesets.Should().NotContainKey(Language.VBNET, "Not expecting any rules for this language"); testSubject.Rulesets.Should().NotContainKey(language, "Not expecting any rules"); controller.NumberOfAbortRequests.Should().Be(1); notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage); this.outputWindowPane.AssertOutputStrings(1); var expectedOutput = string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.CannotDownloadQualityProfileForLanguage, language.Name)); this.outputWindowPane.AssertOutputStrings(expectedOutput); }
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 async Task BindingWorkflow_DownloadQualityProfile_WithNoRules_Fails() { // Arrange const string QualityProfileName = "SQQualityProfileName"; const string ProjectName = "SQProjectName"; BindingWorkflow testSubject = this.CreateTestSubject("key", ProjectName); ConfigurableProgressController controller = new ConfigurableProgressController(); var notifications = new ConfigurableProgressStepExecutionEvents(); RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(Enumerable.Empty <string>()); var nugetPackages = new[] { new PackageName("myPackageId", new SemanticVersion("1.0.0")) }; var additionalFiles = new[] { new AdditionalFileResponse { FileName = "abc.xml", Content = new byte[] { 1, 2, 3 } } }; RoslynExportProfileResponse export = RoslynExportProfileHelper.CreateExport(ruleSet, nugetPackages, additionalFiles); var language = Language.VBNET; SonarQubeQualityProfile profile = this.ConfigureProfileExport(export, language, QualityProfileName); // Act await testSubject.DownloadQualityProfileAsync(controller, notifications, new[] { language }, CancellationToken.None); // Assert testSubject.Rulesets.Should().NotContainKey(Language.VBNET, "Not expecting any rules for this language"); testSubject.Rulesets.Should().NotContainKey(language, "Not expecting any rules"); controller.NumberOfAbortRequests.Should().Be(1); notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage); this.outputWindowPane.AssertOutputStrings(1); var expectedOutput = string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.NoSonarAnalyzerActiveRulesForQualityProfile, QualityProfileName, language.Name)); this.outputWindowPane.AssertOutputStrings(expectedOutput); }
public void TestInitialize() { this.host = new ConfigurableHost(new ConfigurableServiceProvider(), Dispatcher.CurrentDispatcher); this.mockBindingProcess = new Mock <IBindingProcess>(); this.testSubject = new BindingWorkflow(host, mockBindingProcess.Object); }
public async Task BindingWorkflow_DownloadQualityProfile_Success() { // Arrange const string QualityProfileName = "SQQualityProfileName"; const string ProjectName = "SQProjectName"; // Record all of the calls to NuGetBindingOperation.ProcessExport var actualProfiles = new List <Tuple <Language, RoslynExportProfileResponse> >(); Mock <INuGetBindingOperation> nuGetOpMock = new Mock <INuGetBindingOperation>(); nuGetOpMock.Setup(x => x.ProcessExport(It.IsAny <Language>(), It.IsAny <RoslynExportProfileResponse>())) .Callback <Language, RoslynExportProfileResponse>((l, r) => actualProfiles.Add(new Tuple <Language, RoslynExportProfileResponse>(l, r))) .Returns(true); BindingWorkflow testSubject = this.CreateTestSubject("key", ProjectName, nuGetOpMock.Object); ConfigurableProgressController controller = new ConfigurableProgressController(); var notifications = new ConfigurableProgressStepExecutionEvents(); RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" }); var expectedRuleSet = new RuleSet(ruleSet) { NonLocalizedDisplayName = string.Format(Strings.SonarQubeRuleSetNameFormat, ProjectName, QualityProfileName), NonLocalizedDescription = "\r\nhttp://connected/profiles/show?key=" }; var nugetPackages = new[] { new PackageName("myPackageId", new SemanticVersion("1.0.0")) }; var additionalFiles = new[] { new AdditionalFileResponse { FileName = "abc.xml", Content = new byte[] { 1, 2, 3 } } }; RoslynExportProfileResponse export = RoslynExportProfileHelper.CreateExport(ruleSet, nugetPackages, additionalFiles); var language = Language.VBNET; SonarQubeQualityProfile profile = this.ConfigureProfileExport(export, language, QualityProfileName); // Act await testSubject.DownloadQualityProfileAsync(controller, notifications, new[] { language }, CancellationToken.None); // Assert RuleSetAssert.AreEqual(expectedRuleSet, testSubject.Rulesets[language], "Unexpected rule set"); testSubject.QualityProfiles[language].Should().Be(profile); VerifyNuGetPackgesDownloaded(nugetPackages, language, actualProfiles); controller.NumberOfAbortRequests.Should().Be(0); notifications.AssertProgress(0.0, 1.0); notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage, string.Empty); this.outputWindowPane.AssertOutputStrings(1); var expectedOutput = string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.QualityProfileDownloadSuccessfulMessageFormat, QualityProfileName, string.Empty, language.Name)); this.outputWindowPane.AssertOutputStrings(expectedOutput); }
public void BindingWorkflow_DownloadQualityProfile_WithNoActiveRules_Fails() { // Arrange const string QualityProfileName = "SQQualityProfileName"; const string SonarQubeProjectName = "SQProjectName"; var projectInfo = new ProjectInformation { Key = "key", Name = SonarQubeProjectName }; BindingWorkflow testSubject = this.CreateTestSubject(projectInfo); ConfigurableProgressController controller = new ConfigurableProgressController(); var notifications = new ConfigurableProgressStepExecutionEvents(); RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" }); foreach (var rule in ruleSet.Rules) { rule.Action = RuleAction.None; } var expectedRuleSet = new RuleSet(ruleSet) { NonLocalizedDisplayName = string.Format(Strings.SonarQubeRuleSetNameFormat, SonarQubeProjectName, QualityProfileName), NonLocalizedDescription = "\r\nhttp://connected/profiles/show?key=" }; var nugetPackages = new[] { new PackageName("myPackageId", new SemanticVersion("1.0.0")) }; var additionalFiles = new[] { new AdditionalFile { FileName = "abc.xml", Content = new byte[] { 1, 2, 3 } } }; RoslynExportProfile export = RoslynExportProfileHelper.CreateExport(ruleSet, nugetPackages, additionalFiles); var language = Language.VBNET; QualityProfile profile = this.ConfigureProfileExport(export, language); profile.Name = QualityProfileName; // Act testSubject.DownloadQualityProfile(controller, CancellationToken.None, notifications, new[] { language }); // Assert testSubject.Rulesets.Should().NotContainKey(Language.VBNET, "Not expecting any rules for this language"); testSubject.Rulesets.Should().NotContainKey(language, "Not expecting any rules"); controller.NumberOfAbortRequests.Should().Be(1); notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage); this.outputWindowPane.AssertOutputStrings(1); var expectedOutput = string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.NoSonarAnalyzerActiveRulesForQualityProfile, QualityProfileName, language.Name)); this.outputWindowPane.AssertOutputStrings(expectedOutput); }
public void BindingWorkflow_DownloadQualityProfile_Success() { // Setup const string QualityProfileName = "SQQualityProfileName"; const string SonarQubeProjectName = "SQProjectName"; var projectInfo = new ProjectInformation { Key = "key", Name = SonarQubeProjectName }; BindingWorkflow testSubject = this.CreateTestSubject(projectInfo); ConfigurableProgressController controller = new ConfigurableProgressController(); var notifications = new ConfigurableProgressStepExecutionEvents(); RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" }); var expectedRuleSet = new RuleSet(ruleSet) { NonLocalizedDisplayName = string.Format(Strings.SonarQubeRuleSetNameFormat, SonarQubeProjectName, QualityProfileName), NonLocalizedDescription = "\r\nhttp://connected/profiles/show?key=" }; var nugetPackages = new[] { new PackageName("myPackageId", new SemanticVersion("1.0.0")) }; var additionalFiles = new[] { new AdditionalFile { FileName = "abc.xml", Content = new byte[] { 1, 2, 3 } } }; RoslynExportProfile export = RoslynExportProfileHelper.CreateExport(ruleSet, nugetPackages, additionalFiles); var language = Language.VBNET; QualityProfile profile = this.ConfigureProfileExport(export, language); profile.Name = QualityProfileName; // Act testSubject.DownloadQualityProfile(controller, CancellationToken.None, notifications, new[] { language }); // Verify RuleSetAssert.AreEqual(expectedRuleSet, testSubject.Rulesets[language], "Unexpected rule set"); Assert.AreSame(profile, testSubject.QualityProfiles[language]); VerifyNuGetPackgesDownloaded(nugetPackages, testSubject, language); controller.AssertNumberOfAbortRequests(0); notifications.AssertProgress( 0.0, 1.0); notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage, string.Empty); this.outputWindowPane.AssertOutputStrings(1); var expectedOutput = string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.QualityProfileDownloadSuccessfulMessageFormat, QualityProfileName, string.Empty, language.Name)); this.outputWindowPane.AssertOutputStrings(expectedOutput); }
private ConfigurablePackageInstaller PrepareInstallPackagesTest(BindingWorkflow testSubject, Dictionary <Language, IEnumerable <PackageName> > nugetPackagesByLanguage, params Project[] projects) { testSubject.BindingProjects.Clear(); testSubject.BindingProjects.AddRange(projects); foreach (var nugetPackagesForLanguage in nugetPackagesByLanguage) { testSubject.NuGetPackages.Add(nugetPackagesForLanguage.Key, nugetPackagesForLanguage.Value.Select(x => new NuGetPackageInfoResponse { Id = x.Id, Version = x.Version.ToNormalizedString() }).ToList()); } ConfigurablePackageInstaller packageInstaller = new ConfigurablePackageInstaller(nugetPackagesByLanguage.Values.SelectMany(x => x)); this.serviceProvider.RegisterService(typeof(SComponentModel), ConfigurableComponentModel.CreateWithExports(MefTestHelpers.CreateExport <IVsPackageInstaller>(packageInstaller))); return(packageInstaller); }
public async Task BindingWorkflow_DownloadQualityProfile_LegacyMode_WithNoNugetPackage_Fails() { // Arrange const string QualityProfileName = "SQQualityProfileName"; const string ProjectName = "SQProjectName"; var legacyNuGetBinding = new NuGetBindingOperation(this.host, this.host.Logger); BindingWorkflow testSubject = this.CreateTestSubject("key", ProjectName, legacyNuGetBinding); ConfigurableProgressController controller = new ConfigurableProgressController(); var notifications = new ConfigurableProgressStepExecutionEvents(); RuleSet ruleSet = TestRuleSetHelper.CreateTestRuleSetWithRuleIds(new[] { "Key1", "Key2" }); var expectedRuleSet = new RuleSet(ruleSet) { NonLocalizedDisplayName = string.Format(Strings.SonarQubeRuleSetNameFormat, ProjectName, QualityProfileName), NonLocalizedDescription = "\r\nhttp://connected/profiles/show?key=" }; var additionalFiles = new[] { new AdditionalFileResponse { FileName = "abc.xml", Content = new byte[] { 1, 2, 3 } } }; RoslynExportProfileResponse export = RoslynExportProfileHelper.CreateExport(ruleSet, Enumerable.Empty <PackageName>(), additionalFiles); var language = Language.VBNET; SonarQubeQualityProfile profile = this.ConfigureProfileExport(export, language, QualityProfileName); // Act await testSubject.DownloadQualityProfileAsync(controller, notifications, new[] { language }, CancellationToken.None); // Assert testSubject.Rulesets.Should().NotContainKey(Language.VBNET, "Not expecting any rules for this language"); testSubject.Rulesets.Should().NotContainKey(language, "Not expecting any rules"); controller.NumberOfAbortRequests.Should().Be(1); notifications.AssertProgressMessages(Strings.DownloadingQualityProfileProgressMessage); this.outputWindowPane.AssertOutputStrings(1); var expectedOutput = string.Format(Strings.SubTextPaddingFormat, string.Format(Strings.NoNuGetPackageForQualityProfile, language.Name)); this.outputWindowPane.AssertOutputStrings(expectedOutput); }
public void BindingWorkflow_GetProjectsForRulesetBinding_NoProjectsUpToDate() { // Arrange var allProjects = new Project[] { new ProjectMock("cs1.csproj"), new ProjectMock("cs2.csproj"), new ProjectMock("cs3.csproj") }; var logger = new TestLogger(); var bindingInfoProvider = new ConfigurableSolutionBindingInformationProvider(); bindingInfoProvider.UnboundProjects = allProjects; // Act var result = BindingWorkflow.GetProjectsForRulesetBinding(false, allProjects, bindingInfoProvider, logger); // Assert result.Should().BeEquivalentTo(allProjects); logger.AssertOutputStringExists(Strings.Bind_Ruleset_AllProjectsNeedToBeUpdated); }
public void BindingWorkflow_InitializeSolutionBinding_Update_AllUpToDate_NoProjectsUpdated() { // Arrange var allProjects = new Project[] { new ProjectMock("cs1.csproj"), new ProjectMock("cs2.csproj"), new ProjectMock("cs3.csproj"), new ProjectMock("cs4.csproj") }; var logger = new TestLogger(); var bindingInfoProvider = new ConfigurableSolutionBindingInformationProvider(); bindingInfoProvider.UnboundProjects = null; // Act var result = BindingWorkflow.GetProjectsForRulesetBinding(false, allProjects, bindingInfoProvider, logger); // Assert result.Should().BeEmpty(); logger.AssertOutputStringExists(Strings.Bind_Ruleset_SomeProjectsDoNotNeedToBeUpdated); logger.AssertPartialOutputStringExists("cs1.csproj", "cs2.csproj", "cs3.csproj", "cs4.csproj"); }
private static void VerifyNuGetPackgesDownloaded(IEnumerable <PackageName> expectedPackages, BindingWorkflow testSubject, Language language) { var expected = expectedPackages.ToArray(); testSubject.NuGetPackages.Should().ContainKey(language); var actual = testSubject.NuGetPackages[language].Select(x => new PackageName(x.Id, new SemanticVersion(x.Version))).ToArray(); actual.Should().HaveSameCount(expected, "Different number of packages."); actual.Select(x => x.ToString()).Should().Equal(expected.Select(x => x.ToString())); }
private static void VerifyNuGetPackgesDownloaded(IEnumerable <PackageName> expectedPackages, BindingWorkflow testSubject, Language language) { var expected = expectedPackages.ToArray(); if (!testSubject.NuGetPackages.ContainsKey(language)) { Assert.Fail("Given language doesn't exists"); } var actual = testSubject.NuGetPackages[language].Select(x => new PackageName(x.Id, new SemanticVersion(x.Version))).ToArray(); Assert.AreEqual(expected.Length, actual.Length, "Different number of packages."); for (int i = 0; i < expected.Length; i++) { Assert.IsTrue(expected[i].Equals(actual[i]), $"Packages are different at index {i}."); } }