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