@@ -375,17 +375,17 @@ public async Task DownloadExistingDifferentContent(CancellationToken ct)
375375
376376 [ Test ( Description = "Unexpected response code from server" ) ]
377377 [ CancelAfter ( 30_000 ) ]
378- public void UnexpectedResponseCode ( CancellationToken ct )
378+ public async Task UnexpectedResponseCode ( CancellationToken ct )
379379 {
380380 using var httpServer = new TestHttpServer ( ctx => { ctx . Response . StatusCode = 404 ; } ) ;
381381 var url = new Uri ( httpServer . BaseUrl + "/test" ) ;
382382 var destPath = Path . Combine ( _tempDir , "test" ) ;
383383
384384 var manager = new Downloader ( NullLogger < Downloader > . Instance ) ;
385- // The "outer " Task should fail.
386- var ex = Assert . ThrowsAsync < HttpRequestException > ( async ( ) =>
387- await manager . StartDownloadAsync ( new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
388- NullDownloadValidator . Instance , ct ) ) ;
385+ // The "inner " Task should fail.
386+ var dlTask = await manager . StartDownloadAsync ( new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
387+ NullDownloadValidator . Instance , ct ) ;
388+ var ex = Assert . ThrowsAsync < HttpRequestException > ( async ( ) => await dlTask . Task ) ;
389389 Assert . That ( ex . Message , Does . Contain ( "404" ) ) ;
390390 }
391391
@@ -412,22 +412,6 @@ public async Task MismatchedETag(CancellationToken ct)
412412 Assert . That ( ex . Message , Does . Contain ( "ETag does not match SHA1 hash of downloaded file" ) . And . Contains ( "beef" ) ) ;
413413 }
414414
415- [ Test ( Description = "Timeout on response headers" ) ]
416- [ CancelAfter ( 30_000 ) ]
417- public void CancelledOuter ( CancellationToken ct )
418- {
419- using var httpServer = new TestHttpServer ( async _ => { await Task . Delay ( TimeSpan . FromSeconds ( 5 ) , ct ) ; } ) ;
420- var url = new Uri ( httpServer . BaseUrl + "/test" ) ;
421- var destPath = Path . Combine ( _tempDir , "test" ) ;
422-
423- var manager = new Downloader ( NullLogger < Downloader > . Instance ) ;
424- // The "outer" Task should fail.
425- var smallerCt = new CancellationTokenSource ( TimeSpan . FromSeconds ( 1 ) ) . Token ;
426- Assert . ThrowsAsync < TaskCanceledException > ( async ( ) => await manager . StartDownloadAsync (
427- new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
428- NullDownloadValidator . Instance , smallerCt ) ) ;
429- }
430-
431415 [ Test ( Description = "Timeout on response body" ) ]
432416 [ CancelAfter ( 30_000 ) ]
433417 public async Task CancelledInner ( CancellationToken ct )
@@ -479,12 +463,10 @@ public async Task ValidationFailureExistingFile(CancellationToken ct)
479463 await File . WriteAllTextAsync ( destPath , "test" , ct ) ;
480464
481465 var manager = new Downloader ( NullLogger < Downloader > . Instance ) ;
466+ var dlTask = await manager . StartDownloadAsync ( new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
467+ new TestDownloadValidator ( new Exception ( "test exception" ) ) , ct ) ;
482468 // The "outer" Task should fail because the inner task never starts.
483- var ex = Assert . ThrowsAsync < Exception > ( async ( ) =>
484- {
485- await manager . StartDownloadAsync ( new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
486- new TestDownloadValidator ( new Exception ( "test exception" ) ) , ct ) ;
487- } ) ;
469+ var ex = Assert . ThrowsAsync < Exception > ( async ( ) => { await dlTask . Task ; } ) ;
488470 Assert . That ( ex . Message , Does . Contain ( "Existing file failed validation" ) ) ;
489471 Assert . That ( ex . InnerException , Is . Not . Null ) ;
490472 Assert . That ( ex . InnerException ! . Message , Is . EqualTo ( "test exception" ) ) ;
0 commit comments