mirror of
https://github.com/Readarr/Readarr
synced 2025-12-12 03:13:54 +01:00
Fixed tests
This commit is contained in:
parent
138a188cc9
commit
3c335d498e
3 changed files with 17 additions and 11 deletions
|
|
@ -288,6 +288,11 @@ public void should_download_file()
|
|||
Subject.DownloadFile(url, file);
|
||||
|
||||
File.Exists(file).Should().BeTrue();
|
||||
File.Exists(file + ".part").Should().BeFalse();
|
||||
|
||||
var fileInfo = new FileInfo(file);
|
||||
|
||||
fileInfo.Length.Should().Be(307054);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
@ -295,9 +300,10 @@ public void should_not_download_file_with_error()
|
|||
{
|
||||
var file = GetTempFilePath();
|
||||
|
||||
Assert.Throws<WebException>(() => Subject.DownloadFile("https://download.readarr.com/wrongpath", file));
|
||||
Assert.Throws<HttpException>(() => Subject.DownloadFile("https://download.readarr.com/wrongpath", file));
|
||||
|
||||
File.Exists(file).Should().BeFalse();
|
||||
File.Exists(file + ".part").Should().BeFalse();
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,6 +231,8 @@ private void HandleResponseCookies(HttpResponse response, CookieContainer cookie
|
|||
|
||||
public void DownloadFile(string url, string fileName, string userAgent = null)
|
||||
{
|
||||
var fileNamePart = fileName + ".part";
|
||||
|
||||
try
|
||||
{
|
||||
var fileInfo = new FileInfo(fileName);
|
||||
|
|
@ -242,7 +244,7 @@ public void DownloadFile(string url, string fileName, string userAgent = null)
|
|||
_logger.Debug("Downloading [{0}] to [{1}]", url, fileName);
|
||||
|
||||
var stopWatch = Stopwatch.StartNew();
|
||||
using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
|
||||
using (var fileStream = new FileStream(fileNamePart, FileMode.Create, FileAccess.ReadWrite))
|
||||
{
|
||||
var request = new HttpRequest(url);
|
||||
|
||||
|
|
@ -256,17 +258,15 @@ public void DownloadFile(string url, string fileName, string userAgent = null)
|
|||
}
|
||||
|
||||
stopWatch.Stop();
|
||||
File.Move(fileNamePart, fileName);
|
||||
_logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
|
||||
}
|
||||
catch (WebException e)
|
||||
finally
|
||||
{
|
||||
_logger.Warn("Failed to get response from: {0} {1}", url, e.Message);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Warn(e, "Failed to get response from: " + url);
|
||||
throw;
|
||||
if (File.Exists(fileNamePart))
|
||||
{
|
||||
File.Delete(fileNamePart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public HttpException(HttpResponse response)
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
if (Response != null)
|
||||
if (Response != null && Response.ResponseData != null)
|
||||
{
|
||||
return base.ToString() + Environment.NewLine + Response.Content;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue