18
18
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
*/
20
20
21
+ using System . ComponentModel ;
21
22
using SonarLint . VisualStudio . Core ;
22
23
using SonarLint . VisualStudio . Core . Synchronization ;
23
24
using SonarLint . VisualStudio . SLCore . Core ;
@@ -38,6 +39,7 @@ public class ActiveConfigScopeTrackerTests
38
39
private ISLCoreServiceProvider serviceProvider ;
39
40
private IAsyncLockFactory asyncLockFactory ;
40
41
private IThreadHandling threadHandling ;
42
+ private EventHandler currentConfigScopeChangedEventHandler ;
41
43
42
44
[ TestInitialize ]
43
45
public void TestInitialize ( )
@@ -50,8 +52,10 @@ public void TestInitialize()
50
52
threadHandling = Substitute . For < IThreadHandling > ( ) ;
51
53
ConfigureServiceProvider ( isServiceAvailable : true ) ;
52
54
ConfigureAsyncLockFactory ( ) ;
55
+ currentConfigScopeChangedEventHandler = Substitute . For < EventHandler > ( ) ;
53
56
54
57
testSubject = new ActiveConfigScopeTracker ( serviceProvider , asyncLockFactory , threadHandling ) ;
58
+ testSubject . CurrentConfigurationScopeChanged += currentConfigScopeChangedEventHandler ;
55
59
}
56
60
57
61
[ TestMethod ]
@@ -80,6 +84,7 @@ public void SetCurrentConfigScope_SetsUnboundScope()
80
84
VerifyThreadHandling ( ) ;
81
85
VerifyServiceAddCall ( ) ;
82
86
VerifyLockTakenSynchronouslyAndReleased ( ) ;
87
+ VerifyCurrentConfigurationScopeChangedRaised ( ) ;
83
88
}
84
89
85
90
[ TestMethod ]
@@ -95,6 +100,7 @@ public void TryUpdateRootOnCurrentConfigScope_ConfigScopeSame_Updates()
95
100
96
101
result . Should ( ) . BeTrue ( ) ;
97
102
testSubject . currentConfigScope . Should ( ) . BeEquivalentTo ( new ConfigurationScope ( configScopeId , connectionId , sonarProjectKey , "some root" , isReady ) ) ;
103
+ VerifyCurrentConfigurationScopeChangedRaised ( ) ;
98
104
}
99
105
100
106
[ TestMethod ]
@@ -110,6 +116,7 @@ public void TryUpdateRootOnCurrentConfigScope_ConfigScopeDifferent_DoesNotUpdate
110
116
111
117
result . Should ( ) . BeFalse ( ) ;
112
118
testSubject . currentConfigScope . Should ( ) . BeEquivalentTo ( new ConfigurationScope ( configScopeId , connectionId , sonarProjectKey , isReadyForAnalysis : isReady ) ) ;
119
+ VerifyCurrentConfigurationScopeChangedNotRaised ( ) ;
113
120
}
114
121
115
122
[ TestMethod ]
@@ -125,6 +132,7 @@ public void TryUpdateAnalysisReadinessOnCurrentConfigScope_ConfigScopeSame_Updat
125
132
126
133
result . Should ( ) . BeTrue ( ) ;
127
134
testSubject . currentConfigScope . Should ( ) . BeEquivalentTo ( new ConfigurationScope ( configScopeId , connectionId , sonarProjectKey , root , true ) ) ;
135
+ VerifyCurrentConfigurationScopeChangedRaised ( ) ;
128
136
}
129
137
130
138
[ TestMethod ]
@@ -140,6 +148,7 @@ public void TryUpdateAnalysisReadinessOnCurrentConfigScope_ConfigScopeDifferent_
140
148
141
149
result . Should ( ) . BeFalse ( ) ;
142
150
testSubject . currentConfigScope . Should ( ) . BeEquivalentTo ( new ConfigurationScope ( configScopeId , connectionId , sonarProjectKey , root ) ) ;
151
+ VerifyCurrentConfigurationScopeChangedNotRaised ( ) ;
143
152
}
144
153
145
154
[ TestMethod ]
@@ -155,6 +164,7 @@ public void SetCurrentConfigScope_SetsBoundScope()
155
164
VerifyThreadHandling ( ) ;
156
165
VerifyServiceAddCall ( ) ;
157
166
VerifyLockTakenSynchronouslyAndReleased ( ) ;
167
+ VerifyCurrentConfigurationScopeChangedRaised ( ) ;
158
168
}
159
169
160
170
[ TestMethod ]
@@ -174,6 +184,7 @@ public void SetCurrentConfigScope_CurrentScopeExists_UpdatesBoundScope()
174
184
VerifyThreadHandling ( ) ;
175
185
VerifyServiceUpdateCall ( ) ;
176
186
VerifyLockTakenSynchronouslyAndReleased ( ) ;
187
+ VerifyCurrentConfigurationScopeChangedRaised ( ) ;
177
188
}
178
189
179
190
[ TestMethod ]
@@ -185,6 +196,7 @@ public void SetCurrentConfigScope_ServiceUnavailable_Throws()
185
196
186
197
act . Should ( ) . ThrowExactly < InvalidOperationException > ( ) . WithMessage ( SLCoreStrings . ServiceProviderNotInitialized ) ;
187
198
VerifyThreadHandling ( ) ;
199
+ VerifyCurrentConfigurationScopeChangedNotRaised ( ) ;
188
200
}
189
201
190
202
[ TestMethod ]
@@ -199,6 +211,7 @@ public void SetCurrentConfigScope_UpdateConfigScopeWithDifferentId_Throws()
199
211
200
212
act . Should ( ) . ThrowExactly < InvalidOperationException > ( ) . WithMessage ( SLCoreStrings . ConfigScopeConflict ) ;
201
213
VerifyThreadHandling ( ) ;
214
+ VerifyCurrentConfigurationScopeChangedNotRaised ( ) ;
202
215
}
203
216
204
217
[ TestMethod ]
@@ -212,6 +225,7 @@ public void RemoveCurrentConfigScope_RemovesScope()
212
225
configScopeService . Received ( ) . DidRemoveConfigurationScope ( Arg . Is < DidRemoveConfigurationScopeParams > ( p => p . removedId == configScopeId ) ) ;
213
226
VerifyThreadHandling ( ) ;
214
227
VerifyLockTakenSynchronouslyAndReleased ( ) ;
228
+ VerifyCurrentConfigurationScopeChangedRaised ( ) ;
215
229
}
216
230
217
231
[ TestMethod ]
@@ -222,6 +236,7 @@ public void RemoveCurrentConfigScope_NoCurrentScope_DoesNothing()
222
236
configScopeService . ReceivedCalls ( ) . Count ( ) . Should ( ) . Be ( 0 ) ;
223
237
VerifyThreadHandling ( ) ;
224
238
VerifyLockTakenSynchronouslyAndReleased ( ) ;
239
+ VerifyCurrentConfigurationScopeChangedNotRaised ( ) ;
225
240
}
226
241
227
242
[ TestMethod ]
@@ -234,6 +249,7 @@ public void RemoveCurrentConfigScope_ServiceUnavailable_Throws()
234
249
235
250
act . Should ( ) . ThrowExactly < InvalidOperationException > ( ) . WithMessage ( SLCoreStrings . ServiceProviderNotInitialized ) ;
236
251
VerifyThreadHandling ( ) ;
252
+ VerifyCurrentConfigurationScopeChangedNotRaised ( ) ;
237
253
}
238
254
239
255
[ TestMethod ]
@@ -279,6 +295,7 @@ public void Reset_SetsCurrentScopeToNull()
279
295
serviceProvider . ReceivedCalls ( ) . Count ( ) . Should ( ) . Be ( 0 ) ;
280
296
VerifyThreadHandling ( ) ;
281
297
VerifyLockTakenSynchronouslyAndReleased ( ) ;
298
+ VerifyCurrentConfigurationScopeChangedRaised ( ) ;
282
299
}
283
300
284
301
[ TestMethod ]
@@ -335,6 +352,16 @@ private void ConfigureServiceProvider(bool isServiceAvailable)
335
352
} ) ;
336
353
}
337
354
355
+ private void VerifyCurrentConfigurationScopeChangedRaised ( )
356
+ {
357
+ currentConfigScopeChangedEventHandler . Received ( 1 ) . Invoke ( testSubject , Arg . Any < EventArgs > ( ) ) ;
358
+ }
359
+
360
+ private void VerifyCurrentConfigurationScopeChangedNotRaised ( )
361
+ {
362
+ currentConfigScopeChangedEventHandler . DidNotReceive ( ) . Invoke ( testSubject , Arg . Any < EventArgs > ( ) ) ;
363
+ }
364
+
338
365
private class ConfigurationScopeDtoComparer : IEqualityComparer < ConfigurationScopeDto >
339
366
{
340
367
public bool Equals ( ConfigurationScopeDto x , ConfigurationScopeDto y )
0 commit comments