public void GetQualityProfile_WhenHasExportResponse_ReturnsExportResponse() { // Arrange XmlDocument rulesetDoc = new XmlDocument(); var rulesXml = @"<?xml version=""1.0"" encoding=""utf-8""?> <RuleSet Name=""Rules for SonarQube"" Description=""This rule set was automatically generated from SonarQube."" ToolsVersion=""14.0""> <Rules AnalyzerId=""SonarAnalyzer.CSharp"" RuleNamespace=""SonarAnalyzer.CSharp""> <Rule Id=""S121"" Action=""Warning"" /> <Rule Id=""S122"" Action=""Warning"" /> </Rules> </RuleSet>"; rulesetDoc.LoadXml(rulesXml); var exportResponse = new RoslynExportProfileResponse { Configuration = new ConfigurationResponse { RuleSet = rulesetDoc.DocumentElement } }; SetupServiceResponses(ValidQualityProfileResponse, exportResponse); var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object); // Act var result = testSubject.GetQualityProfile(new BoundSonarQubeProject(), Language.VBNET); // Assert result.Should().NotBeNull(); result.Rules.Count().Should().Be(2); }
public void GetQualityProfile_WhenHasUnrecognisedLanguage_ReturnsNull() { // Arrange var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object); // Act var result = testSubject.GetQualityProfile(new BoundSonarQubeProject(), Language.Unknown); // Assert result.Should().BeNull(); }
public void GetQualityProfile_WhenHasNullExportResponse_ReturnsNull() { // Arrange SetupServiceResponses(ValidQualityProfileResponse, null); var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object); // Act var result = testSubject.GetQualityProfile(new BoundSonarQubeProject(), Language.Unknown); // Assert result.Should().BeNull(); }
public void GetQualityProfile_WhenHasNullArgs_Throws() { var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object); // 1. Null project Action act = () => testSubject.GetQualityProfile(null, Language.CSharp); act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("project"); // 2. Null language act = () => testSubject.GetQualityProfile(new BoundSonarQubeProject(), null); act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("language"); }
public void GetQualityProfile_WhenHasNoQualityProfile_ReturnsNull() { // Arrange serviceMock .Setup(x => x.GetQualityProfileAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SonarQubeLanguage>(), It.IsAny <CancellationToken>())) .Throws(new InvalidOperationException("The SonarC# plugin is not installed on the connected SonarQube.")); var testSubject = new SonarQubeQualityProfileProvider(serviceMock.Object, loggerMock.Object); // Act var result = testSubject.GetQualityProfile(new BoundSonarQubeProject(), Language.CSharp); // Assert result.Should().BeNull(); loggerMock.Verify( x => x.WriteLine("SonarQube request failed: {0} {1}", "The SonarC# plugin is not installed on the connected SonarQube.", null), Times.Once()); }
private void RefreshWorkflow(BindingConfiguration configuration) { // There might be some race condition here if an analysis is triggered while the delegates are reset and set back // to the new workflow behavior. This race condition would lead to some issues being reported using the old mode // instead of the new one but everything will be fixed on the next analysis. ResetState(); switch (configuration?.Mode) { case SonarLintMode.Standalone: this.currentWorklow = new SonarAnalyzerStandaloneWorkflow(this.workspace); break; case SonarLintMode.LegacyConnected: case SonarLintMode.Connected: var sonarQubeIssueProvider = new SonarQubeIssuesProvider(sonarQubeService, configuration.Project.ProjectKey, new TimerFactory()); this.disposableObjects.Add(sonarQubeIssueProvider); var liveIssueFactory = new LiveIssueFactory(workspace, vsSolution); var suppressionHandler = new SuppressionHandler(liveIssueFactory, sonarQubeIssueProvider); if (configuration.Mode == SonarLintMode.Connected) { var qualityProfileProvider = new SonarQubeQualityProfileProvider(sonarQubeService, logger); this.disposableObjects.Add(qualityProfileProvider); var cachingProvider = new QualityProfileProviderCachingDecorator(qualityProfileProvider, configuration.Project, sonarQubeService, new TimerFactory()); this.disposableObjects.Add(cachingProvider); this.currentWorklow = new SonarAnalyzerConnectedWorkflow(this.workspace, cachingProvider, configuration.Project, suppressionHandler); } else // Legacy { this.currentWorklow = new SonarAnalyzerLegacyConnectedWorkflow(this.workspace, suppressionHandler, this.logger); } break; default: break; } }