Fixed tests

pull/38/head
Taloth Saldono 5 years ago committed by ta264
parent 138a188cc9
commit 3c335d498e

@ -288,6 +288,11 @@ namespace NzbDrone.Common.Test.Http
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 @@ namespace NzbDrone.Common.Test.Http
{
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 @@ namespace NzbDrone.Common.Http
public void DownloadFile(string url, string fileName, string userAgent = null)
{
var fileNamePart = fileName + ".part";
try
{
var fileInfo = new FileInfo(fileName);
@ -242,7 +244,7 @@ namespace NzbDrone.Common.Http
_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 @@ namespace NzbDrone.Common.Http
}
stopWatch.Stop();
File.Move(fileNamePart, fileName);
_logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
}
catch (WebException e)
{
_logger.Warn("Failed to get response from: {0} {1}", url, e.Message);
throw;
}
catch (Exception e)
finally
{
_logger.Warn(e, "Failed to get response from: " + url);
throw;
if (File.Exists(fileNamePart))
{
File.Delete(fileNamePart);
}
}
}

@ -26,7 +26,7 @@ namespace NzbDrone.Common.Http
public override string ToString()
{
if (Response != null)
if (Response != null && Response.ResponseData != null)
{
return base.ToString() + Environment.NewLine + Response.Content;
}

Loading…
Cancel
Save