2011-10-21 02:42:17 +03:00
|
|
|
using System.IO;
|
2011-10-21 08:04:26 +03:00
|
|
|
using System.Net;
|
2011-09-10 11:42:05 +03:00
|
|
|
using AutoMoq;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2011-10-29 07:54:33 +03:00
|
|
|
using NzbDrone.Common;
|
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.Providers.Jobs;
|
|
|
|
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
|
|
|
|
public class BannerDownloadJobTest : TestBase
|
|
|
|
{
|
2011-11-04 02:23:54 +03:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
WithStrictMocker();
|
|
|
|
WithTempAsStartUpPath();
|
|
|
|
}
|
|
|
|
|
2011-09-10 11:42:05 +03:00
|
|
|
[Test]
|
|
|
|
public void BannerDownload_all()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(c => c.GetAllSeries())
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-10-21 08:04:26 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
.Returns("");
|
|
|
|
|
|
|
|
//Act
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
2011-09-10 11:42:05 +03:00
|
|
|
Times.Exactly(fakeSeries.Count));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void BannerDownload_some_null_BannerUrl()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
2011-10-23 08:39:14 +03:00
|
|
|
.Random(2)
|
2011-10-19 00:46:06 +03:00
|
|
|
.With(s => s.BannerUrl = null)
|
2011-09-10 11:42:05 +03:00
|
|
|
.Build();
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
var notification = new ProgressNotification("Banner Download");
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(c => c.GetAllSeries())
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-10-21 08:04:26 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
.Returns("");
|
|
|
|
|
|
|
|
//Act
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
2011-09-10 11:42:05 +03:00
|
|
|
Times.Exactly(8));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void BannerDownload_some_failed_download()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
var pathProvider = Mocker.Resolve<PathProvider>();
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(c => c.GetAllSeries())
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "1.jpg")))
|
2011-10-21 08:04:26 +03:00
|
|
|
.Throws(new WebException());
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "2.jpg")));
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "3.jpg")))
|
2011-10-21 08:04:26 +03:00
|
|
|
.Throws(new WebException());
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "4.jpg")));
|
2011-10-21 08:04:26 +03:00
|
|
|
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "5.jpg")))
|
2011-10-21 08:04:26 +03:00
|
|
|
.Throws(new WebException());
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "6.jpg")));
|
2011-10-21 08:04:26 +03:00
|
|
|
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "7.jpg")))
|
2011-10-21 08:04:26 +03:00
|
|
|
.Throws(new WebException());
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "8.jpg")));
|
2011-10-21 08:04:26 +03:00
|
|
|
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "9.jpg")))
|
2011-10-21 08:04:26 +03:00
|
|
|
.Throws(new WebException());
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-11-03 08:04:14 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "10.jpg")));
|
2011-10-21 08:04:26 +03:00
|
|
|
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
.Returns("");
|
|
|
|
|
|
|
|
//Act
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
2011-09-10 11:42:05 +03:00
|
|
|
Times.Exactly(fakeSeries.Count));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void BannerDownload_all_failed_download()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(c => c.GetAllSeries())
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
2011-10-21 08:04:26 +03:00
|
|
|
.Throws(new WebException());
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
.Returns("");
|
|
|
|
|
|
|
|
//Act
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
2011-09-10 11:42:05 +03:00
|
|
|
Times.Exactly(fakeSeries.Count));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void BannerDownload_single_banner()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.SeriesId = 1)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(c => c.GetSeries(1))
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
2011-10-21 08:04:26 +03:00
|
|
|
.Throws(new WebException());
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
.Returns("");
|
|
|
|
|
|
|
|
//Act
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
2011-09-10 11:42:05 +03:00
|
|
|
Times.Once());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Download_Banner()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.SeriesId = 1)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.GetMock<HttpProvider>()
|
2011-09-10 11:42:05 +03:00
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
2011-10-21 08:04:26 +03:00
|
|
|
.Throws(new WebException());
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
//Act
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
//Assert
|
2011-11-04 02:23:54 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
2011-09-10 11:42:05 +03:00
|
|
|
Times.Once());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|