@@ -1569,6 +1569,32 @@ public class TheCommitPackageMethod : FactsBase
15691569 . Where ( s => ! SupportedPackageStatuses . Any ( o => s . Equals ( o [ 0 ] ) ) )
15701570 . Select ( s => new object [ ] { s } ) ;
15711571
1572+ [ Fact ]
1573+ public async Task ThrowsWhenPackageIsNull ( )
1574+ {
1575+ var ex = await Assert . ThrowsAsync < ArgumentNullException > ( ( ) => _target . CommitPackageAsync ( package : null , packageFile : Mock . Of < Stream > ( ) ) ) ;
1576+ Assert . Equal ( "package" , ex . ParamName ) ;
1577+ }
1578+
1579+ [ Fact ]
1580+ public async Task ThrowsWhenPackageFileIsNull ( )
1581+ {
1582+ var ex = await Assert . ThrowsAsync < ArgumentNullException > ( ( ) => _target . CommitPackageAsync ( package : Mock . Of < Package > ( ) , packageFile : null ) ) ;
1583+ Assert . Equal ( "packageFile" , ex . ParamName ) ;
1584+ }
1585+
1586+ [ Fact ]
1587+ public async Task ThrowsWhenPackageStreamIsNotSeekable ( )
1588+ {
1589+ var stream = new Mock < Stream > ( ) ;
1590+ stream . SetupGet ( s => s . CanSeek )
1591+ . Returns ( false ) ;
1592+
1593+ var ex = await Assert . ThrowsAsync < ArgumentException > ( ( ) => _target . CommitPackageAsync ( package : Mock . Of < Package > ( ) , packageFile : stream . Object ) ) ;
1594+ Assert . Contains ( "seek" , ex . Message ) ;
1595+ Assert . Equal ( "packageFile" , ex . ParamName ) ;
1596+ }
1597+
15721598 [ Theory ]
15731599 [ MemberData ( nameof ( SupportedPackageStatuses ) ) ]
15741600 public async Task CommitsAfterSavingSupportedPackageStatuses ( PackageStatus packageStatus )
@@ -1865,6 +1891,30 @@ public async Task SavesLicenseFileWhenPackageIsAvailable(PackageStatus packageSt
18651891 expectedLicenseSave ? Times . Once ( ) : Times . Never ( ) ) ;
18661892 }
18671893
1894+ [ Fact ]
1895+ public async Task ResetsPackageStreamAfterSavingLicenseFile ( )
1896+ {
1897+ _package . PackageStatusKey = PackageStatus . Available ;
1898+ _package . EmbeddedLicenseType = EmbeddedLicenseFileType . PlainText ;
1899+
1900+ _packageFile = GeneratePackageWithUserContent ( licenseFilename : "license.txt" , licenseFileContents : "some license" ) . Object . GetStream ( ) ;
1901+
1902+ _licenseFileService
1903+ . Setup ( lfs => lfs . ExtractAndSaveLicenseFileAsync ( _package , _packageFile ) )
1904+ . Callback < Package , Stream > ( ( _ , stream ) => stream . Position = 42 )
1905+ . Returns ( Task . CompletedTask ) ;
1906+
1907+ _packageFileService
1908+ . Setup ( pfs => pfs . SavePackageFileAsync ( _package , _packageFile ) )
1909+ . Callback < Package , Stream > ( ( _ , stream ) => Assert . Equal ( 0 , stream . Position ) )
1910+ . Returns ( Task . CompletedTask ) ;
1911+
1912+ var result = await _target . CommitPackageAsync ( _package , _packageFile ) ;
1913+
1914+ _licenseFileService . Verify ( lfs => lfs . ExtractAndSaveLicenseFileAsync ( _package , _packageFile ) , Times . Once ) ;
1915+ _packageFileService . Verify ( pfs => pfs . SavePackageFileAsync ( _package , _packageFile ) , Times . Once ) ;
1916+ }
1917+
18681918 [ Theory ]
18691919 [ InlineData ( PackageStatus . Validating , false ) ]
18701920 [ InlineData ( PackageStatus . Available , true ) ]
0 commit comments