2013-02-19 06:56:02 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
2011-09-10 08:42:05 +00:00
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2011-09-10 08:42:05 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-02-19 06:56:02 +00:00
|
|
|
|
using System.Linq;
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.JobTests
|
2011-09-10 08:42:05 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 05:44:06 +00:00
|
|
|
|
public class BannerDownloadJobTest : CoreTest
|
2011-09-10 08:42:05 +00:00
|
|
|
|
{
|
2012-03-07 02:53:49 +00:00
|
|
|
|
private ProgressNotification _notification;
|
2011-11-03 23:23:54 +00:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2012-03-07 02:53:49 +00:00
|
|
|
|
_notification = new ProgressNotification("Test");
|
2011-11-13 07:27:16 +00:00
|
|
|
|
WithTempAsAppPath();
|
2011-11-03 23:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-07 02:53:49 +00:00
|
|
|
|
private void WithSuccessfulDownload()
|
2011-09-10 08:42:05 +00:00
|
|
|
|
{
|
2012-03-07 02:53:49 +00:00
|
|
|
|
Mocker.GetMock<BannerProvider>()
|
2012-03-07 20:37:36 +00:00
|
|
|
|
.Setup(s => s.Download(It.IsAny<Series>()))
|
2012-03-07 02:53:49 +00:00
|
|
|
|
.Returns(true);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-07 02:53:49 +00:00
|
|
|
|
private void WithFailedDownload()
|
2011-09-10 08:42:05 +00:00
|
|
|
|
{
|
2012-03-07 02:53:49 +00:00
|
|
|
|
Mocker.GetMock<BannerProvider>()
|
2012-03-07 20:37:36 +00:00
|
|
|
|
.Setup(s => s.Download(It.IsAny<Series>()))
|
2012-03-07 02:53:49 +00:00
|
|
|
|
.Returns(false);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-07 02:53:49 +00:00
|
|
|
|
private void VerifyDownloadMock(int times)
|
2011-09-10 08:42:05 +00:00
|
|
|
|
{
|
2012-03-07 20:37:36 +00:00
|
|
|
|
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(It.IsAny<Series>()), Times.Exactly(times));
|
2011-09-10 08:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-03-07 02:53:49 +00:00
|
|
|
|
public void Start_should_download_banners_for_all_series_when_no_targetId_is_passed_in()
|
2011-09-10 08:42:05 +00:00
|
|
|
|
{
|
2012-03-07 02:53:49 +00:00
|
|
|
|
WithSuccessfulDownload();
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2012-03-07 02:53:49 +00:00
|
|
|
|
var series = Builder<Series>.CreateListOfSize(5)
|
2013-02-19 06:56:02 +00:00
|
|
|
|
.Build().ToList();
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.All())
|
2012-03-07 02:53:49 +00:00
|
|
|
|
.Returns(series);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, null);
|
2012-03-07 02:53:49 +00:00
|
|
|
|
VerifyDownloadMock(series.Count);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-03-07 02:53:49 +00:00
|
|
|
|
public void Start_should_only_attempt_to_download_for_series_with_banner_url()
|
2011-09-10 08:42:05 +00:00
|
|
|
|
{
|
2012-03-07 02:53:49 +00:00
|
|
|
|
WithSuccessfulDownload();
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2012-03-07 02:53:49 +00:00
|
|
|
|
var series = Builder<Series>.CreateListOfSize(5)
|
|
|
|
|
.TheFirst(2)
|
|
|
|
|
.With(s => s.BannerUrl = null)
|
2013-02-19 06:56:02 +00:00
|
|
|
|
.Build().ToList();
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.All())
|
2012-03-07 02:53:49 +00:00
|
|
|
|
.Returns(series);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, null);
|
2012-03-07 02:53:49 +00:00
|
|
|
|
VerifyDownloadMock(3);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-03-07 02:53:49 +00:00
|
|
|
|
public void Start_should_download_single_banner_when_seriesId_is_passed_in()
|
2011-09-10 08:42:05 +00:00
|
|
|
|
{
|
2012-03-07 02:53:49 +00:00
|
|
|
|
WithSuccessfulDownload();
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2012-03-07 02:53:49 +00:00
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.Build();
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2013-02-26 03:58:57 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>().Setup(s => s.Get(series.Id))
|
2012-03-07 02:53:49 +00:00
|
|
|
|
.Returns(series);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2013-02-26 03:58:57 +00:00
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, new { SeriesId = series.Id });
|
2012-03-07 02:53:49 +00:00
|
|
|
|
VerifyDownloadMock(1);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|