2020-03-29 20:05:48 +00:00
|
|
|
using System;
|
2019-12-22 22:08:53 +00:00
|
|
|
using FluentAssertions;
|
2014-04-19 15:09:22 +00:00
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Common.Disk;
|
2014-09-11 23:49:41 +00:00
|
|
|
using NzbDrone.Common.Http;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.Download;
|
2014-09-13 23:13:00 +00:00
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2018-03-14 20:41:36 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2014-09-11 20:24:00 +00:00
|
|
|
using NzbDrone.Core.RemotePathMappings;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Download.DownloadClientTests
|
|
|
|
{
|
|
|
|
public abstract class DownloadClientFixtureBase<TSubject> : CoreTest<TSubject>
|
|
|
|
where TSubject : class, IDownloadClient
|
|
|
|
{
|
2017-03-06 21:23:25 +00:00
|
|
|
protected readonly string _title = "Droned.1998.1080p.WEB-DL-DRONE";
|
|
|
|
protected readonly string _downloadUrl = "http://somewhere.com/Droned.1998.1080p.WEB-DL-DRONE.ext";
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void SetupBase()
|
|
|
|
{
|
2014-05-27 21:04:13 +00:00
|
|
|
Mocker.GetMock<IConfigService>()
|
|
|
|
.SetupGet(s => s.DownloadClientHistoryLimit)
|
|
|
|
.Returns(30);
|
|
|
|
|
2014-04-19 15:09:22 +00:00
|
|
|
Mocker.GetMock<IParsingService>()
|
2017-02-24 14:40:25 +00:00
|
|
|
.Setup(s => s.Map(It.IsAny<ParsedMovieInfo>(), It.IsAny<string>(), (SearchCriteriaBase)null))
|
2019-12-22 22:08:53 +00:00
|
|
|
.Returns(() => new MappingResult { RemoteMovie = CreateRemoteMovie(), MappingResultType = MappingResultType.Success });
|
2014-09-11 23:49:41 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IHttpClient>()
|
2014-09-12 22:39:42 +00:00
|
|
|
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
|
2020-10-02 18:29:25 +00:00
|
|
|
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
|
2014-09-11 23:49:41 +00:00
|
|
|
|
2014-09-11 20:24:00 +00:00
|
|
|
Mocker.GetMock<IRemotePathMappingService>()
|
2015-10-03 17:45:26 +00:00
|
|
|
.Setup(v => v.RemapRemoteToLocal(It.IsAny<string>(), It.IsAny<OsPath>()))
|
|
|
|
.Returns<string, OsPath>((h, r) => r);
|
2014-04-19 15:09:22 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 14:40:25 +00:00
|
|
|
protected virtual RemoteMovie CreateRemoteMovie()
|
2014-04-19 15:09:22 +00:00
|
|
|
{
|
2017-03-06 21:23:25 +00:00
|
|
|
var remoteMovie = new RemoteMovie();
|
|
|
|
remoteMovie.Release = new ReleaseInfo();
|
|
|
|
remoteMovie.Release.Title = _title;
|
|
|
|
remoteMovie.Release.DownloadUrl = _downloadUrl;
|
|
|
|
remoteMovie.Release.DownloadProtocol = Subject.Protocol;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
remoteMovie.ParsedMovieInfo = new ParsedMovieInfo();
|
2014-04-19 15:09:22 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
remoteMovie.Movie = new Movie();
|
2014-04-19 15:09:22 +00:00
|
|
|
|
2017-03-06 21:23:25 +00:00
|
|
|
return remoteMovie;
|
2014-04-19 15:09:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void VerifyIdentifiable(DownloadClientItem downloadClientItem)
|
|
|
|
{
|
2020-03-29 20:05:48 +00:00
|
|
|
downloadClientItem.DownloadClientInfo.Protocol.Should().Be(Subject.Protocol);
|
|
|
|
downloadClientItem.DownloadClientInfo.Id.Should().Be(Subject.Definition.Id);
|
|
|
|
downloadClientItem.DownloadClientInfo.Name.Should().Be(Subject.Definition.Name);
|
2014-12-19 00:26:42 +00:00
|
|
|
downloadClientItem.DownloadId.Should().NotBeNullOrEmpty();
|
2014-04-19 15:09:22 +00:00
|
|
|
downloadClientItem.Title.Should().NotBeNullOrEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void VerifyQueued(DownloadClientItem downloadClientItem)
|
|
|
|
{
|
|
|
|
VerifyIdentifiable(downloadClientItem);
|
|
|
|
downloadClientItem.RemainingSize.Should().NotBe(0);
|
2019-12-22 22:08:53 +00:00
|
|
|
|
2022-11-20 18:27:45 +00:00
|
|
|
// downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero);
|
|
|
|
// downloadClientItem.OutputPath.Should().NotBeNullOrEmpty();
|
2014-04-19 15:09:22 +00:00
|
|
|
downloadClientItem.Status.Should().Be(DownloadItemStatus.Queued);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void VerifyPaused(DownloadClientItem downloadClientItem)
|
|
|
|
{
|
|
|
|
VerifyIdentifiable(downloadClientItem);
|
|
|
|
|
|
|
|
downloadClientItem.RemainingSize.Should().NotBe(0);
|
2019-12-22 22:08:53 +00:00
|
|
|
|
2022-11-20 18:27:45 +00:00
|
|
|
// downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero);
|
|
|
|
// downloadClientItem.OutputPath.Should().NotBeNullOrEmpty();
|
2014-04-19 15:09:22 +00:00
|
|
|
downloadClientItem.Status.Should().Be(DownloadItemStatus.Paused);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void VerifyDownloading(DownloadClientItem downloadClientItem)
|
|
|
|
{
|
|
|
|
VerifyIdentifiable(downloadClientItem);
|
|
|
|
|
|
|
|
downloadClientItem.RemainingSize.Should().NotBe(0);
|
2019-12-22 22:08:53 +00:00
|
|
|
|
2022-11-20 18:27:45 +00:00
|
|
|
// downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero);
|
|
|
|
// downloadClientItem.OutputPath.Should().NotBeNullOrEmpty();
|
2014-04-19 15:09:22 +00:00
|
|
|
downloadClientItem.Status.Should().Be(DownloadItemStatus.Downloading);
|
2016-02-14 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void VerifyPostprocessing(DownloadClientItem downloadClientItem)
|
|
|
|
{
|
|
|
|
VerifyIdentifiable(downloadClientItem);
|
|
|
|
|
2022-11-20 18:27:45 +00:00
|
|
|
// downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero);
|
|
|
|
// downloadClientItem.OutputPath.Should().NotBeNullOrEmpty();
|
2016-02-14 16:55:32 +00:00
|
|
|
downloadClientItem.Status.Should().Be(DownloadItemStatus.Downloading);
|
2014-04-19 15:09:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void VerifyCompleted(DownloadClientItem downloadClientItem)
|
|
|
|
{
|
|
|
|
VerifyIdentifiable(downloadClientItem);
|
|
|
|
|
|
|
|
downloadClientItem.Title.Should().NotBeNullOrEmpty();
|
|
|
|
downloadClientItem.RemainingSize.Should().Be(0);
|
|
|
|
downloadClientItem.RemainingTime.Should().Be(TimeSpan.Zero);
|
2019-12-22 22:08:53 +00:00
|
|
|
|
2022-11-20 18:27:45 +00:00
|
|
|
// downloadClientItem.OutputPath.Should().NotBeNullOrEmpty();
|
2014-04-19 15:09:22 +00:00
|
|
|
downloadClientItem.Status.Should().Be(DownloadItemStatus.Completed);
|
|
|
|
}
|
|
|
|
|
2014-11-23 20:40:18 +00:00
|
|
|
protected void VerifyWarning(DownloadClientItem downloadClientItem)
|
|
|
|
{
|
|
|
|
VerifyIdentifiable(downloadClientItem);
|
|
|
|
|
|
|
|
downloadClientItem.Status.Should().Be(DownloadItemStatus.Warning);
|
|
|
|
}
|
|
|
|
|
2014-04-19 15:09:22 +00:00
|
|
|
protected void VerifyFailed(DownloadClientItem downloadClientItem)
|
|
|
|
{
|
|
|
|
VerifyIdentifiable(downloadClientItem);
|
|
|
|
|
|
|
|
downloadClientItem.Status.Should().Be(DownloadItemStatus.Failed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|