@@ -412,6 +412,38 @@ public async Task DownloadAsync_WritesFile(int certificateId, bool isValid) {
412
412
}
413
413
}
414
414
415
+ [ Fact ]
416
+ public async Task DownloadAsync_WritesFileToWorkingDirectory ( ) {
417
+ var response = new HttpResponseMessage ( HttpStatusCode . OK ) {
418
+ Content = new StringContent ( "DATA" )
419
+ } ;
420
+
421
+ var handler = new TestHandler ( response ) ;
422
+ using var httpClient = new HttpClient ( handler ) ;
423
+ var client = new SectigoClient ( new ApiConfig ( "https://example.com/" , "u" , "p" , "c" , ApiVersion . V25_4 ) , httpClient ) ;
424
+ var certificates = new CertificatesClient ( client ) ;
425
+
426
+ var dir = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ;
427
+ Directory . CreateDirectory ( dir ) ;
428
+ var originalDir = Directory . GetCurrentDirectory ( ) ;
429
+ Directory . SetCurrentDirectory ( dir ) ;
430
+ var fileName = Path . GetRandomFileName ( ) ;
431
+ try {
432
+ await certificates . DownloadAsync ( 1 , fileName ) ;
433
+ Assert . NotNull ( handler . Request ) ;
434
+ Assert . Equal ( "https://example.com/ssl/v1/collect/1?format=base64" , handler . Request ! . RequestUri ! . ToString ( ) ) ;
435
+ var fullPath = Path . Combine ( dir , fileName ) ;
436
+ Assert . True ( File . Exists ( fullPath ) ) ;
437
+ Assert . Equal ( "DATA" , File . ReadAllText ( fullPath ) ) ;
438
+ Assert . Empty ( Directory . GetDirectories ( dir ) ) ;
439
+ } finally {
440
+ Directory . SetCurrentDirectory ( originalDir ) ;
441
+ if ( Directory . Exists ( dir ) ) {
442
+ Directory . Delete ( dir , true ) ;
443
+ }
444
+ }
445
+ }
446
+
415
447
[ Theory ]
416
448
[ InlineData ( "" ) ]
417
449
[ InlineData ( null ) ]
0 commit comments