2011-10-20 23:42:17 +00:00
|
|
|
|
using System.IO;
|
2011-10-21 05:04:26 +00:00
|
|
|
|
using System.Net;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
2011-09-10 08:42:05 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2011-10-29 04:54:33 +00:00
|
|
|
|
using NzbDrone.Common;
|
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.Providers.Core;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
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
|
2011-11-13 07:27:16 +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)
|
|
|
|
|
.Build();
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2012-03-07 02:53:49 +00:00
|
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetAllSeries())
|
|
|
|
|
.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)
|
|
|
|
|
.Build();
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2012-03-07 02:53:49 +00:00
|
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetAllSeries())
|
|
|
|
|
.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
|
|
|
|
|
2012-03-07 02:53:49 +00:00
|
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetSeries(series.SeriesId))
|
|
|
|
|
.Returns(series);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
2012-09-11 06:35:25 +00:00
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, new { SeriesId = series.SeriesId });
|
2012-03-07 02:53:49 +00:00
|
|
|
|
VerifyDownloadMock(1);
|
2011-09-10 08:42:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|