2011-10-21 02:42:17 +03:00
|
|
|
using System.IO;
|
2011-10-21 08:04:26 +03:00
|
|
|
using System.Net;
|
2011-11-14 03:22:18 +03:00
|
|
|
|
2011-09-10 11:42:05 +03:00
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2011-10-29 07:54:33 +03:00
|
|
|
using NzbDrone.Common;
|
2011-12-02 04:33:17 +03:00
|
|
|
using NzbDrone.Core.Jobs;
|
2011-09-10 11:42:05 +03: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-21 02:42:17 +03:00
|
|
|
namespace NzbDrone.Core.Test.JobTests
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 10:27:16 +03:00
|
|
|
public class BannerDownloadJobTest : CoreTest
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
2012-03-07 05:53:49 +03:00
|
|
|
private ProgressNotification _notification;
|
2011-11-04 02:23:54 +03:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2012-03-07 05:53:49 +03:00
|
|
|
_notification = new ProgressNotification("Test");
|
2011-11-13 10:27:16 +03:00
|
|
|
WithTempAsAppPath();
|
2011-11-04 02:23:54 +03:00
|
|
|
}
|
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
private void WithSuccessfulDownload()
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
2012-03-07 05:53:49 +03:00
|
|
|
Mocker.GetMock<BannerProvider>()
|
2012-03-07 23:37:36 +03:00
|
|
|
.Setup(s => s.Download(It.IsAny<Series>()))
|
2012-03-07 05:53:49 +03:00
|
|
|
.Returns(true);
|
2011-09-10 11:42:05 +03:00
|
|
|
}
|
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
private void WithFailedDownload()
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
2012-03-07 05:53:49 +03:00
|
|
|
Mocker.GetMock<BannerProvider>()
|
2012-03-07 23:37:36 +03:00
|
|
|
.Setup(s => s.Download(It.IsAny<Series>()))
|
2012-03-07 05:53:49 +03:00
|
|
|
.Returns(false);
|
2011-09-10 11:42:05 +03:00
|
|
|
}
|
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
private void VerifyDownloadMock(int times)
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
2012-03-07 23:37:36 +03:00
|
|
|
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(It.IsAny<Series>()), Times.Exactly(times));
|
2011-09-10 11:42:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-03-07 05:53:49 +03:00
|
|
|
public void Start_should_download_banners_for_all_series_when_no_targetId_is_passed_in()
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
2012-03-07 05:53:49 +03:00
|
|
|
WithSuccessfulDownload();
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
var series = Builder<Series>.CreateListOfSize(5)
|
|
|
|
.Build();
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetAllSeries())
|
|
|
|
.Returns(series);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, 0, 0);
|
|
|
|
VerifyDownloadMock(series.Count);
|
2011-09-10 11:42:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-03-07 05:53:49 +03:00
|
|
|
public void Start_should_only_attempt_to_download_for_series_with_banner_url()
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
2012-03-07 05:53:49 +03:00
|
|
|
WithSuccessfulDownload();
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
var series = Builder<Series>.CreateListOfSize(5)
|
|
|
|
.TheFirst(2)
|
|
|
|
.With(s => s.BannerUrl = null)
|
|
|
|
.Build();
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetAllSeries())
|
|
|
|
.Returns(series);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, 0, 0);
|
|
|
|
VerifyDownloadMock(3);
|
2011-09-10 11:42:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-03-07 05:53:49 +03:00
|
|
|
public void Start_should_download_single_banner_when_seriesId_is_passed_in()
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
2012-03-07 05:53:49 +03:00
|
|
|
WithSuccessfulDownload();
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
.Build();
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetSeries(series.SeriesId))
|
|
|
|
.Returns(series);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, 1, 0);
|
|
|
|
VerifyDownloadMock(1);
|
2011-09-10 11:42:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|