@@ -18,12 +18,18 @@ import { AccountSignInTreeNode } from "../../src/objectExplorer/accountSignInTre
18
18
import { ConnectTreeNode } from "../../src/objectExplorer/connectTreeNode" ;
19
19
import { NodeInfo } from "../../src/models/contracts/objectExplorer/nodeInfo" ;
20
20
import { Deferred } from "../../src/protocol" ;
21
+ import {
22
+ ExpandParams ,
23
+ ExpandResponse ,
24
+ } from "../../src/models/contracts/objectExplorer/expandNodeRequest" ;
25
+ import VscodeWrapper from "../../src/controllers/vscodeWrapper" ;
21
26
22
- suite ( "Object Explorer Provider Tests" , ( ) => {
27
+ suite ( "Object Explorer Provider Tests" , function ( ) {
23
28
let objectExplorerService : TypeMoq . IMock < ObjectExplorerService > ;
24
29
let connectionManager : TypeMoq . IMock < ConnectionManager > ;
25
30
let client : TypeMoq . IMock < SqlToolsServiceClient > ;
26
31
let objectExplorerProvider : ObjectExplorerProvider ;
32
+ let vscodeWrapper : TypeMoq . IMock < VscodeWrapper > ;
27
33
28
34
setup ( ( ) => {
29
35
let mockContext : TypeMoq . IMock < vscode . ExtensionContext > =
@@ -42,13 +48,29 @@ suite("Object Explorer Provider Tests", () => {
42
48
c . onNotification ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) ,
43
49
) ;
44
50
connectionManager . object . client = client . object ;
51
+
52
+ vscodeWrapper = TypeMoq . Mock . ofType (
53
+ VscodeWrapper ,
54
+ TypeMoq . MockBehavior . Loose ,
55
+ ) ;
56
+
57
+ vscodeWrapper . setup ( ( v ) =>
58
+ v . showErrorMessage ( TypeMoq . It . isAnyString ( ) ) ,
59
+ ) ;
60
+
61
+ connectionManager
62
+ . setup ( ( c ) => c . vscodeWrapper )
63
+ . returns ( ( ) => vscodeWrapper . object ) ;
64
+ connectionManager . object . vscodeWrapper = vscodeWrapper . object ;
65
+
45
66
objectExplorerProvider = new ObjectExplorerProvider (
46
67
connectionManager . object ,
47
68
) ;
48
69
expect (
49
70
objectExplorerProvider ,
50
71
"Object Explorer Provider is initialzied properly" ,
51
72
) . is . not . equal ( undefined ) ;
73
+
52
74
objectExplorerService = TypeMoq . Mock . ofType (
53
75
ObjectExplorerService ,
54
76
TypeMoq . MockBehavior . Loose ,
@@ -334,6 +356,146 @@ suite("Object Explorer Provider Tests", () => {
334
356
assert . equal ( treeItem , node ) ;
335
357
} ) ;
336
358
359
+ const mockParentTreeNode = new TreeNodeInfo (
360
+ "Parent Node" ,
361
+ undefined ,
362
+ undefined ,
363
+ "parentNodePath" ,
364
+ undefined ,
365
+ undefined ,
366
+ undefined ,
367
+ undefined ,
368
+ undefined ,
369
+ undefined ,
370
+ ) ;
371
+
372
+ test ( "Test handleExpandSessionNotification returns child nodes upon success" , async function ( ) {
373
+ const childNodeInfo : NodeInfo = {
374
+ nodePath : `${ mockParentTreeNode . nodePath } /childNodePath` ,
375
+ nodeStatus : undefined ,
376
+ nodeSubType : undefined ,
377
+ nodeType : undefined ,
378
+ label : "Child Node" ,
379
+ isLeaf : true ,
380
+ errorMessage : undefined ,
381
+ metadata : undefined ,
382
+ } ;
383
+
384
+ const mockExpandResponse : ExpandResponse = {
385
+ sessionId : "test_session" ,
386
+ nodePath : mockParentTreeNode . nodePath ,
387
+ nodes : [ childNodeInfo ] ,
388
+ errorMessage : undefined ,
389
+ } ;
390
+
391
+ const testOeService = new ObjectExplorerService (
392
+ connectionManager . object ,
393
+ objectExplorerProvider ,
394
+ ) ;
395
+
396
+ let notificationObject =
397
+ testOeService . handleExpandSessionNotification ( ) ;
398
+
399
+ const expandParams : ExpandParams = {
400
+ sessionId : mockExpandResponse . sessionId ,
401
+ nodePath : mockExpandResponse . nodePath ,
402
+ } ;
403
+
404
+ testOeService [ "_expandParamsToTreeNodeInfoMap" ] . set (
405
+ expandParams ,
406
+ mockParentTreeNode ,
407
+ ) ;
408
+
409
+ testOeService [ "_sessionIdToConnectionCredentialsMap" ] . set (
410
+ mockExpandResponse . sessionId ,
411
+ undefined ,
412
+ ) ;
413
+
414
+ const outputPromise = new Deferred < TreeNodeInfo [ ] > ( ) ;
415
+
416
+ testOeService [ "_expandParamsToPromiseMap" ] . set (
417
+ expandParams ,
418
+ outputPromise ,
419
+ ) ;
420
+
421
+ notificationObject . call ( testOeService , mockExpandResponse ) ;
422
+
423
+ const childNodes = await outputPromise ;
424
+ assert . equal ( childNodes . length , 1 , "Child nodes length" ) ;
425
+ assert . equal (
426
+ childNodes [ 0 ] . label ,
427
+ childNodeInfo . label ,
428
+ "Child node label" ,
429
+ ) ;
430
+ assert . equal (
431
+ childNodes [ 0 ] . nodePath ,
432
+ childNodeInfo . nodePath ,
433
+ "Child node path" ,
434
+ ) ;
435
+ } ) ;
436
+
437
+ test ( "Test handleExpandSessionNotification returns message node upon failure" , async function ( ) {
438
+ this . timeout ( 0 ) ;
439
+
440
+ const mockExpandResponse : ExpandResponse = {
441
+ sessionId : "test_session" ,
442
+ nodePath : mockParentTreeNode . nodePath ,
443
+ nodes : [ ] ,
444
+ errorMessage : "Error occurred when expanding node" ,
445
+ } ;
446
+
447
+ const testOeService = new ObjectExplorerService (
448
+ connectionManager . object ,
449
+ objectExplorerProvider ,
450
+ ) ;
451
+
452
+ let notificationObject =
453
+ testOeService . handleExpandSessionNotification ( ) ;
454
+
455
+ const expandParams : ExpandParams = {
456
+ sessionId : mockExpandResponse . sessionId ,
457
+ nodePath : mockExpandResponse . nodePath ,
458
+ } ;
459
+
460
+ testOeService [ "_expandParamsToTreeNodeInfoMap" ] . set (
461
+ expandParams ,
462
+ mockParentTreeNode ,
463
+ ) ;
464
+
465
+ testOeService [ "_sessionIdToConnectionCredentialsMap" ] . set (
466
+ mockExpandResponse . sessionId ,
467
+ undefined ,
468
+ ) ;
469
+
470
+ const outputPromise = new Deferred < TreeNodeInfo [ ] > ( ) ;
471
+
472
+ testOeService [ "_expandParamsToPromiseMap" ] . set (
473
+ expandParams ,
474
+ outputPromise ,
475
+ ) ;
476
+
477
+ notificationObject . call ( testOeService , mockExpandResponse ) ;
478
+
479
+ const childNodes = await outputPromise ;
480
+
481
+ vscodeWrapper . verify (
482
+ ( x ) => x . showErrorMessage ( mockExpandResponse . errorMessage ) ,
483
+ TypeMoq . Times . once ( ) ,
484
+ ) ;
485
+
486
+ assert . equal ( childNodes . length , 1 , "Child nodes length" ) ;
487
+ assert . equal (
488
+ childNodes [ 0 ] . label ,
489
+ "Error loading; refresh to try again" ,
490
+ "Error node label" ,
491
+ ) ;
492
+ assert . equal (
493
+ childNodes [ 0 ] . tooltip ,
494
+ mockExpandResponse . errorMessage ,
495
+ "Error node tooltip" ,
496
+ ) ;
497
+ } ) ;
498
+
337
499
test ( "Test signInNode function" , ( ) => {
338
500
objectExplorerService . setup ( ( s ) =>
339
501
s . signInNodeServer ( TypeMoq . It . isAny ( ) ) ,
0 commit comments