2013-04-01 08:22:16 +02:00
|
|
|
using System.Linq;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Core.Download;
|
2013-04-15 03:41:39 +02:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-01 08:22:16 +02:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
using NzbDrone.Core.Tv;
|
2013-07-31 07:49:41 +02:00
|
|
|
using NzbDrone.Test.Common;
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Download
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class DownloadServiceFixture : CoreTest<DownloadService>
|
|
|
|
{
|
2013-04-15 03:41:39 +02:00
|
|
|
private RemoteEpisode _parseResult;
|
2013-04-01 08:22:16 +02:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IProvideDownloadClient>()
|
|
|
|
.Setup(c => c.GetDownloadClient()).Returns(Mocker.GetMock<IDownloadClient>().Object);
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
.TheFirst(1).With(s => s.Id = 12)
|
|
|
|
.TheNext(1).With(s => s.Id = 99)
|
|
|
|
.All().With(s => s.SeriesId = 5)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
_parseResult = Builder<RemoteEpisode>.CreateNew()
|
2013-04-01 08:22:16 +02:00
|
|
|
.With(c => c.Series = Builder<Series>.CreateNew().Build())
|
2013-07-31 07:49:41 +02:00
|
|
|
.With(c => c.Report = Builder<ReportInfo>.CreateNew().Build())
|
2013-04-01 08:22:16 +02:00
|
|
|
.With(c => c.Episodes = episodes)
|
|
|
|
.Build();
|
2013-07-31 07:49:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDownloadClient>().Setup(c => c.IsConfigured).Returns(true);
|
2013-04-01 08:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void WithSuccessfulAdd()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IDownloadClient>()
|
2013-07-08 05:15:15 +02:00
|
|
|
.Setup(s => s.DownloadNzb(It.IsAny<RemoteEpisode>()))
|
2013-04-01 08:22:16 +02:00
|
|
|
.Returns(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void WithFailedAdd()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IDownloadClient>()
|
2013-07-08 05:15:15 +02:00
|
|
|
.Setup(s => s.DownloadNzb(It.IsAny<RemoteEpisode>()))
|
2013-04-01 08:22:16 +02:00
|
|
|
.Returns(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Download_report_should_publish_on_grab_event()
|
|
|
|
{
|
|
|
|
WithSuccessfulAdd();
|
|
|
|
|
|
|
|
Subject.DownloadReport(_parseResult);
|
|
|
|
|
|
|
|
VerifyEventPublished<EpisodeGrabbedEvent>();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Download_report_should_grab_using_client()
|
|
|
|
{
|
|
|
|
WithSuccessfulAdd();
|
|
|
|
|
|
|
|
Subject.DownloadReport(_parseResult);
|
|
|
|
|
|
|
|
Mocker.GetMock<IDownloadClient>()
|
2013-07-08 05:15:15 +02:00
|
|
|
.Verify(s => s.DownloadNzb(It.IsAny<RemoteEpisode>()), Times.Once());
|
2013-04-01 08:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Download_report_should_not_publish_on_failed_grab_event()
|
|
|
|
{
|
|
|
|
WithFailedAdd();
|
|
|
|
|
|
|
|
Subject.DownloadReport(_parseResult);
|
|
|
|
VerifyEventNotPublished<EpisodeGrabbedEvent>();
|
|
|
|
}
|
2013-07-31 07:49:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_not_attempt_download_if_client_isnt_configure()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IDownloadClient>().Setup(c => c.IsConfigured).Returns(false);
|
|
|
|
|
|
|
|
|
|
|
|
Subject.DownloadReport(_parseResult);
|
|
|
|
|
|
|
|
Mocker.GetMock<IDownloadClient>().Verify(c => c.DownloadNzb(It.IsAny<RemoteEpisode>()),Times.Never());
|
|
|
|
VerifyEventNotPublished<EpisodeGrabbedEvent>();
|
|
|
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
}
|
2013-04-01 08:22:16 +02:00
|
|
|
}
|
2013-07-08 05:15:15 +02:00
|
|
|
}
|