@@ -290,16 +290,45 @@ public void VersionRange(bool asArgument)
290
290
cmd . StdErr . Should ( ) . BeEmpty ( ) ;
291
291
}
292
292
293
- [ Fact ]
294
- public void FileBasedApp ( )
293
+ private string [ ] ? GetFileBasedAppArgs ( bool legacyForm , bool ? versionOption , bool fileOption , bool noRestore , string packageName = "Humanizer" )
295
294
{
295
+ if ( ! legacyForm && ! fileOption )
296
+ {
297
+ Log . WriteLine ( "Skipping invalid combination of parameters" ) ;
298
+ return null ;
299
+ }
300
+
301
+ ( string , string ) commandArgs = legacyForm
302
+ ? ( "add" , "package" )
303
+ : ( "package" , "add" ) ;
304
+
305
+ return [
306
+ commandArgs . Item1 ,
307
+ .. ( ReadOnlySpan < string > ) ( fileOption ? [ ] : [ "Program.cs" ] ) ,
308
+ commandArgs . Item2 ,
309
+ .. ( ReadOnlySpan < string > ) ( versionOption switch
310
+ {
311
+ true => [ packageName , "--version" , "2.14.1" ] ,
312
+ false => [ $ "{ packageName } @2.14.1"] ,
313
+ null => [ packageName ] ,
314
+ } ) ,
315
+ .. ( ReadOnlySpan < string > ) ( fileOption ? [ "--file" , "Program.cs" ] : [ ] ) ,
316
+ .. ( ReadOnlySpan < string > ) ( noRestore ? [ "--no-restore" ] : [ ] ) ,
317
+ ] ;
318
+ }
319
+
320
+ [ Theory , CombinatorialData ]
321
+ public void FileBasedApp ( bool legacyForm , bool versionOption , bool fileOption , bool noRestore )
322
+ {
323
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption , fileOption , noRestore ) is not { } args ) return ;
324
+
296
325
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
297
326
var file = Path . Join ( testInstance . Path , "Program.cs" ) ;
298
327
File . WriteAllText ( file , """
299
328
Console.WriteLine();
300
329
""" ) ;
301
330
302
- new DotnetCommand ( Log , "package" , "add" , "[email protected] " , "--file" , "Program.cs" )
331
+ new DotnetCommand ( Log , args )
303
332
. WithWorkingDirectory ( testInstance . Path )
304
333
. Execute ( )
305
334
. Should ( ) . Pass ( ) ;
@@ -311,20 +340,21 @@ public void FileBasedApp()
311
340
""" ) ;
312
341
}
313
342
314
- [ Theory ]
315
- [ InlineData ( "Humanizer" ) ]
316
- [ InlineData ( "humanizer" ) ]
343
+ [ Theory , CombinatorialData ]
317
344
public void FileBasedApp_ReplaceExisting (
318
- string sourceFilePackageId )
345
+ [ CombinatorialValues ( "Humanizer" , "humanizer" ) ] string sourceFilePackageId ,
346
+ bool legacyForm , bool versionOption , bool fileOption , bool noRestore )
319
347
{
348
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption , fileOption , noRestore ) is not { } args ) return ;
349
+
320
350
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
321
351
var file = Path . Join ( testInstance . Path , "Program.cs" ) ;
322
352
File . WriteAllText ( file , $ """
323
353
#:package { sourceFilePackageId } @2.9.9
324
354
Console.WriteLine();
325
355
""" ) ;
326
356
327
- new DotnetCommand ( Log , "package" , "add" , "[email protected] " , "--file" , "Program.cs" )
357
+ new DotnetCommand ( Log , args )
328
358
. WithWorkingDirectory ( testInstance . Path )
329
359
. Execute ( )
330
360
. Should ( ) . Pass ( ) ;
@@ -400,16 +430,18 @@ public void FileBasedApp_NoVersion_Prerelease(string[] inputVersions, string? _,
400
430
""" ) ;
401
431
}
402
432
403
- [ Fact ]
404
- public void FileBasedApp_NoVersionAndNoRestore ( )
433
+ [ Theory , CombinatorialData ]
434
+ public void FileBasedApp_NoVersionAndNoRestore ( bool legacyForm , bool fileOption )
405
435
{
436
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption : null , fileOption , noRestore : true ) is not { } args ) return ;
437
+
406
438
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
407
439
var file = Path . Join ( testInstance . Path , "Program.cs" ) ;
408
440
File . WriteAllText ( file , """
409
441
Console.WriteLine();
410
442
""" ) ;
411
443
412
- new DotnetCommand ( Log , "package" , "add" , "Humanizer" , "--file" , "Program.cs" , "--no-restore" )
444
+ new DotnetCommand ( Log , args )
413
445
. WithWorkingDirectory ( testInstance . Path )
414
446
. Execute ( )
415
447
. Should ( ) . Pass ( ) ;
@@ -421,17 +453,19 @@ public void FileBasedApp_NoVersionAndNoRestore()
421
453
""" ) ;
422
454
}
423
455
424
- [ Fact ]
425
- public void FileBasedApp_VersionAndPrerelease ( )
456
+ [ Theory , CombinatorialData ]
457
+ public void FileBasedApp_VersionAndPrerelease ( bool legacyForm , bool versionOption , bool fileOption , bool noRestore )
426
458
{
459
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption , fileOption , noRestore ) is not { } args ) return ;
460
+
427
461
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
428
462
var file = Path . Join ( testInstance . Path , "Program.cs" ) ;
429
463
var source = """
430
464
Console.WriteLine();
431
465
""" ;
432
466
File . WriteAllText ( file , source ) ;
433
467
434
- new DotnetCommand ( Log , "package" , "add" , "[email protected] " , "--file" , "Program.cs" , " --prerelease")
468
+ new DotnetCommand ( Log , [ .. args , "--prerelease" ] )
435
469
. WithWorkingDirectory ( testInstance . Path )
436
470
. Execute ( )
437
471
. Should ( ) . Fail ( )
@@ -440,34 +474,38 @@ public void FileBasedApp_VersionAndPrerelease()
440
474
File . ReadAllText ( file ) . Should ( ) . Be ( source ) ;
441
475
}
442
476
443
- [ Fact ]
444
- public void FileBasedApp_InvalidPackage ( )
477
+ [ Theory , CombinatorialData ]
478
+ public void FileBasedApp_InvalidPackage ( bool legacyForm , bool fileOption )
445
479
{
480
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption : null , fileOption , noRestore : false , packageName : "Microsoft.ThisPackageDoesNotExist" ) is not { } args ) return ;
481
+
446
482
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
447
483
var file = Path . Join ( testInstance . Path , "Program.cs" ) ;
448
484
var source = """
449
485
Console.WriteLine();
450
486
""" ;
451
487
File . WriteAllText ( file , source ) ;
452
488
453
- new DotnetCommand ( Log , "package" , "add" , "Microsoft.ThisPackageDoesNotExist" , "--file" , "Program.cs" )
489
+ new DotnetCommand ( Log , args )
454
490
. WithWorkingDirectory ( testInstance . Path )
455
491
. Execute ( )
456
492
. Should ( ) . Fail ( ) ;
457
493
458
494
File . ReadAllText ( file ) . Should ( ) . Be ( source ) ;
459
495
}
460
496
461
- [ Fact ]
462
- public void FileBasedApp_InvalidPackage_NoRestore ( )
497
+ [ Theory , CombinatorialData ]
498
+ public void FileBasedApp_InvalidPackage_NoRestore ( bool legacyForm , bool fileOption )
463
499
{
500
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption : null , fileOption , noRestore : true , packageName : "Microsoft.ThisPackageDoesNotExist" ) is not { } args ) return ;
501
+
464
502
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
465
503
var file = Path . Join ( testInstance . Path , "Program.cs" ) ;
466
504
File . WriteAllText ( file , """
467
505
Console.WriteLine();
468
506
""" ) ;
469
507
470
- new DotnetCommand ( Log , "package" , "add" , "Microsoft.ThisPackageDoesNotExist" , "--file" , "Program.cs" , "--no-restore" )
508
+ new DotnetCommand ( Log , args )
471
509
. WithWorkingDirectory ( testInstance . Path )
472
510
. Execute ( )
473
511
. Should ( ) . Pass ( ) ;
@@ -479,9 +517,11 @@ public void FileBasedApp_InvalidPackage_NoRestore()
479
517
""" ) ;
480
518
}
481
519
482
- [ Fact ]
483
- public void FileBasedApp_CentralPackageManagement ( )
520
+ [ Theory , CombinatorialData ]
521
+ public void FileBasedApp_CentralPackageManagement ( bool legacyForm , bool versionOption , bool fileOption , bool noRestore )
484
522
{
523
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption , fileOption , noRestore ) is not { } args ) return ;
524
+
485
525
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
486
526
var file = Path . Join ( testInstance . Path , "Program.cs" ) ;
487
527
var source = """
@@ -498,7 +538,7 @@ public void FileBasedApp_CentralPackageManagement()
498
538
</Project>
499
539
""" ) ;
500
540
501
- new DotnetCommand ( Log , "package" , "add" , "[email protected] " , "--file" , "Program.cs" )
541
+ new DotnetCommand ( Log , args )
502
542
. WithWorkingDirectory ( testInstance . Path )
503
543
. Execute ( )
504
544
. Should ( ) . Pass ( ) ;
@@ -522,8 +562,10 @@ public void FileBasedApp_CentralPackageManagement()
522
562
}
523
563
524
564
[ Theory , CombinatorialData ]
525
- public void FileBasedApp_CentralPackageManagement_ReplaceExisting ( bool wasInFile )
565
+ public void FileBasedApp_CentralPackageManagement_ReplaceExisting ( bool wasInFile , bool legacyForm , bool versionOption , bool fileOption , bool noRestore )
526
566
{
567
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption , fileOption , noRestore ) is not { } args ) return ;
568
+
527
569
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
528
570
var file = Path . Join ( testInstance . Path , "Program.cs" ) ;
529
571
var source = """
@@ -553,7 +595,7 @@ public void FileBasedApp_CentralPackageManagement_ReplaceExisting(bool wasInFile
553
595
</Project>
554
596
""" ) ;
555
597
556
- new DotnetCommand ( Log , "package" , "add" , "[email protected] " , "--file" , "Program.cs" )
598
+ new DotnetCommand ( Log , args )
557
599
. WithWorkingDirectory ( testInstance . Path )
558
600
. Execute ( )
559
601
. Should ( ) . Pass ( ) ;
@@ -576,9 +618,11 @@ public void FileBasedApp_CentralPackageManagement_ReplaceExisting(bool wasInFile
576
618
""" ) ;
577
619
}
578
620
579
- [ Fact ]
580
- public void FileBasedApp_CentralPackageManagement_NoVersionSpecified ( )
621
+ [ Theory , CombinatorialData ]
622
+ public void FileBasedApp_CentralPackageManagement_NoVersionSpecified ( bool legacyForm , bool fileOption )
581
623
{
624
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption : null , fileOption , noRestore : false , packageName : "A" ) is not { } args ) return ;
625
+
582
626
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
583
627
584
628
string [ ] versions = [ "0.0.5" , "0.9.0" , "1.0.0-preview.3" ] ;
@@ -602,7 +646,7 @@ public void FileBasedApp_CentralPackageManagement_NoVersionSpecified()
602
646
</Project>
603
647
""" ) ;
604
648
605
- new DotnetCommand ( Log , "package" , "add" , "A" , "--file" , "Program.cs" )
649
+ new DotnetCommand ( Log , args )
606
650
. WithWorkingDirectory ( testInstance . Path )
607
651
. Execute ( )
608
652
. Should ( ) . Pass ( ) ;
@@ -624,9 +668,11 @@ public void FileBasedApp_CentralPackageManagement_NoVersionSpecified()
624
668
""" ) ;
625
669
}
626
670
627
- [ Fact ]
628
- public void FileBasedApp_CentralPackageManagement_NoVersionSpecified_KeepExisting ( )
671
+ [ Theory , CombinatorialData ]
672
+ public void FileBasedApp_CentralPackageManagement_NoVersionSpecified_KeepExisting ( bool legacyForm , bool fileOption , bool noRestore )
629
673
{
674
+ if ( GetFileBasedAppArgs ( legacyForm , versionOption : null , fileOption , noRestore ) is not { } args ) return ;
675
+
630
676
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
631
677
var file = Path . Join ( testInstance . Path , "Program.cs" ) ;
632
678
var source = """
@@ -648,7 +694,7 @@ public void FileBasedApp_CentralPackageManagement_NoVersionSpecified_KeepExistin
648
694
""" ;
649
695
File . WriteAllText ( directoryPackagesProps , directoryPackagesPropsSource ) ;
650
696
651
- new DotnetCommand ( Log , "package" , "add" , "Humanizer" , "--file" , "Program.cs" )
697
+ new DotnetCommand ( Log , args )
652
698
. WithWorkingDirectory ( testInstance . Path )
653
699
. Execute ( )
654
700
. Should ( ) . Pass ( ) ;
0 commit comments