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.logger.WriteLine(Resources.Strings.AnalyzerManager_InStandaloneMode); this.currentWorklow = new SonarAnalyzerStandaloneWorkflow(this.workspace); break; case SonarLintMode.LegacyConnected: case SonarLintMode.Connected: this.logger.WriteLine(Resources.Strings.AnalyzerManager_InConnectedMode); var liveIssueFactory = new RoslynLiveIssueFactory(workspace, vsSolution); var suppressionHandler = new RoslynSuppressionHandler(liveIssueFactory, new SuppressedIssueMatcher(sonarQubeIssuesProvider)); if (configuration.Mode == SonarLintMode.Connected) { this.currentWorklow = new SonarAnalyzerConnectedWorkflow(this.workspace, suppressionHandler); } else // Legacy { this.currentWorklow = new SonarAnalyzerLegacyConnectedWorkflow(this.workspace, suppressionHandler, this.logger); } break; } }
public void ShouldReport_LocationNotInSource_ReturnsTrue() { // Arrange Diagnostic diag = CreateDiagnostic("dummy rule ID", CreateNonSourceLocation()); RoslynSuppressionHandler handler = new RoslynSuppressionHandler(issueFactoryMock.Object, issueMatcherMock.Object); // Act bool result = handler.ShouldIssueBeReported(new Mock <SyntaxTree>().Object, diag); // Assert result.Should().BeTrue(); // Should early-out VerifyLiveIssueCreated(Times.Never()); VerifyServerIssuesRequested(Times.Never()); }
public void ShouldReport_CannotCreateLiveIssue_ReturnsTrue() { // Arrange Diagnostic diag = CreateDiagnostic("dummy rule id", CreateSourceLocation()); SetLiveIssue(null); RoslynSuppressionHandler handler = new RoslynSuppressionHandler(issueFactoryMock.Object, issueMatcherMock.Object); // Act bool result = handler.ShouldIssueBeReported(syntaxTreeMock.Object, diag); // Assert VerifyLiveIssueCreated(Times.Once()); VerifyServerIssuesRequested(Times.Never()); result.Should().BeTrue(); }
public void ShouldReport_MatchingSuppressionExists(bool suppressionExists, bool expectedShouldIssueBeReported) { // Arrange Diagnostic diag = CreateDiagnostic("dummy rule id", CreateSourceLocation()); SetLiveIssue(diag, startLine: 1, wholeLineText: "text"); SetSuppressionExistsResponse(suppressionExists); RoslynSuppressionHandler handler = new RoslynSuppressionHandler(issueFactoryMock.Object, issueMatcherMock.Object); // Act bool result = handler.ShouldIssueBeReported(syntaxTreeMock.Object, diag); // Assert VerifyLiveIssueCreated(Times.Once()); VerifyServerIssuesRequested(Times.Once()); result.Should().Be(expectedShouldIssueBeReported); }