@@ -356,10 +356,10 @@ public async Task GetCommitRefs(CommitRefType type)
356356
357357 [ Test ]
358358 [ NGitLabRetry ]
359- public async Task GetArchiveWithoutOptionalParameters ( )
359+ public async Task GetArchive ( )
360360 {
361361 // Arrange
362- using var context = await RepositoryClientTestsContext . CreateAsync ( commitCount : 2 ) ;
362+ using var context = await RepositoryClientTestsContext . CreateAsync ( commitCount : 2 ) . ConfigureAwait ( false ) ;
363363
364364 // Act
365365 context . RepositoryClient . GetArchive ( ( stream ) => { } ) ;
@@ -376,78 +376,134 @@ public async Task GetArchiveWithoutOptionalParameters()
376376
377377 [ Test ]
378378 [ NGitLabRetry ]
379- public async Task GetArchiveAcceptsShaParameter ( )
379+ public async Task GetArchiveWithNullQueryPassesNoParameters ( )
380380 {
381381 // Arrange
382- using var context = await RepositoryClientTestsContext . CreateAsync ( commitCount : 2 ) ;
382+ using var context = await RepositoryClientTestsContext . CreateAsync ( commitCount : 2 ) . ConfigureAwait ( false ) ;
383383 var firstCommitId = context . Commits [ 0 ] . Id . ToString ( ) ;
384384
385385 // Act
386- context . RepositoryClient . GetArchive ( ( stream ) => { } , sha : firstCommitId ) ;
386+ context . RepositoryClient . GetArchive ( ( stream ) => { } , fileArchiveQuery : null ) ;
387387
388388 // Assert
389389 var requestPathAndQuery = context . Context . LastRequest . RequestUri . PathAndQuery ;
390390
391391 Assert . Multiple ( ( ) =>
392392 {
393393 Assert . That ( requestPathAndQuery , Is . Not . Null ) ;
394- Assert . That ( requestPathAndQuery . Contains ( $ "?sha= { firstCommitId } ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
394+ Assert . That ( requestPathAndQuery . EndsWith ( "/archive ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
395395 } ) ;
396396 }
397397
398- [ Test ]
398+ [ TestCase ( null , "" ) ]
399+ [ TestCase ( FileArchiveFormat . Bz2 , ".bz2" ) ]
400+ [ TestCase ( FileArchiveFormat . Gz , ".gz" ) ]
401+ [ TestCase ( FileArchiveFormat . Tar , ".tar" ) ]
402+ [ TestCase ( FileArchiveFormat . TarBz2 , ".tar.bz2" ) ]
403+ [ TestCase ( FileArchiveFormat . TarGz , ".tar.gz" ) ]
404+ [ TestCase ( FileArchiveFormat . Tb2 , ".tb2" ) ]
405+ [ TestCase ( FileArchiveFormat . Tbz2 , ".tbz2" ) ]
406+ [ TestCase ( FileArchiveFormat . Zip , ".zip" ) ]
399407 [ NGitLabRetry ]
400- public async Task GetArchiveAcceptsFormatParameter ( )
408+ public async Task GetArchiveFormatValuePassedCorrectly ( FileArchiveFormat ? archiveFormat , string expectedExtension )
401409 {
402410 // Arrange
403411 using var context = await RepositoryClientTestsContext . CreateAsync ( commitCount : 2 ) ;
404- var format = ".zip" ;
412+ var fileArchiveQuery = new FileArchiveQuery
413+ {
414+ Format = archiveFormat ,
415+ } ;
405416
406417 // Act
407- context . RepositoryClient . GetArchive ( ( stream ) => { } , format : format ) ;
418+ context . RepositoryClient . GetArchive ( ( stream ) => { } , fileArchiveQuery ) ;
408419
409420 // Assert
410421 var requestPathAndQuery = context . Context . LastRequest . RequestUri . PathAndQuery ;
411422
412423 Assert . Multiple ( ( ) =>
413424 {
414425 Assert . That ( requestPathAndQuery , Is . Not . Null ) ;
415- Assert . That ( requestPathAndQuery . Contains ( $ "/archive{ format } ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
426+ Assert . That ( requestPathAndQuery . EndsWith ( $ "/archive{ expectedExtension } ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
416427 } ) ;
417428 }
418429
419430 [ Test ]
420431 [ NGitLabRetry ]
421- public async Task GetArchiveAcceptsShaAndFormatParametersTogether ( )
432+ public async Task GetArchiveShaValuePassedCorrectly ( )
422433 {
423434 // Arrange
424435 using var context = await RepositoryClientTestsContext . CreateAsync ( commitCount : 2 ) ;
425- var format = ".zip" ;
426436 var firstCommitId = context . Commits [ 0 ] . Id . ToString ( ) ;
437+ var fileArchiveQuery = new FileArchiveQuery
438+ {
439+ Ref = firstCommitId ,
440+ } ;
427441
428442 // Act
429- context . RepositoryClient . GetArchive ( ( stream ) => { } , sha : firstCommitId , format : format ) ;
443+ context . RepositoryClient . GetArchive ( ( stream ) => { } , fileArchiveQuery ) ;
430444
431445 // Assert
432446 var requestPathAndQuery = context . Context . LastRequest . RequestUri . PathAndQuery ;
433447
434448 Assert . Multiple ( ( ) =>
435449 {
436450 Assert . That ( requestPathAndQuery , Is . Not . Null ) ;
437- Assert . That ( requestPathAndQuery . Contains ( $ "/archive{ format } ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
438- Assert . That ( requestPathAndQuery . Contains ( $ "?sha={ firstCommitId } ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
451+ Assert . That ( requestPathAndQuery . Contains ( $ "sha={ firstCommitId } ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
439452 } ) ;
440453 }
441454
442455 [ Test ]
443456 [ NGitLabRetry ]
444- public async Task GetArchiveThrowsExceptionWhenFormatDoesNotStartWithDot ( )
457+ public async Task GetArchivePathValuePassedCorrectly ( )
445458 {
446459 // Arrange
447460 using var context = await RepositoryClientTestsContext . CreateAsync ( commitCount : 2 ) ;
448- var format = "zip" ;
461+ var path = RepositoryClientTestsContext . SubfolderName ;
462+ var fileArchiveQuery = new FileArchiveQuery
463+ {
464+ Path = path ,
465+ } ;
449466
450- // Act and Assert
451- Assert . Throws < ArgumentException > ( ( ) => context . RepositoryClient . GetArchive ( ( stream ) => { } , format : format ) ) ;
467+ // Act
468+ context . RepositoryClient . GetArchive ( ( stream ) => { } , fileArchiveQuery ) ;
469+
470+ // Assert
471+ var requestPathAndQuery = context . Context . LastRequest . RequestUri . PathAndQuery ;
472+
473+ Assert . Multiple ( ( ) =>
474+ {
475+ Assert . That ( requestPathAndQuery , Is . Not . Null ) ;
476+ Assert . That ( requestPathAndQuery . Contains ( $ "path={ path } ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
477+ } ) ;
478+ }
479+
480+ [ Test ]
481+ [ NGitLabRetry ]
482+ public async Task GetArchiveCombinationOfValuesPassedCorrectly ( )
483+ {
484+ // Arrange
485+ using var context = await RepositoryClientTestsContext . CreateAsync ( commitCount : 2 ) ;
486+ var firstCommitId = context . Commits [ 0 ] . Id . ToString ( ) ;
487+ var path = RepositoryClientTestsContext . SubfolderName ;
488+ var fileArchiveQuery = new FileArchiveQuery
489+ {
490+ Format = FileArchiveFormat . Zip ,
491+ Path = path ,
492+ Ref = firstCommitId ,
493+ } ;
494+
495+ // Act
496+ context . RepositoryClient . GetArchive ( ( stream ) => { } , fileArchiveQuery ) ;
497+
498+ // Assert
499+ var requestPathAndQuery = context . Context . LastRequest . RequestUri . PathAndQuery ;
500+
501+ Assert . Multiple ( ( ) =>
502+ {
503+ Assert . That ( requestPathAndQuery , Is . Not . Null ) ;
504+ Assert . That ( requestPathAndQuery . Contains ( $ "/archive.zip", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
505+ Assert . That ( requestPathAndQuery . Contains ( $ "path={ path } ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
506+ Assert . That ( requestPathAndQuery . Contains ( $ "sha={ firstCommitId } ", StringComparison . OrdinalIgnoreCase ) , Is . True ) ;
507+ } ) ;
452508 }
453509}
0 commit comments