sonarr-repo-only/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs

92 lines
2.7 KiB
C#
Raw Normal View History

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