Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gb/cleanup taint sqs #5834

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
eb24cf2
SLVS-1582 Support new SLCore DTOs for rule descriptions (#5798)
georgii-borovinskikh-sonarsource Nov 7, 2024
ff36cfa
SLVS-1590 Add SLCore rpc contracts for taint issues (#5808)
georgii-borovinskikh-sonarsource Nov 7, 2024
9f15429
SLVS-1596 Add GetEffectiveIssueDetailsAsync (#5814)
vnaskos-sonar Nov 8, 2024
26319fd
SLVS-1589 Update RaisedFindingDto to support new MQR/Std mode with ov…
gabriela-trutan-sonarsource Nov 11, 2024
6aecf95
SLVS-1606 Update SLCore to 10.9 release (#5817)
gabriela-trutan-sonarsource Nov 11, 2024
ae5ffaf
SLVS-1563 Raise CurrentConfigurationScopeChanged when configuration s…
gabriela-trutan-sonarsource Oct 30, 2024
3620cf6
SLVS-1612 Update the RaiseFindingToAnalysisIssueConverter (#5819)
gabriela-trutan-sonarsource Nov 11, 2024
e8d8254
SLVS-1613 Add conversion from TaintVulnerabilityDto to IAnalysisIssue…
georgii-borovinskikh-sonarsource Nov 12, 2024
6baf1e0
SLVS-1597 Store SLCore issue id in AnalysisIssue (#5823)
gabriela-trutan-sonarsource Nov 12, 2024
fb03a90
SLVS-1614 Fix Category in the error list for MQR mode (#5822)
gabriela-trutan-sonarsource Nov 12, 2024
7dc403b
SLVS-1621 Clean up custom SSE implementation for taints (#5826)
georgii-borovinskikh-sonarsource Nov 14, 2024
66a7607
SLVS-1592 Update TaintStore with taints from SLCore (#5821)
georgii-borovinskikh-sonarsource Nov 14, 2024
1fad501
SLVS-1598 Use getEffectiveIssueDetails for issues with SLCore id inst…
gabriela-trutan-sonarsource Nov 14, 2024
64f505a
SLVS-1616 TaintIssuesControl & TaintIssuesControlViewModel: remove An…
georgii-borovinskikh-sonarsource Nov 14, 2024
a4e28c1
SLVS-1628 Remove taint related methods from SonarQubeService
georgii-borovinskikh-sonarsource Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 46 additions & 57 deletions src/ConnectedMode.UnitTests/ServerSentEvents/SSESessionFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,81 +18,70 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/


using System;
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.TestInfrastructure;
using SonarQube.Client;
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.Taint;
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.Issue;
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.QualityProfile;

namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.ServerSentEvents
namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.ServerSentEvents;

[TestClass]
public class SSESessionFactoryTests
{
[TestClass]
public class SSESessionFactoryTests
[TestMethod]
public void MefCtor_CheckIsExported()
{
[TestMethod]
public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<SSESessionFactory, ISSESessionFactory>(
MefTestHelpers.CreateExport<ISonarQubeService>(),
MefTestHelpers.CreateExport<ITaintServerEventSourcePublisher>(),
MefTestHelpers.CreateExport<IIssueServerEventSourcePublisher>(),
MefTestHelpers.CreateExport<IQualityProfileServerEventSourcePublisher>(),
MefTestHelpers.CreateExport<ILogger>(),
MefTestHelpers.CreateExport<IThreadHandling>());
}
MefTestHelpers.CheckTypeCanBeImported<SSESessionFactory, ISSESessionFactory>(
MefTestHelpers.CreateExport<ISonarQubeService>(),
MefTestHelpers.CreateExport<IIssueServerEventSourcePublisher>(),
MefTestHelpers.CreateExport<IQualityProfileServerEventSourcePublisher>(),
MefTestHelpers.CreateExport<ILogger>(),
MefTestHelpers.CreateExport<IThreadHandling>());
}

[TestMethod]
public void Create_ReturnsCorrectType()
{
var testSubject = CreateTestSubject();
[TestMethod]
public void Create_ReturnsCorrectType()
{
var testSubject = CreateTestSubject();

var sseSession = testSubject.Create("MyProjectName", null);
var sseSession = testSubject.Create("MyProjectName", null);

sseSession.Should().NotBeNull().And.BeOfType<SSESessionFactory.SSESession>();
}
sseSession.Should().NotBeNull().And.BeOfType<SSESessionFactory.SSESession>();
}

[TestMethod]
public void Create_AfterDispose_Throws()
{
var testSubject = CreateTestSubject();
[TestMethod]
public void Create_AfterDispose_Throws()
{
var testSubject = CreateTestSubject();

testSubject.Dispose();
Action act = () => testSubject.Create("MyProjectName", null);
testSubject.Dispose();
Action act = () => testSubject.Create("MyProjectName", null);

act.Should().Throw<ObjectDisposedException>();
}
act.Should().Throw<ObjectDisposedException>();
}

[TestMethod]
public void Dispose_IdempotentAndDisposesPublishers()
{
var taintPublisherMock = new Mock<ITaintServerEventSourcePublisher>();
var issuesPublisherMock = new Mock<IIssueServerEventSourcePublisher>();
var qualityProfilePublisherMock = new Mock<IQualityProfileServerEventSourcePublisher>();
var testSubject = CreateTestSubject(taintPublisherMock, issuesPublisherMock, qualityProfilePublisherMock);
[TestMethod]
public void Dispose_IdempotentAndDisposesPublishers()
{
var issuesPublisherMock = new Mock<IIssueServerEventSourcePublisher>();
var qualityProfilePublisherMock = new Mock<IQualityProfileServerEventSourcePublisher>();
var testSubject = CreateTestSubject(issuesPublisherMock, qualityProfilePublisherMock);

testSubject.Dispose();
testSubject.Dispose();
testSubject.Dispose();
testSubject.Dispose();
testSubject.Dispose();
testSubject.Dispose();

taintPublisherMock.Verify(p => p.Dispose(), Times.Once);
issuesPublisherMock.Verify(p => p.Dispose(), Times.Once);
qualityProfilePublisherMock.Verify(p => p.Dispose(), Times.Once);
}
issuesPublisherMock.Verify(p => p.Dispose(), Times.Once);
qualityProfilePublisherMock.Verify(p => p.Dispose(), Times.Once);
}

private SSESessionFactory CreateTestSubject(Mock<ITaintServerEventSourcePublisher> taintPublisher = null,
Mock<IIssueServerEventSourcePublisher> issuePublisher = null,
Mock<IQualityProfileServerEventSourcePublisher> qualityProfileServerEventSourcePublisher = null)
{
return new SSESessionFactory(Mock.Of<ISonarQubeService>(),
taintPublisher?.Object ?? Mock.Of<ITaintServerEventSourcePublisher>(),
issuePublisher?.Object ?? Mock.Of<IIssueServerEventSourcePublisher>(),
qualityProfileServerEventSourcePublisher?.Object ?? Mock.Of<IQualityProfileServerEventSourcePublisher>(),
private SSESessionFactory CreateTestSubject(Mock<IIssueServerEventSourcePublisher> issuePublisher = null,
Mock<IQualityProfileServerEventSourcePublisher> qualityProfileServerEventSourcePublisher = null) =>
new(Mock.Of<ISonarQubeService>(),
issuePublisher?.Object ?? Mock.Of<IIssueServerEventSourcePublisher>(),
qualityProfileServerEventSourcePublisher?.Object ?? Mock.Of<IQualityProfileServerEventSourcePublisher>(),
Mock.Of<IThreadHandling>(),
Mock.Of<ILogger>());
}
}
Mock.Of<ILogger>());
}
23 changes: 1 addition & 22 deletions src/ConnectedMode.UnitTests/ServerSentEvents/SSESessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.TestInfrastructure;
using SonarQube.Client;
using SonarQube.Client.Models.ServerSentEvents;
using SonarQube.Client.Models.ServerSentEvents.ClientContract;
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.Taint;
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.Issue;
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.QualityProfile;

Expand Down Expand Up @@ -62,22 +55,17 @@ public async Task PumpAllAsync_SelectsPublisherCorrectlyAndPreservesOrderWithinT
var inputSequence = new IServerEvent[]
{
Mock.Of<IIssueChangedServerEvent>(),
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
Mock.Of<IQualityProfileEvent>(),
Mock.Of<IIssueChangedServerEvent>(),
Mock.Of<ITaintVulnerabilityClosedServerEvent>(),
Mock.Of<ITaintVulnerabilityClosedServerEvent>(),
Mock.Of<IQualityProfileEvent>(),
Mock.Of<IIssueChangedServerEvent>(),
Mock.Of<ITaintVulnerabilityRaisedServerEvent>()
};
testScope.SetUpSwitchToBackgroundThread();
var sseStreamMock = testScope.SetUpSQServiceToSuccessfullyReturnSSEStreamReader();
testScope.SetUpSSEStreamReaderToReturnEventsSequenceAndExit(sseStreamMock, inputSequence);

await testScope.TestSubject.PumpAllAsync();

CheckEventsSequence<ITaintServerEvent>(testScope.TaintPublisherMock.Invocations);
CheckEventsSequence<IIssueChangedServerEvent>(testScope.IssuePublisherMock.Invocations);
CheckEventsSequence<IQualityProfileEvent>(testScope.QualityProfilePublisherMock.Invocations);

Expand All @@ -100,18 +88,15 @@ public async Task PumpAllAsync_WhenNullEvent_Ignores()
testScope.SetUpSSEStreamReaderToReturnEventsSequenceAndExit(sseStreamMock,
new IServerEvent[]
{
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
Mock.Of<IQualityProfileEvent>(),
null,
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
Mock.Of<IIssueChangedServerEvent>(),
Mock.Of<IQualityProfileEvent>(),
Mock.Of<IIssueChangedServerEvent>()
});

await testScope.TestSubject.PumpAllAsync();

testScope.TaintPublisherMock.Verify(publisher => publisher.Publish(It.IsAny<ITaintServerEvent>()), Times.Exactly(2));
testScope.IssuePublisherMock.Verify(publisher => publisher.Publish(It.IsAny<IIssueChangedServerEvent>()), Times.Exactly(2));
testScope.QualityProfilePublisherMock.Verify(publisher => publisher.Publish(It.IsAny<IQualityProfileEvent>()), Times.Exactly(2));
}
Expand All @@ -126,16 +111,13 @@ public async Task PumpAllAsync_WhenUnsupportedEvent_Ignores()
testScope.SetUpSSEStreamReaderToReturnEventsSequenceAndExit(sseStreamMock,
new IServerEvent[]
{
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
Mock.Of<IQualityProfileEvent>(),
Mock.Of<IDummyServerEvent>(),
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
Mock.Of<IIssueChangedServerEvent>()
});

await testScope.TestSubject.PumpAllAsync();

testScope.TaintPublisherMock.Verify(publisher => publisher.Publish(It.IsAny<ITaintServerEvent>()), Times.Exactly(2));
testScope.IssuePublisherMock.Verify(publisher => publisher.Publish(It.IsAny<IIssueChangedServerEvent>()), Times.Exactly(1));
testScope.QualityProfilePublisherMock.Verify(publisher => publisher.Publish(It.IsAny<IQualityProfileEvent>()), Times.Exactly(1));
}
Expand Down Expand Up @@ -232,7 +214,6 @@ public TestScope()
{
mockRepository = new MockRepository(MockBehavior.Strict);
SonarQubeServiceMock = mockRepository.Create<ISonarQubeService>();
TaintPublisherMock = mockRepository.Create<ITaintServerEventSourcePublisher>(MockBehavior.Loose);
IssuePublisherMock = mockRepository.Create<IIssueServerEventSourcePublisher>(MockBehavior.Loose);
QualityProfilePublisherMock = mockRepository.Create<IQualityProfileServerEventSourcePublisher>(MockBehavior.Loose);
ThreadHandlingMock = mockRepository.Create<IThreadHandling>();
Expand All @@ -241,18 +222,16 @@ public TestScope()

var factory = new SSESessionFactory(
SonarQubeServiceMock.Object,
TaintPublisherMock.Object,
IssuePublisherMock.Object,
QualityProfilePublisherMock.Object,
ThreadHandlingMock.Object,
LoggerMock.Object);

TestSubject = factory.Create("blalala", OnSessionFailedAsyncMock.Object);
}

private Mock<IThreadHandling> ThreadHandlingMock { get; }
public Mock<ISonarQubeService> SonarQubeServiceMock { get; }
public Mock<ITaintServerEventSourcePublisher> TaintPublisherMock { get; }
public Mock<IIssueServerEventSourcePublisher> IssuePublisherMock { get; }
public Mock<IQualityProfileServerEventSourcePublisher> QualityProfilePublisherMock { get; }
public Mock<ILogger> LoggerMock { get; }
Expand Down
1 change: 1 addition & 0 deletions src/ConnectedMode.UnitTests/TestFilterableIssue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace SonarLint.VisualStudio.ConnectedMode.UnitTests;

internal class TestFilterableIssue : IFilterableIssue
{
public Guid? IssueId { get; set; }
public string RuleId { get; set; }
public string LineHash { get; set; }
public int? StartLine { get; set; }
Expand Down
Loading