2011-09-10 08:42:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-09-16 06:01:31 +00:00
|
|
|
|
using System.IO;
|
2011-09-10 08:42:05 +00:00
|
|
|
|
using AutoMoq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
using NzbDrone.Core.Providers.Indexer;
|
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
public class BannerDownloadJobTest : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void BannerDownload_all()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
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>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
public void BannerDownload_some_null_BannerUrl()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
|
.WhereRandom(2)
|
|
|
|
|
.Have(s => s.BannerUrl = null)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
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>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
public void BannerDownload_some_failed_download()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
|
.Build();
|
|
|
|
|
|
2011-09-16 06:01:31 +00:00
|
|
|
|
var path = Path.Combine(CentralDispatch.AppPath, "Content", "Images", "Banners");
|
2011-09-10 08:42:05 +00:00
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(c => c.GetAllSeries())
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "1.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "2.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "3.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "4.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "5.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "6.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "7.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "8.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "9.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-09-16 06:01:31 +00:00
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "10.jpg")))
|
2011-09-10 08:42:05 +00:00
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
public void BannerDownload_all_failed_download()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
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>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
public void BannerDownload_single_banner()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.SeriesId = 1)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
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>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
|
|
|
|
.Returns("");
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
|
|
|
|
Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Download_Banner()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.SeriesId = 1)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Banner Download");
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
|
|
|
|
Times.Once());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|