File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
test/ICSharpCode.SharpZipLib.Tests/Zip Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -1569,5 +1569,47 @@ public void AddingAnAESEncryptedEntryShouldThrow()
15691569 Assert . That ( exception . Message , Is . EqualTo ( "Creation of AES encrypted entries is not supported" ) ) ;
15701570 }
15711571 }
1572+
1573+ /// <summary>
1574+ /// Test that we can add a file entry and set the name to sometihng other than the name of the file.
1575+ /// </summary>
1576+ [ Test ]
1577+ [ Category ( "Zip" ) ]
1578+ [ Category ( "CreatesTempFile" ) ]
1579+ public void AddFileWithAlternateName ( )
1580+ {
1581+ // Create a unique name that will be different from the file name
1582+ string fileName = Guid . NewGuid ( ) . ToString ( ) ;
1583+
1584+ using ( var sourceFile = Utils . GetDummyFile ( ) )
1585+ using ( var outputFile = Utils . GetDummyFile ( 0 ) )
1586+ {
1587+ var inputContent = File . ReadAllText ( sourceFile . Filename ) ;
1588+ using ( ZipFile f = ZipFile . Create ( outputFile . Filename ) )
1589+ {
1590+ f . BeginUpdate ( ) ;
1591+
1592+ // Add a file with the unique display name
1593+ f . Add ( sourceFile . Filename , fileName ) ;
1594+
1595+ f . CommitUpdate ( ) ;
1596+ f . Close ( ) ;
1597+ }
1598+
1599+ using ( ZipFile zipFile = new ZipFile ( outputFile . Filename ) )
1600+ {
1601+ Assert . That ( zipFile . Count , Is . EqualTo ( 1 ) ) ;
1602+
1603+ var fileEntry = zipFile . GetEntry ( fileName ) ;
1604+ Assert . That ( fileEntry , Is . Not . Null ) ;
1605+
1606+ using ( var sr = new StreamReader ( zipFile . GetInputStream ( fileEntry ) ) )
1607+ {
1608+ var outputContent = sr . ReadToEnd ( ) ;
1609+ Assert . AreEqual ( inputContent , outputContent , "extracted content does not match source content" ) ;
1610+ }
1611+ }
1612+ }
1613+ }
15721614 }
15731615}
You can’t perform that action at this time.
0 commit comments