Fixed tests
This commit is contained in:
parent
adbd519061
commit
b764c44318
|
@ -281,6 +281,11 @@ namespace NzbDrone.Common.Test.Http
|
||||||
Subject.DownloadFile(url, file);
|
Subject.DownloadFile(url, file);
|
||||||
|
|
||||||
File.Exists(file).Should().BeTrue();
|
File.Exists(file).Should().BeTrue();
|
||||||
|
File.Exists(file + ".part").Should().BeFalse();
|
||||||
|
|
||||||
|
var fileInfo = new FileInfo(file);
|
||||||
|
|
||||||
|
fileInfo.Length.Should().Be(307054);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -288,9 +293,10 @@ namespace NzbDrone.Common.Test.Http
|
||||||
{
|
{
|
||||||
var file = GetTempFilePath();
|
var file = GetTempFilePath();
|
||||||
|
|
||||||
Assert.Throws<WebException>(() => Subject.DownloadFile("http://download.sonarr.tv/wrongpath", file));
|
Assert.Throws<HttpException>(() => Subject.DownloadFile("http://download.sonarr.tv/wrongpath", file));
|
||||||
|
|
||||||
File.Exists(file).Should().BeFalse();
|
File.Exists(file).Should().BeFalse();
|
||||||
|
File.Exists(file + ".part").Should().BeFalse();
|
||||||
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
ExceptionVerification.ExpectedWarns(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,6 +229,8 @@ namespace NzbDrone.Common.Http
|
||||||
|
|
||||||
public void DownloadFile(string url, string fileName)
|
public void DownloadFile(string url, string fileName)
|
||||||
{
|
{
|
||||||
|
var fileNamePart = fileName + ".part";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var fileInfo = new FileInfo(fileName);
|
var fileInfo = new FileInfo(fileName);
|
||||||
|
@ -240,24 +242,22 @@ namespace NzbDrone.Common.Http
|
||||||
_logger.Debug("Downloading [{0}] to [{1}]", url, fileName);
|
_logger.Debug("Downloading [{0}] to [{1}]", url, fileName);
|
||||||
|
|
||||||
var stopWatch = Stopwatch.StartNew();
|
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);
|
var request = new HttpRequest(url);
|
||||||
request.ResponseStream = fileStream;
|
request.ResponseStream = fileStream;
|
||||||
var response = Get(request);
|
var response = Get(request);
|
||||||
}
|
}
|
||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
|
File.Move(fileNamePart, fileName);
|
||||||
_logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
|
_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);
|
if (File.Exists(fileNamePart))
|
||||||
throw;
|
{
|
||||||
|
File.Delete(fileNamePart);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.Warn(e, "Failed to get response from: " + url);
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace NzbDrone.Common.Http
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
if (Response != null)
|
if (Response != null && Response.ResponseData != null)
|
||||||
{
|
{
|
||||||
return base.ToString() + Environment.NewLine + Response.Content;
|
return base.ToString() + Environment.NewLine + Response.Content;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue