@@ -411,6 +411,38 @@ public async Task VerifyTranslation_RootsFromMultipleLocationsAreAgregatedAsync(
411
411
}
412
412
413
413
[ TestMethod ]
414
+ public async Task VerifyTranslation_AncesterFromMultipleLocationsAreAgregatedAsync ( )
415
+ {
416
+ var componentRecorder = new ComponentRecorder ( ) ;
417
+ var npmDetector = new Mock < IComponentDetector > ( ) ;
418
+ var settings = new ScanSettings
419
+ {
420
+ SourceDirectory = this . sourceDirectory ,
421
+ } ;
422
+
423
+ var singleFileComponentRecorder = componentRecorder . CreateSingleFileComponentRecorder ( "location1" ) ;
424
+ var detectedComponent1 = new DetectedComponent ( new NpmComponent ( "test" , "1.0.0" ) , detector : npmDetector . Object ) ;
425
+ var detectedComponent2 = new DetectedComponent ( new NpmComponent ( "test" , "2.0.0" ) , detector : npmDetector . Object ) ;
426
+
427
+ singleFileComponentRecorder . RegisterUsage ( detectedComponent1 , isExplicitReferencedDependency : true ) ;
428
+ singleFileComponentRecorder . RegisterUsage ( detectedComponent2 , parentComponentId : detectedComponent1 . Component . Id ) ;
429
+
430
+ singleFileComponentRecorder = componentRecorder . CreateSingleFileComponentRecorder ( "location2" ) ;
431
+ var detectedComponent2NewLocation = new DetectedComponent ( new NpmComponent ( "test" , "2.0.0" ) , detector : npmDetector . Object ) ;
432
+ singleFileComponentRecorder . RegisterUsage ( detectedComponent2NewLocation , isExplicitReferencedDependency : true ) ;
433
+
434
+ var results = await this . SetupRecorderBasedScanningAsync ( settings , new List < ComponentRecorder > { componentRecorder } ) ;
435
+
436
+ var detectedComponents = results . ComponentsFound ;
437
+
438
+ var storedComponent1 = detectedComponents . First ( dc => dc . Component . Id == detectedComponent1 . Component . Id ) ;
439
+ storedComponent1 . AncestralReferrers . Should ( ) . BeEmpty ( "If a component is a root, then no root of itself" ) ;
440
+
441
+ var storedComponent2 = detectedComponents . First ( dc => dc . Component . Id == detectedComponent2 . Component . Id ) ;
442
+ storedComponent2 . AncestralReferrers . Should ( ) . ContainSingle ( "There 1 roots, the component is root of other component" ) ;
443
+ storedComponent2 . AncestralReferrers . Should ( ) . Contain ( detectedComponent1 . Component ) ;
444
+ }
445
+
414
446
public async Task VerifyTranslation_ComponentsAreReturnedWithRootsAsync ( )
415
447
{
416
448
var componentRecorder = new ComponentRecorder ( ) ;
@@ -440,6 +472,35 @@ public async Task VerifyTranslation_ComponentsAreReturnedWithRootsAsync()
440
472
storedComponent2 . TopLevelReferrers . Should ( ) . Contain ( detectedComponent1 . Component ) ;
441
473
}
442
474
475
+ [ TestMethod ]
476
+ public async Task VerifyTranslation_ComponentsAreReturnedWithAncesterAsync ( )
477
+ {
478
+ var componentRecorder = new ComponentRecorder ( ) ;
479
+ var npmDetector = new Mock < IComponentDetector > ( ) ;
480
+ var settings = new ScanSettings
481
+ {
482
+ SourceDirectory = this . sourceDirectory ,
483
+ } ;
484
+
485
+ var singleFileComponentRecorder = componentRecorder . CreateSingleFileComponentRecorder ( "location" ) ;
486
+ var detectedComponent1 = new DetectedComponent ( new NpmComponent ( "test" , "1.0.0" ) , detector : npmDetector . Object ) ;
487
+ var detectedComponent2 = new DetectedComponent ( new NpmComponent ( "test" , "2.0.0" ) , detector : npmDetector . Object ) ;
488
+
489
+ singleFileComponentRecorder . RegisterUsage ( detectedComponent1 , isExplicitReferencedDependency : true ) ;
490
+ singleFileComponentRecorder . RegisterUsage ( detectedComponent2 , parentComponentId : detectedComponent1 . Component . Id ) ;
491
+
492
+ var results = await this . SetupRecorderBasedScanningAsync ( settings , new List < ComponentRecorder > { componentRecorder } ) ;
493
+
494
+ var detectedComponents = results . ComponentsFound ;
495
+
496
+ var storedComponent1 = detectedComponents . First ( dc => dc . Component . Id == detectedComponent1 . Component . Id ) ;
497
+ storedComponent1 . AncestralReferrers . Should ( ) . BeEmpty ( "If a component is a root, then no root of itself" ) ;
498
+
499
+ var storedComponent2 = detectedComponents . First ( dc => dc . Component . Id == detectedComponent2 . Component . Id ) ;
500
+ storedComponent2 . AncestralReferrers . Should ( ) . ContainSingle ( ) ;
501
+ storedComponent2 . AncestralReferrers . Should ( ) . Contain ( detectedComponent1 . Component ) ;
502
+ }
503
+
443
504
[ TestMethod ]
444
505
public async Task VerifyTranslation_DevDependenciesAreMergedWhenSameComponentInDifferentFilesAsync ( )
445
506
{
0 commit comments