@@ -369,58 +369,55 @@ public void FiltersFrameworkPackagesCollectionWithVulnerableMetadata(
369369 }
370370 }
371371
372- public class GetPackageMetadataAsyncWithEmptyPackageSources
372+ [ Fact ]
373+ public async Task GetPackageMetadataAsync_WithEmptyPackageSources_DoesNotThrowDivideByZero ( )
373374 {
374- [ Fact ]
375- public async Task GetPackageMetadataAsync_WithEmptyPackageSources_DoesNotThrowDivideByZero ( )
375+ // Arrange
376+ var packages = new FrameworkPackages ( "net40" ) ;
377+ var topLevelPackages = new List < InstalledPackageReference >
376378 {
377- // Arrange
378- var packages = new FrameworkPackages ( "net40" ) ;
379- var topLevelPackages = new List < InstalledPackageReference >
380- {
381- ListPackageTestHelper . CreateInstalledPackageReference ( name : "TestPackage" )
382- } ;
383- packages . TopLevelPackages = topLevelPackages ;
384- var allPackages = new List < FrameworkPackages > { packages } ;
385-
386- var output = new StringBuilder ( ) ;
387- var error = new StringBuilder ( ) ;
388- using TextWriter consoleOut = new StringWriter ( output ) ;
389- using TextWriter consoleError = new StringWriter ( error ) ;
390-
391- // Create ListPackageArgs with empty packageSources list to trigger the divide by zero scenario
392- var listPackageArgs = new ListPackageArgs (
393- path : "" ,
394- packageSources : new List < PackageSource > ( ) , // Empty package sources - this would cause divide by zero
395- frameworks : new List < string > ( ) ,
396- ReportType . Outdated , // This will trigger the code path that calls GetPackageMetadataAsync
397- new ListPackageConsoleRenderer ( consoleOut , consoleError ) ,
398- includeTransitive : false ,
399- prerelease : false ,
400- highestPatch : false ,
401- highestMinor : false ,
402- auditSources : null ,
403- logger : new Mock < ILogger > ( ) . Object ,
404- CancellationToken . None ) ;
405-
406- var listPackageRunner = new ListPackageCommandRunner ( ) ;
407-
408- // Act & Assert - Test the private method using reflection
409- var getPackageMetadataAsyncMethod = typeof ( ListPackageCommandRunner )
410- . GetMethod ( "GetPackageMetadataAsync" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance ) ;
411-
412- Assert . NotNull ( getPackageMetadataAsyncMethod ) ;
413-
414- // This should not throw DivideByZeroException
415- Exception exception = await Record . ExceptionAsync ( async ( ) =>
416- {
417- var task = ( Task < Dictionary < string , List < IPackageSearchMetadata > > > ) getPackageMetadataAsyncMethod . Invoke (
418- listPackageRunner , new object [ ] { allPackages , listPackageArgs } ) ;
419- await task ;
420- } ) ;
379+ ListPackageTestHelper . CreateInstalledPackageReference ( name : "TestPackage" )
380+ } ;
381+ packages . TopLevelPackages = topLevelPackages ;
382+ var allPackages = new List < FrameworkPackages > { packages } ;
383+
384+ var output = new StringBuilder ( ) ;
385+ var error = new StringBuilder ( ) ;
386+ using TextWriter consoleOut = new StringWriter ( output ) ;
387+ using TextWriter consoleError = new StringWriter ( error ) ;
388+
389+ // Create ListPackageArgs with empty packageSources list to trigger the divide by zero scenario
390+ var listPackageArgs = new ListPackageArgs (
391+ path : "" ,
392+ packageSources : new List < PackageSource > ( ) , // Empty package sources - this would cause divide by zero
393+ frameworks : new List < string > ( ) ,
394+ ReportType . Outdated , // This will trigger the code path that calls GetPackageMetadataAsync
395+ new ListPackageConsoleRenderer ( consoleOut , consoleError ) ,
396+ includeTransitive : false ,
397+ prerelease : false ,
398+ highestPatch : false ,
399+ highestMinor : false ,
400+ auditSources : null ,
401+ logger : new Mock < ILogger > ( ) . Object ,
402+ CancellationToken . None ) ;
403+
404+ var listPackageRunner = new ListPackageCommandRunner ( ) ;
405+
406+ // Act & Assert - Test the private method using reflection
407+ var getPackageMetadataAsyncMethod = typeof ( ListPackageCommandRunner )
408+ . GetMethod ( "GetPackageMetadataAsync" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance ) ;
409+
410+ Assert . NotNull ( getPackageMetadataAsyncMethod ) ;
411+
412+ // This should not throw DivideByZeroException
413+ Exception exception = await Record . ExceptionAsync ( async ( ) =>
414+ {
415+ var task = ( Task < Dictionary < string , List < IPackageSearchMetadata > > > ) getPackageMetadataAsyncMethod . Invoke (
416+ listPackageRunner , new object [ ] { allPackages , listPackageArgs } ) ;
417+ await task ;
418+ } ) ;
421419
422- Assert . Null ( exception ) ;
423- }
420+ Assert . Null ( exception ) ;
424421 }
425422 }
426423}
0 commit comments