using System; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Movies; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.Download.DownloadClientTests { public abstract class DownloadClientFixtureBase : CoreTest where TSubject : class, IDownloadClient { protected readonly string _title = "Droned.1998.1080p.WEB-DL-DRONE"; protected readonly string _downloadUrl = "http://somewhere.com/Droned.1998.1080p.WEB-DL-DRONE.ext"; [SetUp] public void SetupBase() { Mocker.GetMock() .SetupGet(s => s.DownloadClientHistoryLimit) .Returns(30); Mocker.GetMock() .Setup(s => s.Map(It.IsAny(), It.IsAny(), (SearchCriteriaBase)null)) .Returns(() => new MappingResult { RemoteMovie = CreateRemoteMovie(), MappingResultType = MappingResultType.Success }); Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); Mocker.GetMock() .Setup(v => v.RemapRemoteToLocal(It.IsAny(), It.IsAny())) .Returns((h, r) => r); } protected virtual RemoteMovie CreateRemoteMovie() { var remoteMovie = new RemoteMovie(); remoteMovie.Release = new ReleaseInfo(); remoteMovie.Release.Title = _title; remoteMovie.Release.DownloadUrl = _downloadUrl; remoteMovie.Release.DownloadProtocol = Subject.Protocol; remoteMovie.ParsedMovieInfo = new ParsedMovieInfo(); remoteMovie.Movie = new Movie(); return remoteMovie; } protected void VerifyIdentifiable(DownloadClientItem downloadClientItem) { downloadClientItem.DownloadClientInfo.Protocol.Should().Be(Subject.Protocol); downloadClientItem.DownloadClientInfo.Id.Should().Be(Subject.Definition.Id); downloadClientItem.DownloadClientInfo.Name.Should().Be(Subject.Definition.Name); downloadClientItem.DownloadId.Should().NotBeNullOrEmpty(); downloadClientItem.Title.Should().NotBeNullOrEmpty(); } protected void VerifyQueued(DownloadClientItem downloadClientItem) { VerifyIdentifiable(downloadClientItem); downloadClientItem.RemainingSize.Should().NotBe(0); // downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero); // downloadClientItem.OutputPath.Should().NotBeNullOrEmpty(); downloadClientItem.Status.Should().Be(DownloadItemStatus.Queued); } protected void VerifyPaused(DownloadClientItem downloadClientItem) { VerifyIdentifiable(downloadClientItem); downloadClientItem.RemainingSize.Should().NotBe(0); // downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero); // downloadClientItem.OutputPath.Should().NotBeNullOrEmpty(); downloadClientItem.Status.Should().Be(DownloadItemStatus.Paused); } protected void VerifyDownloading(DownloadClientItem downloadClientItem) { VerifyIdentifiable(downloadClientItem); downloadClientItem.RemainingSize.Should().NotBe(0); // downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero); // downloadClientItem.OutputPath.Should().NotBeNullOrEmpty(); downloadClientItem.Status.Should().Be(DownloadItemStatus.Downloading); } protected void VerifyPostprocessing(DownloadClientItem downloadClientItem) { VerifyIdentifiable(downloadClientItem); // downloadClientItem.RemainingTime.Should().NotBe(TimeSpan.Zero); // downloadClientItem.OutputPath.Should().NotBeNullOrEmpty(); downloadClientItem.Status.Should().Be(DownloadItemStatus.Downloading); } protected void VerifyCompleted(DownloadClientItem downloadClientItem) { VerifyIdentifiable(downloadClientItem); downloadClientItem.Title.Should().NotBeNullOrEmpty(); downloadClientItem.RemainingSize.Should().Be(0); downloadClientItem.RemainingTime.Should().Be(TimeSpan.Zero); // downloadClientItem.OutputPath.Should().NotBeNullOrEmpty(); downloadClientItem.Status.Should().Be(DownloadItemStatus.Completed); } protected void VerifyWarning(DownloadClientItem downloadClientItem) { VerifyIdentifiable(downloadClientItem); downloadClientItem.Status.Should().Be(DownloadItemStatus.Warning); } protected void VerifyFailed(DownloadClientItem downloadClientItem) { VerifyIdentifiable(downloadClientItem); downloadClientItem.Status.Should().Be(DownloadItemStatus.Failed); } } }