-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLVS-1693 Fix: issues set to empty after hotspots event (#5886)
[SLVS-1693](https://sonarsource.atlassian.net/browse/SLVS-1693) [SLVS-1693]: https://sonarsource.atlassian.net/browse/SLVS-1693?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
1 parent
3902570
commit 1d8a731
Showing
23 changed files
with
614 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
using SonarLint.VisualStudio.Core.Analysis; | ||
using SonarLint.VisualStudio.TestInfrastructure; | ||
|
||
namespace SonarLint.VisualStudio.Core.UnitTests.Analysis; | ||
|
||
[TestClass] | ||
public class HotspotPublisherTests | ||
{ | ||
private IIssueConsumerStorage issueConsumerStorage; | ||
private IIssueConsumer issueConsumer; | ||
private HotspotPublisher testSubject; | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsExported() => | ||
MefTestHelpers.CheckTypeCanBeImported<HotspotPublisher, IHotspotPublisher>(MefTestHelpers.CreateExport<IIssueConsumerStorage>()); | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsSingleton() => | ||
MefTestHelpers.CheckIsSingletonMefComponent<HotspotPublisher>(); | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
issueConsumerStorage = Substitute.For<IIssueConsumerStorage>(); | ||
issueConsumer = Substitute.For<IIssueConsumer>(); | ||
testSubject = new HotspotPublisher(issueConsumerStorage); | ||
} | ||
|
||
[TestMethod] | ||
public void PublishHotspots_NoConsumerInStorage_DoesNothing() | ||
{ | ||
issueConsumerStorage.TryGet(default, out _, out _).ReturnsForAnyArgs(false); | ||
|
||
var act = () => testSubject.Publish("file/path", Guid.NewGuid(), Substitute.For<IEnumerable<IAnalysisIssue>>()); | ||
|
||
act.Should().NotThrow(); | ||
issueConsumer.DidNotReceiveWithAnyArgs().SetIssues(default, default); | ||
issueConsumer.DidNotReceiveWithAnyArgs().SetHotspots(default, default); | ||
} | ||
|
||
[TestMethod] | ||
public void PublishHotspots_DifferentAnalysisId_DoesNothing() | ||
{ | ||
issueConsumerStorage.TryGet("file/path", out Arg.Any<Guid>(), out Arg.Any<IIssueConsumer>()) | ||
.Returns(info => | ||
{ | ||
info[1] = Guid.NewGuid(); | ||
info[2] = issueConsumer; | ||
return true; | ||
}); | ||
|
||
testSubject.Publish("file/path", Guid.NewGuid(), Substitute.For<IEnumerable<IAnalysisIssue>>()); | ||
|
||
issueConsumer.DidNotReceiveWithAnyArgs().SetIssues(default, default); | ||
issueConsumer.DidNotReceiveWithAnyArgs().SetHotspots(default, default); | ||
} | ||
|
||
[TestMethod] | ||
public void PublishHotspots_MatchingConsumer_PublishesHotspots() | ||
{ | ||
var analysisId = Guid.NewGuid(); | ||
var analysisIssues = Substitute.For<IEnumerable<IAnalysisIssue>>(); | ||
issueConsumerStorage.TryGet("file/path", out Arg.Any<Guid>(), out Arg.Any<IIssueConsumer>()) | ||
.Returns(info => | ||
{ | ||
info[1] = analysisId; | ||
info[2] = issueConsumer; | ||
return true; | ||
}); | ||
|
||
testSubject.Publish("file/path", analysisId, analysisIssues); | ||
|
||
issueConsumer.Received().SetHotspots("file/path", analysisIssues); | ||
issueConsumer.DidNotReceiveWithAnyArgs().SetIssues(default, default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
using SonarLint.VisualStudio.Core.Analysis; | ||
using SonarLint.VisualStudio.TestInfrastructure; | ||
|
||
namespace SonarLint.VisualStudio.Core.UnitTests.Analysis; | ||
|
||
[TestClass] | ||
public class IssuePublisherTests | ||
{ | ||
private IIssueConsumerStorage issueConsumerStorage; | ||
private IIssueConsumer issueConsumer; | ||
private IssuePublisher testSubject; | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsExported() => | ||
MefTestHelpers.CheckTypeCanBeImported<IssuePublisher, IIssuePublisher>(MefTestHelpers.CreateExport<IIssueConsumerStorage>()); | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsSingleton() => | ||
MefTestHelpers.CheckIsSingletonMefComponent<IssuePublisher>(); | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
issueConsumerStorage = Substitute.For<IIssueConsumerStorage>(); | ||
issueConsumer = Substitute.For<IIssueConsumer>(); | ||
testSubject = new IssuePublisher(issueConsumerStorage); | ||
} | ||
|
||
[TestMethod] | ||
public void PublishIssues_NoConsumerInStorage_DoesNothing() | ||
{ | ||
issueConsumerStorage.TryGet(default, out _, out _).ReturnsForAnyArgs(false); | ||
|
||
var act = () => testSubject.Publish("file/path", Guid.NewGuid(), Substitute.For<IEnumerable<IAnalysisIssue>>()); | ||
|
||
act.Should().NotThrow(); | ||
issueConsumer.DidNotReceiveWithAnyArgs().SetIssues(default, default); | ||
issueConsumer.DidNotReceiveWithAnyArgs().SetHotspots(default, default); | ||
} | ||
|
||
[TestMethod] | ||
public void PublishIssues_DifferentAnalysisId_DoesNothing() | ||
{ | ||
issueConsumerStorage.TryGet("file/path", out Arg.Any<Guid>(), out Arg.Any<IIssueConsumer>()) | ||
.Returns(info => | ||
{ | ||
info[1] = Guid.NewGuid(); | ||
info[2] = issueConsumer; | ||
return true; | ||
}); | ||
|
||
testSubject.Publish("file/path", Guid.NewGuid(), Substitute.For<IEnumerable<IAnalysisIssue>>()); | ||
|
||
issueConsumer.DidNotReceiveWithAnyArgs().SetIssues(default, default); | ||
issueConsumer.DidNotReceiveWithAnyArgs().SetHotspots(default, default); | ||
} | ||
|
||
[TestMethod] | ||
public void PublishIssues_MatchingConsumer_PublishesIssues() | ||
{ | ||
var analysisId = Guid.NewGuid(); | ||
var analysisIssues = Substitute.For<IEnumerable<IAnalysisIssue>>(); | ||
issueConsumerStorage.TryGet("file/path", out Arg.Any<Guid>(), out Arg.Any<IIssueConsumer>()) | ||
.Returns(info => | ||
{ | ||
info[1] = analysisId; | ||
info[2] = issueConsumer; | ||
return true; | ||
}); | ||
|
||
testSubject.Publish("file/path", analysisId, analysisIssues); | ||
|
||
issueConsumer.Received().SetIssues("file/path", analysisIssues); | ||
issueConsumer.DidNotReceiveWithAnyArgs().SetHotspots(default, default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
using System.ComponentModel.Composition; | ||
|
||
namespace SonarLint.VisualStudio.Core.Analysis; | ||
|
||
[Export(typeof(IHotspotPublisher))] | ||
[PartCreationPolicy(CreationPolicy.Shared)] | ||
[method:ImportingConstructor] | ||
internal class HotspotPublisher(IIssueConsumerStorage issueConsumerStorage) : IHotspotPublisher | ||
{ | ||
public void Publish(string filePath, Guid analysisId, IEnumerable<IAnalysisIssue> findings) | ||
{ | ||
if (issueConsumerStorage.TryGet(filePath, out var currentAnalysisId, out var issueConsumer) | ||
&& analysisId == currentAnalysisId) | ||
{ | ||
issueConsumer.SetHotspots(filePath, findings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
namespace SonarLint.VisualStudio.Core.Analysis; | ||
|
||
public interface IFindingsPublisher | ||
{ | ||
/// <summary> | ||
/// Handles analysis results | ||
/// </summary> | ||
void Publish(string filePath, Guid analysisId, IEnumerable<IAnalysisIssue> findings); | ||
} | ||
|
||
public interface IIssuePublisher : IFindingsPublisher; | ||
|
||
public interface IHotspotPublisher : IFindingsPublisher; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.