Skip to content

Commit c4e925c

Browse files

File tree

14 files changed

+171
-1023
lines changed

14 files changed

+171
-1023
lines changed

src/ConnectedMode.UnitTests/ServerSentEvents/SSESessionFactoryTests.cs

Lines changed: 46 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,81 +18,70 @@
1818
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
2020

21-
22-
using System;
2321
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents;
2422
using SonarLint.VisualStudio.Core;
2523
using SonarLint.VisualStudio.TestInfrastructure;
2624
using SonarQube.Client;
27-
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.Taint;
2825
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.Issue;
2926
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.QualityProfile;
3027

31-
namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.ServerSentEvents
28+
namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.ServerSentEvents;
29+
30+
[TestClass]
31+
public class SSESessionFactoryTests
3232
{
33-
[TestClass]
34-
public class SSESessionFactoryTests
33+
[TestMethod]
34+
public void MefCtor_CheckIsExported()
3535
{
36-
[TestMethod]
37-
public void MefCtor_CheckIsExported()
38-
{
39-
MefTestHelpers.CheckTypeCanBeImported<SSESessionFactory, ISSESessionFactory>(
40-
MefTestHelpers.CreateExport<ISonarQubeService>(),
41-
MefTestHelpers.CreateExport<ITaintServerEventSourcePublisher>(),
42-
MefTestHelpers.CreateExport<IIssueServerEventSourcePublisher>(),
43-
MefTestHelpers.CreateExport<IQualityProfileServerEventSourcePublisher>(),
44-
MefTestHelpers.CreateExport<ILogger>(),
45-
MefTestHelpers.CreateExport<IThreadHandling>());
46-
}
36+
MefTestHelpers.CheckTypeCanBeImported<SSESessionFactory, ISSESessionFactory>(
37+
MefTestHelpers.CreateExport<ISonarQubeService>(),
38+
MefTestHelpers.CreateExport<IIssueServerEventSourcePublisher>(),
39+
MefTestHelpers.CreateExport<IQualityProfileServerEventSourcePublisher>(),
40+
MefTestHelpers.CreateExport<ILogger>(),
41+
MefTestHelpers.CreateExport<IThreadHandling>());
42+
}
4743

48-
[TestMethod]
49-
public void Create_ReturnsCorrectType()
50-
{
51-
var testSubject = CreateTestSubject();
44+
[TestMethod]
45+
public void Create_ReturnsCorrectType()
46+
{
47+
var testSubject = CreateTestSubject();
5248

53-
var sseSession = testSubject.Create("MyProjectName", null);
49+
var sseSession = testSubject.Create("MyProjectName", null);
5450

55-
sseSession.Should().NotBeNull().And.BeOfType<SSESessionFactory.SSESession>();
56-
}
51+
sseSession.Should().NotBeNull().And.BeOfType<SSESessionFactory.SSESession>();
52+
}
5753

58-
[TestMethod]
59-
public void Create_AfterDispose_Throws()
60-
{
61-
var testSubject = CreateTestSubject();
54+
[TestMethod]
55+
public void Create_AfterDispose_Throws()
56+
{
57+
var testSubject = CreateTestSubject();
6258

63-
testSubject.Dispose();
64-
Action act = () => testSubject.Create("MyProjectName", null);
59+
testSubject.Dispose();
60+
Action act = () => testSubject.Create("MyProjectName", null);
6561

66-
act.Should().Throw<ObjectDisposedException>();
67-
}
62+
act.Should().Throw<ObjectDisposedException>();
63+
}
6864

69-
[TestMethod]
70-
public void Dispose_IdempotentAndDisposesPublishers()
71-
{
72-
var taintPublisherMock = new Mock<ITaintServerEventSourcePublisher>();
73-
var issuesPublisherMock = new Mock<IIssueServerEventSourcePublisher>();
74-
var qualityProfilePublisherMock = new Mock<IQualityProfileServerEventSourcePublisher>();
75-
var testSubject = CreateTestSubject(taintPublisherMock, issuesPublisherMock, qualityProfilePublisherMock);
65+
[TestMethod]
66+
public void Dispose_IdempotentAndDisposesPublishers()
67+
{
68+
var issuesPublisherMock = new Mock<IIssueServerEventSourcePublisher>();
69+
var qualityProfilePublisherMock = new Mock<IQualityProfileServerEventSourcePublisher>();
70+
var testSubject = CreateTestSubject(issuesPublisherMock, qualityProfilePublisherMock);
7671

77-
testSubject.Dispose();
78-
testSubject.Dispose();
79-
testSubject.Dispose();
72+
testSubject.Dispose();
73+
testSubject.Dispose();
74+
testSubject.Dispose();
8075

81-
taintPublisherMock.Verify(p => p.Dispose(), Times.Once);
82-
issuesPublisherMock.Verify(p => p.Dispose(), Times.Once);
83-
qualityProfilePublisherMock.Verify(p => p.Dispose(), Times.Once);
84-
}
76+
issuesPublisherMock.Verify(p => p.Dispose(), Times.Once);
77+
qualityProfilePublisherMock.Verify(p => p.Dispose(), Times.Once);
78+
}
8579

86-
private SSESessionFactory CreateTestSubject(Mock<ITaintServerEventSourcePublisher> taintPublisher = null,
87-
Mock<IIssueServerEventSourcePublisher> issuePublisher = null,
88-
Mock<IQualityProfileServerEventSourcePublisher> qualityProfileServerEventSourcePublisher = null)
89-
{
90-
return new SSESessionFactory(Mock.Of<ISonarQubeService>(),
91-
taintPublisher?.Object ?? Mock.Of<ITaintServerEventSourcePublisher>(),
92-
issuePublisher?.Object ?? Mock.Of<IIssueServerEventSourcePublisher>(),
93-
qualityProfileServerEventSourcePublisher?.Object ?? Mock.Of<IQualityProfileServerEventSourcePublisher>(),
80+
private SSESessionFactory CreateTestSubject(Mock<IIssueServerEventSourcePublisher> issuePublisher = null,
81+
Mock<IQualityProfileServerEventSourcePublisher> qualityProfileServerEventSourcePublisher = null) =>
82+
new(Mock.Of<ISonarQubeService>(),
83+
issuePublisher?.Object ?? Mock.Of<IIssueServerEventSourcePublisher>(),
84+
qualityProfileServerEventSourcePublisher?.Object ?? Mock.Of<IQualityProfileServerEventSourcePublisher>(),
9485
Mock.Of<IThreadHandling>(),
95-
Mock.Of<ILogger>());
96-
}
97-
}
86+
Mock.Of<ILogger>());
9887
}

src/ConnectedMode.UnitTests/ServerSentEvents/SSESessionTests.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,12 @@
1818
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
2020

21-
22-
using System;
23-
using System.Collections.Generic;
24-
using System.Linq;
25-
using System.Threading;
26-
using System.Threading.Tasks;
2721
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents;
2822
using SonarLint.VisualStudio.Core;
2923
using SonarLint.VisualStudio.TestInfrastructure;
3024
using SonarQube.Client;
3125
using SonarQube.Client.Models.ServerSentEvents;
3226
using SonarQube.Client.Models.ServerSentEvents.ClientContract;
33-
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.Taint;
3427
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.Issue;
3528
using SonarLint.VisualStudio.ConnectedMode.ServerSentEvents.QualityProfile;
3629

@@ -62,22 +55,17 @@ public async Task PumpAllAsync_SelectsPublisherCorrectlyAndPreservesOrderWithinT
6255
var inputSequence = new IServerEvent[]
6356
{
6457
Mock.Of<IIssueChangedServerEvent>(),
65-
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
6658
Mock.Of<IQualityProfileEvent>(),
6759
Mock.Of<IIssueChangedServerEvent>(),
68-
Mock.Of<ITaintVulnerabilityClosedServerEvent>(),
69-
Mock.Of<ITaintVulnerabilityClosedServerEvent>(),
7060
Mock.Of<IQualityProfileEvent>(),
7161
Mock.Of<IIssueChangedServerEvent>(),
72-
Mock.Of<ITaintVulnerabilityRaisedServerEvent>()
7362
};
7463
testScope.SetUpSwitchToBackgroundThread();
7564
var sseStreamMock = testScope.SetUpSQServiceToSuccessfullyReturnSSEStreamReader();
7665
testScope.SetUpSSEStreamReaderToReturnEventsSequenceAndExit(sseStreamMock, inputSequence);
7766

7867
await testScope.TestSubject.PumpAllAsync();
7968

80-
CheckEventsSequence<ITaintServerEvent>(testScope.TaintPublisherMock.Invocations);
8169
CheckEventsSequence<IIssueChangedServerEvent>(testScope.IssuePublisherMock.Invocations);
8270
CheckEventsSequence<IQualityProfileEvent>(testScope.QualityProfilePublisherMock.Invocations);
8371

@@ -100,18 +88,15 @@ public async Task PumpAllAsync_WhenNullEvent_Ignores()
10088
testScope.SetUpSSEStreamReaderToReturnEventsSequenceAndExit(sseStreamMock,
10189
new IServerEvent[]
10290
{
103-
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
10491
Mock.Of<IQualityProfileEvent>(),
10592
null,
106-
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
10793
Mock.Of<IIssueChangedServerEvent>(),
10894
Mock.Of<IQualityProfileEvent>(),
10995
Mock.Of<IIssueChangedServerEvent>()
11096
});
11197

11298
await testScope.TestSubject.PumpAllAsync();
11399

114-
testScope.TaintPublisherMock.Verify(publisher => publisher.Publish(It.IsAny<ITaintServerEvent>()), Times.Exactly(2));
115100
testScope.IssuePublisherMock.Verify(publisher => publisher.Publish(It.IsAny<IIssueChangedServerEvent>()), Times.Exactly(2));
116101
testScope.QualityProfilePublisherMock.Verify(publisher => publisher.Publish(It.IsAny<IQualityProfileEvent>()), Times.Exactly(2));
117102
}
@@ -126,16 +111,13 @@ public async Task PumpAllAsync_WhenUnsupportedEvent_Ignores()
126111
testScope.SetUpSSEStreamReaderToReturnEventsSequenceAndExit(sseStreamMock,
127112
new IServerEvent[]
128113
{
129-
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
130114
Mock.Of<IQualityProfileEvent>(),
131115
Mock.Of<IDummyServerEvent>(),
132-
Mock.Of<ITaintVulnerabilityRaisedServerEvent>(),
133116
Mock.Of<IIssueChangedServerEvent>()
134117
});
135118

136119
await testScope.TestSubject.PumpAllAsync();
137120

138-
testScope.TaintPublisherMock.Verify(publisher => publisher.Publish(It.IsAny<ITaintServerEvent>()), Times.Exactly(2));
139121
testScope.IssuePublisherMock.Verify(publisher => publisher.Publish(It.IsAny<IIssueChangedServerEvent>()), Times.Exactly(1));
140122
testScope.QualityProfilePublisherMock.Verify(publisher => publisher.Publish(It.IsAny<IQualityProfileEvent>()), Times.Exactly(1));
141123
}
@@ -232,7 +214,6 @@ public TestScope()
232214
{
233215
mockRepository = new MockRepository(MockBehavior.Strict);
234216
SonarQubeServiceMock = mockRepository.Create<ISonarQubeService>();
235-
TaintPublisherMock = mockRepository.Create<ITaintServerEventSourcePublisher>(MockBehavior.Loose);
236217
IssuePublisherMock = mockRepository.Create<IIssueServerEventSourcePublisher>(MockBehavior.Loose);
237218
QualityProfilePublisherMock = mockRepository.Create<IQualityProfileServerEventSourcePublisher>(MockBehavior.Loose);
238219
ThreadHandlingMock = mockRepository.Create<IThreadHandling>();
@@ -241,18 +222,16 @@ public TestScope()
241222

242223
var factory = new SSESessionFactory(
243224
SonarQubeServiceMock.Object,
244-
TaintPublisherMock.Object,
245225
IssuePublisherMock.Object,
246226
QualityProfilePublisherMock.Object,
247227
ThreadHandlingMock.Object,
248228
LoggerMock.Object);
249229

250230
TestSubject = factory.Create("blalala", OnSessionFailedAsyncMock.Object);
251231
}
252-
232+
253233
private Mock<IThreadHandling> ThreadHandlingMock { get; }
254234
public Mock<ISonarQubeService> SonarQubeServiceMock { get; }
255-
public Mock<ITaintServerEventSourcePublisher> TaintPublisherMock { get; }
256235
public Mock<IIssueServerEventSourcePublisher> IssuePublisherMock { get; }
257236
public Mock<IQualityProfileServerEventSourcePublisher> QualityProfilePublisherMock { get; }
258237
public Mock<ILogger> LoggerMock { get; }

0 commit comments

Comments
 (0)