|
|
|
@ -18,199 +18,79 @@ namespace NzbDrone.Core.Test.JobTests
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
public class BannerDownloadJobTest : CoreTest
|
|
|
|
|
{
|
|
|
|
|
private ProgressNotification _notification;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
WithStrictMocker();
|
|
|
|
|
_notification = new ProgressNotification("Test");
|
|
|
|
|
WithTempAsAppPath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void BannerDownload_all()
|
|
|
|
|
private void WithSuccessfulDownload()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(c => c.GetAllSeries())
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
|
.Returns("");
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
|
|
|
|
Times.Exactly(fakeSeries.Count));
|
|
|
|
|
Mocker.GetMock<BannerProvider>()
|
|
|
|
|
.Setup(s => s.Download(It.IsAny<ProgressNotification>(), It.IsAny<Series>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void BannerDownload_some_null_BannerUrl()
|
|
|
|
|
private void WithFailedDownload()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
|
.Random(2)
|
|
|
|
|
.With(s => s.BannerUrl = null)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(c => c.GetAllSeries())
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
|
.Returns("");
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
|
|
|
|
Times.Exactly(8));
|
|
|
|
|
Mocker.GetMock<BannerProvider>()
|
|
|
|
|
.Setup(s => s.Download(It.IsAny<ProgressNotification>(), It.IsAny<Series>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void BannerDownload_some_failed_download()
|
|
|
|
|
private void VerifyDownloadMock(int times)
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(4)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var bannerPath = Mocker.GetMock<EnviromentProvider>().Object.GetBannerPath();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(c => c.GetAllSeries())
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(bannerPath, "1.jpg")))
|
|
|
|
|
.Throws(new WebException());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(bannerPath, "2.jpg")));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(bannerPath, "3.jpg")))
|
|
|
|
|
.Throws(new WebException());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(bannerPath, "4.jpg")));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
|
.Returns("");
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
|
|
|
|
Times.Exactly(fakeSeries.Count));
|
|
|
|
|
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(_notification, It.IsAny<Series>()), Times.Exactly(times));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void BannerDownload_all_failed_download()
|
|
|
|
|
public void Start_should_download_banners_for_all_series_when_no_targetId_is_passed_in()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(c => c.GetAllSeries())
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
WithSuccessfulDownload();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
|
.Throws(new WebException());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
|
.Returns("");
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(5)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
|
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetAllSeries())
|
|
|
|
|
.Returns(series);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
|
|
|
|
Times.Exactly(fakeSeries.Count));
|
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, 0, 0);
|
|
|
|
|
VerifyDownloadMock(series.Count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void BannerDownload_single_banner()
|
|
|
|
|
public void Start_should_only_attempt_to_download_for_series_with_banner_url()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.SeriesId = 1)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(c => c.GetSeries(1))
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
|
.Throws(new WebException());
|
|
|
|
|
WithSuccessfulDownload();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
|
.Returns("");
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(5)
|
|
|
|
|
.TheFirst(2)
|
|
|
|
|
.With(s => s.BannerUrl = null)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
|
|
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetAllSeries())
|
|
|
|
|
.Returns(series);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
|
|
|
|
Times.Once());
|
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, 0, 0);
|
|
|
|
|
VerifyDownloadMock(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Download_Banner()
|
|
|
|
|
public void Start_should_download_single_banner_when_seriesId_is_passed_in()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.SeriesId = 1)
|
|
|
|
|
.Build();
|
|
|
|
|
WithSuccessfulDownload();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
|
.Throws(new WebException());
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
|
|
|
|
|
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetSeries(series.SeriesId))
|
|
|
|
|
.Returns(series);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
|
|
|
|
Times.Once());
|
|
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(_notification, 1, 0);
|
|
|
|
|
VerifyDownloadMock(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|