@@ -429,6 +429,163 @@ public void UpdateFromFile_ModuleThere_RemovesMatchingComponent()
429
429
}
430
430
}
431
431
432
+ [ Category ( "Code Explorer" ) ]
433
+ [ Test ]
434
+ public void UpdateFromFile_MultipleImports_DifferentNames ( )
435
+ {
436
+ const string path1 = @"C:\Users\Rubberduck\Desktop\StdModule1.bas" ;
437
+ const string path2 = @"C:\Users\Rubberduck\Desktop\Class1.cls" ;
438
+ const string path3 = @"C:\Users\Rubberduck\Desktop\StdModule2.bas" ;
439
+ const string path4 = @"C:\Users\Rubberduck\Desktop\Class2.cls" ;
440
+
441
+ using ( var explorer = new MockedCodeExplorer (
442
+ ProjectType . HostProject ,
443
+ ( "TestModule" , ComponentType . StandardModule , string . Empty ) ,
444
+ ( "OtherTestModule" , ComponentType . StandardModule , string . Empty ) ,
445
+ ( "TestClass" , ComponentType . ClassModule , string . Empty ) )
446
+ . ConfigureOpenDialog ( new [ ] { path1 , path2 , path3 , path4 } , DialogResult . OK )
447
+ . SelectFirstProject ( ) )
448
+ {
449
+ explorer . ExecuteUpdateFromFileCommand ( filename =>
450
+ {
451
+ switch ( filename )
452
+ {
453
+ case path1 :
454
+ return "TestModule" ;
455
+ case path2 :
456
+ return "TestClass" ;
457
+ case path3 :
458
+ return "NewModule" ;
459
+ case path4 :
460
+ return "NewClass" ;
461
+ default :
462
+ return "YetAnotherModule" ;
463
+ }
464
+ } ) ;
465
+
466
+ var modulesNames = explorer
467
+ . VbComponents
468
+ . Object
469
+ . Select ( component => component . Name )
470
+ . ToList ( ) ;
471
+
472
+ explorer . VbComponents . Verify ( c => c . Remove ( It . IsAny < IVBComponent > ( ) ) , Times . Exactly ( 2 ) ) ;
473
+ explorer . VbComponents . Verify ( c => c . Import ( path1 ) , Times . Once ) ;
474
+ explorer . VbComponents . Verify ( c => c . Import ( path2 ) , Times . Once ) ;
475
+ explorer . VbComponents . Verify ( c => c . Import ( path3 ) , Times . Once ) ;
476
+ explorer . VbComponents . Verify ( c => c . Import ( path4 ) , Times . Once ) ;
477
+
478
+ Assert . IsTrue ( modulesNames . Contains ( "OtherTestModule" ) ) ;
479
+ //This depends on the setup of Import on the VBComponents mock, which determines the component name from the filename.
480
+ Assert . IsTrue ( modulesNames . Contains ( "StdModule1" ) ) ;
481
+ Assert . IsTrue ( modulesNames . Contains ( "Class1" ) ) ;
482
+ Assert . IsTrue ( modulesNames . Contains ( "StdModule2" ) ) ;
483
+ Assert . IsTrue ( modulesNames . Contains ( "Class2" ) ) ;
484
+ Assert . IsFalse ( modulesNames . Contains ( "TestModule" ) ) ;
485
+ Assert . IsFalse ( modulesNames . Contains ( "TestClass" ) ) ;
486
+ }
487
+ }
488
+
489
+ [ Category ( "Code Explorer" ) ]
490
+ [ Test ]
491
+ public void UpdateFromFile_MultipleImports_RepeatedModeuleName_Aborts ( )
492
+ {
493
+ const string path1 = @"C:\Users\Rubberduck\Desktop\StdModule1.bas" ;
494
+ const string path2 = @"C:\Users\Rubberduck\Desktop\Class1.cls" ;
495
+ const string path3 = @"C:\Users\Rubberduck\Desktop\StdModule2.bas" ;
496
+ const string path4 = @"C:\Users\Rubberduck\Desktop\Class2.cls" ;
497
+
498
+ using ( var explorer = new MockedCodeExplorer (
499
+ ProjectType . HostProject ,
500
+ ( "TestModule" , ComponentType . StandardModule , string . Empty ) ,
501
+ ( "OtherTestModule" , ComponentType . StandardModule , string . Empty ) ,
502
+ ( "TestClass" , ComponentType . ClassModule , string . Empty ) )
503
+ . ConfigureOpenDialog ( new [ ] { path1 , path2 , path3 , path4 } , DialogResult . OK )
504
+ . SelectFirstProject ( ) )
505
+ {
506
+ explorer . ExecuteUpdateFromFileCommand ( filename =>
507
+ {
508
+ switch ( filename )
509
+ {
510
+ case path1 :
511
+ return "TestModule" ;
512
+ case path2 :
513
+ return "TestClass" ;
514
+ case path3 :
515
+ return "TestModule" ;
516
+ case path4 :
517
+ return "NewClass" ;
518
+ default :
519
+ return "YetAnotherModule" ;
520
+ }
521
+ } ) ;
522
+
523
+ var modulesNames = explorer
524
+ . VbComponents
525
+ . Object
526
+ . Select ( component => component . Name )
527
+ . ToList ( ) ;
528
+
529
+ explorer . VbComponents . Verify ( c => c . Remove ( It . IsAny < IVBComponent > ( ) ) , Times . Never ) ;
530
+ explorer . VbComponents . Verify ( c => c . Import ( It . IsAny < string > ( ) ) , Times . Never ) ;
531
+
532
+ Assert . IsTrue ( modulesNames . Contains ( "OtherTestModule" ) ) ;
533
+ Assert . IsTrue ( modulesNames . Contains ( "TestModule" ) ) ;
534
+ Assert . IsTrue ( modulesNames . Contains ( "TestClass" ) ) ;
535
+ Assert . AreEqual ( 3 , modulesNames . Count ) ;
536
+ }
537
+ }
538
+
539
+ [ Category ( "Code Explorer" ) ]
540
+ [ Test ]
541
+ public void UpdateFromFile_NonMatchingComponentType_Aborts ( )
542
+ {
543
+ const string path1 = @"C:\Users\Rubberduck\Desktop\StdModule1.cls" ;
544
+ const string path2 = @"C:\Users\Rubberduck\Desktop\Class1.cls" ;
545
+ const string path3 = @"C:\Users\Rubberduck\Desktop\StdModule2.bas" ;
546
+ const string path4 = @"C:\Users\Rubberduck\Desktop\Class2.cls" ;
547
+
548
+ using ( var explorer = new MockedCodeExplorer (
549
+ ProjectType . HostProject ,
550
+ ( "TestModule" , ComponentType . StandardModule , string . Empty ) ,
551
+ ( "OtherTestModule" , ComponentType . StandardModule , string . Empty ) ,
552
+ ( "TestClass" , ComponentType . ClassModule , string . Empty ) )
553
+ . ConfigureOpenDialog ( new [ ] { path1 , path2 , path3 , path4 } , DialogResult . OK )
554
+ . SelectFirstProject ( ) )
555
+ {
556
+ explorer . ExecuteUpdateFromFileCommand ( filename =>
557
+ {
558
+ switch ( filename )
559
+ {
560
+ case path1 :
561
+ return "TestModule" ;
562
+ case path2 :
563
+ return "TestClass" ;
564
+ case path3 :
565
+ return "NewModule" ;
566
+ case path4 :
567
+ return "NewClass" ;
568
+ default :
569
+ return "YetAnotherModule" ;
570
+ }
571
+ } ) ;
572
+
573
+ var modulesNames = explorer
574
+ . VbComponents
575
+ . Object
576
+ . Select ( component => component . Name )
577
+ . ToList ( ) ;
578
+
579
+ explorer . VbComponents . Verify ( c => c . Remove ( It . IsAny < IVBComponent > ( ) ) , Times . Never ) ;
580
+ explorer . VbComponents . Verify ( c => c . Import ( It . IsAny < string > ( ) ) , Times . Never ) ;
581
+
582
+ Assert . IsTrue ( modulesNames . Contains ( "OtherTestModule" ) ) ;
583
+ Assert . IsTrue ( modulesNames . Contains ( "TestModule" ) ) ;
584
+ Assert . IsTrue ( modulesNames . Contains ( "TestClass" ) ) ;
585
+ Assert . AreEqual ( 3 , modulesNames . Count ) ;
586
+ }
587
+ }
588
+
432
589
[ Category ( "Code Explorer" ) ]
433
590
[ Test ]
434
591
public void UpdateFromFile_Cancel ( )
0 commit comments