public async Task BindingWorkflow_DownloadQualityProfile_Success() { // Arrange ConfigurableProgressController controller = new ConfigurableProgressController(); var notifications = new ConfigurableProgressStepExecutionEvents(); SetDownloadQPResult(true); // Act await testSubject.DownloadQualityProfileAsync(controller, notifications, CancellationToken.None) .ConfigureAwait(false); // Assert controller.NumberOfAbortRequests.Should().Be(0); }
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 async Task BindingWorkflow_DownloadQualityProfile_WhenProfileExportIsNotAvailable_Fails() { // Arrange BindingWorkflow testSubject = this.CreateTestSubject(); ConfigurableProgressController controller = new ConfigurableProgressController(); var notifications = new ConfigurableProgressStepExecutionEvents(); var language = Language.CSharp; this.ConfigureProfileExport(null, language, ""); // 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.QualityProfileDownloadFailedMessageFormat, string.Empty, string.Empty, language.Name)); this.outputWindowPane.AssertOutputStrings(expectedOutput); }
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 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); }