22
22
using System . IO ;
23
23
using SonarLint . VisualStudio . ConnectedMode . UI ;
24
24
using SonarLint . VisualStudio . ConnectedMode . UI . Credentials ;
25
+ using SonarLint . VisualStudio . ConnectedMode . UI . OrganizationSelection ;
25
26
using SonarLint . VisualStudio . ConnectedMode . UI . Resources ;
26
27
using SonarLint . VisualStudio . SLCore . Service . Connection ;
27
28
@@ -275,26 +276,26 @@ public void AccountSecurityUrl_ConnectionIsSonarQube_ReturnsSonarQubeUrl()
275
276
}
276
277
277
278
[ TestMethod ]
278
- public async Task ValidateConnectionAsync_TokenIsProvided_ShouldValidateConnectionWithToken ( )
279
+ public async Task AdapterValidateConnectionAsync_TokenIsProvided_ShouldValidateConnectionWithToken ( )
279
280
{
280
281
MockAdapterValidateConnectionAsync ( ) ;
281
282
testSubject . SelectedAuthenticationType = UiResources . AuthenticationTypeOptionToken ;
282
283
testSubject . Token = "dummyToken" ;
283
284
284
- await testSubject . ValidateConnectionAsync ( ) ;
285
+ await testSubject . AdapterValidateConnectionAsync ( ) ;
285
286
286
287
await slCoreConnectionAdapter . Received ( 1 ) . ValidateConnectionAsync ( testSubject . ConnectionInfo , testSubject . Token ) ;
287
288
}
288
289
289
290
[ TestMethod ]
290
- public async Task ValidateConnectionAsync_CredentialsAreProvided_ShouldValidateConnectionWithToken ( )
291
+ public async Task AdapterValidateConnectionAsync_CredentialsAreProvided_ShouldValidateConnectionWithToken ( )
291
292
{
292
293
MockAdapterValidateConnectionAsync ( ) ;
293
294
testSubject . SelectedAuthenticationType = UiResources . AuthenticationTypeOptionCredentials ;
294
295
testSubject . Username = "username" ;
295
296
testSubject . Password = "password" ;
296
297
297
- await testSubject . ValidateConnectionAsync ( ) ;
298
+ await testSubject . AdapterValidateConnectionAsync ( ) ;
298
299
299
300
await slCoreConnectionAdapter . Received ( 1 ) . ValidateConnectionAsync ( testSubject . ConnectionInfo , testSubject . Username , testSubject . Password ) ;
300
301
}
@@ -304,74 +305,24 @@ public async Task ValidateConnectionAsync_CredentialsAreProvided_ShouldValidateC
304
305
[ DataRow ( false ) ]
305
306
public async Task ValidateConnectionAsync_ReturnsResponseFromSlCore ( bool success )
306
307
{
307
- MockAdapterValidateConnectionAsync ( success ) ;
308
+ progressReporterViewModel . ExecuteTaskWithProgressAsync ( Arg . Any < TaskToPerformParams < AdapterResponse > > ( ) ) . Returns ( new AdapterResponse ( success ) ) ;
308
309
309
310
var response = await testSubject . ValidateConnectionAsync ( ) ;
310
311
311
312
response . Should ( ) . Be ( success ) ;
312
313
}
313
314
314
315
[ TestMethod ]
315
- public async Task ValidateConnectionAsync_UpdatesProgress ( )
316
- {
317
- MockAdapterValidateConnectionAsync ( ) ;
318
-
319
- await testSubject . ValidateConnectionAsync ( ) ;
320
-
321
- Received . InOrder ( ( ) =>
322
- {
323
- progressReporterViewModel . ProgressStatus = UiResources . ValidatingConnectionProgressText ;
324
- slCoreConnectionAdapter . ValidateConnectionAsync ( Arg . Any < ConnectionInfo > ( ) , Arg . Any < string > ( ) ) ;
325
- progressReporterViewModel . ProgressStatus = null ;
326
- } ) ;
327
- }
328
-
329
- [ TestMethod ]
330
- public async Task ValidateConnectionAsync_AdapterValidationThrowsException_SetsProgressToNull ( )
331
- {
332
- testSubject . ProgressReporterViewModel . ProgressStatus . Returns ( UiResources . ValidatingConnectionProgressText ) ;
333
-
334
- await RunAdapterValidationThrowingException ( ) ;
335
-
336
- testSubject . ProgressReporterViewModel . Received ( 1 ) . ProgressStatus = null ;
337
- }
338
-
339
- [ TestMethod ]
340
- public async Task ValidateConnectionAsync_AdapterValidationFails_UpdatesWarning ( )
341
- {
342
- var warning = "wrong credentials" ;
343
- MockAdapterValidateConnectionAsync ( success : false , message : warning ) ;
344
-
345
- await testSubject . ValidateConnectionAsync ( ) ;
346
-
347
- progressReporterViewModel . Received ( 1 ) . Warning = warning ;
348
- }
349
-
350
- [ TestMethod ]
351
- public async Task ValidateConnectionAsync_AdapterValidationSucceeds_DoesNotUpdateWarning ( )
316
+ public async Task ValidateConnectionAsync_ReturnsResponseFromSlCore ( )
352
317
{
353
- var warning = "correct credentials" ;
354
- MockAdapterValidateConnectionAsync ( success : true , message : warning ) ;
355
-
356
318
await testSubject . ValidateConnectionAsync ( ) ;
357
319
358
- progressReporterViewModel . DidNotReceive ( ) . Warning = warning ;
359
- }
360
-
361
- [ TestMethod ]
362
- public async Task ValidateConnectionAsync_ResetsPreviousWarningBeforeValidation ( )
363
- {
364
- var warning = "correct credentials" ;
365
- MockAdapterValidateConnectionAsync ( success : false , message : warning ) ;
366
-
367
- await testSubject . ValidateConnectionAsync ( ) ;
368
-
369
- Received . InOrder ( ( ) =>
370
- {
371
- progressReporterViewModel . Warning = null ;
372
- slCoreConnectionAdapter . ValidateConnectionAsync ( Arg . Any < ConnectionInfo > ( ) , Arg . Any < string > ( ) ) ;
373
- progressReporterViewModel . Warning = warning ;
374
- } ) ;
320
+ await progressReporterViewModel . Received ( 1 )
321
+ . ExecuteTaskWithProgressAsync ( Arg . Is < TaskToPerformParams < AdapterResponse > > ( x =>
322
+ x . TaskToPerform == testSubject . AdapterValidateConnectionAsync &&
323
+ x . ProgressStatus == UiResources . ValidatingConnectionProgressText &&
324
+ x . WarningText == UiResources . ValidatingConnectionFailedText &&
325
+ x . AfterProgressUpdated == testSubject . AfterProgressStatusUpdated ) ) ;
375
326
}
376
327
377
328
[ TestMethod ]
@@ -381,7 +332,7 @@ public void UpdateProgressStatus_RaisesEvents()
381
332
testSubject . PropertyChanged += eventHandler ;
382
333
eventHandler . ReceivedCalls ( ) . Should ( ) . BeEmpty ( ) ;
383
334
384
- testSubject . UpdateProgressStatus ( null ) ;
335
+ testSubject . AfterProgressStatusUpdated ( ) ;
385
336
386
337
eventHandler . Received ( ) . Invoke ( testSubject , Arg . Is < PropertyChangedEventArgs > ( x => x . PropertyName == nameof ( testSubject . IsConfirmationEnabled ) ) ) ;
387
338
}
@@ -415,26 +366,12 @@ public void GetCredentialsModel_SelectedAuthenticationTypeIsCredentials_ReturnsM
415
366
( ( UsernamePasswordModel ) credentialsModel ) . Password . Should ( ) . Be ( testSubject . Password ) ;
416
367
}
417
368
418
- private void MockAdapterValidateConnectionAsync ( bool success = true , string message = null )
369
+ private void MockAdapterValidateConnectionAsync ( bool success = true )
419
370
{
420
371
slCoreConnectionAdapter . ValidateConnectionAsync ( Arg . Any < ConnectionInfo > ( ) , Arg . Any < string > ( ) )
421
- . Returns ( new ValidateConnectionResponse ( success , message ) ) ;
372
+ . Returns ( new AdapterResponse ( success ) ) ;
422
373
slCoreConnectionAdapter . ValidateConnectionAsync ( Arg . Any < ConnectionInfo > ( ) , Arg . Any < string > ( ) , Arg . Any < string > ( ) )
423
- . Returns ( new ValidateConnectionResponse ( success , message ) ) ;
424
- }
425
-
426
- private async Task RunAdapterValidationThrowingException ( )
427
- {
428
- slCoreConnectionAdapter . When ( x => x . ValidateConnectionAsync ( Arg . Any < ConnectionInfo > ( ) , Arg . Any < string > ( ) ) )
429
- . Do ( x => throw new Exception ( "testing" ) ) ;
430
- try
431
- {
432
- await testSubject . ValidateConnectionAsync ( ) ;
433
- }
434
- catch ( Exception )
435
- {
436
- // this is only for testing purposes
437
- }
374
+ . Returns ( new AdapterResponse ( success ) ) ;
438
375
}
439
376
}
440
377
}
0 commit comments