@@ -261,17 +261,17 @@ static void SetupCredentialServiceMock(Mock<ICredentialService> mockedCredential
261
261
return outCredentials != null ;
262
262
} ) ;
263
263
}
264
+ }
264
265
265
- static async Task RestoreProjectsAsync ( SimpleTestPathContext pathContext , SimpleTestProjectContext projectA , SimpleTestProjectContext projectB , ITestOutputHelper testOutputHelper )
266
- {
267
- var settings = Settings . LoadDefaultSettings ( Path . GetDirectoryName ( pathContext . SolutionRoot ) , Path . GetFileName ( pathContext . NuGetConfig ) , null ) ;
268
- var packageSourceProvider = new PackageSourceProvider ( settings ) ;
266
+ static async Task RestoreProjectsAsync ( SimpleTestPathContext pathContext , SimpleTestProjectContext projectA , SimpleTestProjectContext projectB , ITestOutputHelper testOutputHelper )
267
+ {
268
+ var settings = Settings . LoadDefaultSettings ( Path . GetDirectoryName ( pathContext . SolutionRoot ) , Path . GetFileName ( pathContext . NuGetConfig ) , null ) ;
269
+ var packageSourceProvider = new PackageSourceProvider ( settings ) ;
269
270
270
- var sources = packageSourceProvider . LoadPackageSources ( ) ;
271
+ var sources = packageSourceProvider . LoadPackageSources ( ) ;
271
272
272
- await RestoreProjectAsync ( settings , pathContext , projectA , sources , testOutputHelper ) ;
273
- await RestoreProjectAsync ( settings , pathContext , projectB , sources , testOutputHelper ) ;
274
- }
273
+ await RestoreProjectAsync ( settings , pathContext , projectA , sources , testOutputHelper ) ;
274
+ await RestoreProjectAsync ( settings , pathContext , projectB , sources , testOutputHelper ) ;
275
275
276
276
static async Task RestoreProjectAsync ( ISettings settings ,
277
277
SimpleTestPathContext pathContext ,
@@ -290,6 +290,63 @@ static async Task RestoreProjectAsync(ISettings settings,
290
290
}
291
291
}
292
292
293
+ [ InlineData ( true ) ]
294
+ [ InlineData ( false ) ]
295
+ [ Theory ]
296
+ public async Task CanListPackagesForProjectsInSolutions ( bool useSlnx )
297
+ {
298
+ // Arrange
299
+ using var pathContext = new SimpleTestPathContext ( ) ;
300
+
301
+ var packageA100 = new SimpleTestPackageContext ( "A" , "1.0.0" ) ;
302
+ var packageB100 = new SimpleTestPackageContext ( "B" , "1.0.0" ) ;
303
+
304
+ await SimpleTestPackageUtility . CreatePackagesAsync (
305
+ pathContext . PackageSource ,
306
+ packageA100 ,
307
+ packageB100 ) ;
308
+
309
+ var projectA = SimpleTestProjectContext . CreateNETCore ( "ProjectA" , pathContext . SolutionRoot , "net6.0" ) ;
310
+ var projectB = SimpleTestProjectContext . CreateNETCore ( "ProjectB" , pathContext . SolutionRoot , "net6.0" ) ;
311
+
312
+ projectA . AddPackageToAllFrameworks ( packageA100 ) ;
313
+ projectB . AddPackageToAllFrameworks ( packageB100 ) ;
314
+
315
+ var solution = new SimpleTestSolutionContext ( pathContext . SolutionRoot , useSlnx ) ;
316
+ solution . Projects . Add ( projectA ) ;
317
+ solution . Projects . Add ( projectB ) ;
318
+ solution . Create ( pathContext . SolutionRoot ) ;
319
+
320
+ using var mockServer = new FileSystemBackedV3MockServer ( pathContext . PackageSource , isPrivateFeed : true ) ;
321
+ mockServer . Start ( ) ;
322
+ pathContext . Settings . AddSource ( sourceName : "private-source" , sourceUri : mockServer . ServiceIndexUri , allowInsecureConnectionsValue : bool . TrueString ) ;
323
+
324
+ // List package command requires restore to be run before it can list packages.
325
+ await RestoreProjectsAsync ( pathContext , projectA , projectB , _testOutputHelper ) ;
326
+
327
+ var output = new StringBuilder ( ) ;
328
+ var error = new StringBuilder ( ) ;
329
+ using TextWriter consoleOut = new StringWriter ( output ) ;
330
+ using TextWriter consoleError = new StringWriter ( error ) ;
331
+ var logger = new TestLogger ( _testOutputHelper ) ;
332
+ ListPackageCommandRunner listPackageCommandRunner = new ( ) ;
333
+ var packageRefArgs = new ListPackageArgs (
334
+ path : solution . SolutionPath ,
335
+ packageSources : [ new ( mockServer . ServiceIndexUri ) ] ,
336
+ frameworks : [ "net6.0" ] ,
337
+ reportType : ReportType . Vulnerable ,
338
+ renderer : new ListPackageConsoleRenderer ( consoleOut , consoleError ) ,
339
+ includeTransitive : false ,
340
+ prerelease : false ,
341
+ highestPatch : false ,
342
+ highestMinor : false ,
343
+ logger : logger ,
344
+ cancellationToken : CancellationToken . None ) ;
345
+
346
+ int result = await listPackageCommandRunner . ExecuteCommandAsync ( packageRefArgs ) ;
347
+ Assert . True ( result == 0 , userMessage : logger . ShowMessages ( ) ) ;
348
+ }
349
+
293
350
private void VerifyCommand ( Action < string , Mock < IListPackageCommandRunner > , CommandLineApplication , Func < LogLevel > > verify )
294
351
{
295
352
// Arrange
0 commit comments