2012-02-07 08:08:07 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
2013-02-24 09:48:52 +03:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-02-24 22:18:48 +03:00
|
|
|
using NzbDrone.Core.Download;
|
2013-02-19 09:01:03 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
2012-02-07 08:08:07 +03:00
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
using NzbDrone.Core.Providers.DownloadClients;
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
2013-01-25 02:33:32 +03:00
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests
|
2012-02-07 08:08:07 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-02-24 22:18:48 +03:00
|
|
|
public class DownloadProviderFixture : CoreTest<DownloadProvider>
|
2012-02-07 08:08:07 +03:00
|
|
|
{
|
2013-02-24 22:18:48 +03:00
|
|
|
|
2012-02-07 08:08:07 +03:00
|
|
|
|
|
|
|
private void SetDownloadClient(DownloadClientType clientType)
|
|
|
|
{
|
2013-02-24 22:39:31 +03:00
|
|
|
Mocker.GetMock<IConfigService>()
|
2012-02-07 08:08:07 +03:00
|
|
|
.Setup(c => c.DownloadClient)
|
|
|
|
.Returns(clientType);
|
|
|
|
}
|
|
|
|
|
|
|
|
private EpisodeParseResult SetupParseResult()
|
|
|
|
{
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
2013-02-20 05:05:15 +03:00
|
|
|
.TheFirst(1).With(s => s.OID = 12)
|
|
|
|
.TheNext(1).With(s => s.OID = 99)
|
2012-02-07 08:08:07 +03:00
|
|
|
.All().With(s => s.SeriesId = 5)
|
|
|
|
.Build().ToList();
|
|
|
|
|
2013-02-22 03:47:09 +03:00
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-02-07 08:08:07 +03:00
|
|
|
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(episodes);
|
|
|
|
|
|
|
|
return Builder<EpisodeParseResult>.CreateNew()
|
2012-10-14 00:15:21 +03:00
|
|
|
.With(c => c.Quality = new QualityModel(QualityTypes.DVD, false))
|
2012-02-07 08:08:07 +03:00
|
|
|
.With(c => c.Series = Builder<Series>.CreateNew().Build())
|
2013-02-24 22:18:48 +03:00
|
|
|
.With(c => c.EpisodeNumbers = new List<int> { 2 })
|
2012-10-17 10:39:06 +03:00
|
|
|
.With(c => c.Episodes = episodes)
|
2012-02-07 08:08:07 +03:00
|
|
|
.Build();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void WithSuccessfullAdd()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<SabProvider>()
|
2012-11-23 06:36:07 +03:00
|
|
|
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<bool>()))
|
2012-02-07 08:08:07 +03:00
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
Mocker.GetMock<BlackholeProvider>()
|
2012-11-23 06:36:07 +03:00
|
|
|
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<bool>()))
|
2012-02-07 08:08:07 +03:00
|
|
|
.Returns(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void WithFailedAdd()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<SabProvider>()
|
2012-11-23 05:56:27 +03:00
|
|
|
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), false))
|
2012-02-07 08:08:07 +03:00
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
Mocker.GetMock<BlackholeProvider>()
|
2012-11-23 05:56:27 +03:00
|
|
|
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), false))
|
2012-02-07 08:08:07 +03:00
|
|
|
.Returns(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2013-02-24 22:18:48 +03:00
|
|
|
public void Download_report_should_publish_on_grab_event()
|
2012-02-07 08:08:07 +03:00
|
|
|
{
|
|
|
|
WithSuccessfullAdd();
|
|
|
|
SetDownloadClient(DownloadClientType.Sabnzbd);
|
|
|
|
|
|
|
|
var parseResult = SetupParseResult();
|
|
|
|
|
|
|
|
//Act
|
2013-02-24 22:18:48 +03:00
|
|
|
Subject.DownloadReport(parseResult);
|
2012-02-07 08:08:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Mocker.GetMock<SabProvider>()
|
2012-11-23 06:36:07 +03:00
|
|
|
.Verify(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), true), Times.Once());
|
2012-02-07 08:08:07 +03:00
|
|
|
|
|
|
|
Mocker.GetMock<BlackholeProvider>()
|
2012-11-23 06:36:07 +03:00
|
|
|
.Verify(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), true), Times.Never());
|
2012-02-07 08:08:07 +03:00
|
|
|
|
|
|
|
|
2013-02-24 22:39:31 +03:00
|
|
|
VerifyEventPublished<EpisodeGrabbedEvent>();
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(DownloadClientType.Sabnzbd)]
|
|
|
|
[TestCase(DownloadClientType.Blackhole)]
|
2013-02-24 22:18:48 +03:00
|
|
|
public void Download_report_should_not_publish_grabbed_event(DownloadClientType clientType)
|
2012-02-07 08:08:07 +03:00
|
|
|
{
|
|
|
|
WithFailedAdd();
|
|
|
|
SetDownloadClient(clientType);
|
|
|
|
|
|
|
|
var parseResult = SetupParseResult();
|
|
|
|
|
2013-02-24 22:18:48 +03:00
|
|
|
Subject.DownloadReport(parseResult);
|
2012-02-07 08:08:07 +03:00
|
|
|
|
|
|
|
|
2013-02-24 22:18:48 +03:00
|
|
|
VerifyEventNotPublished<EpisodeGrabbedEvent>();
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_sab_as_active_client()
|
|
|
|
{
|
|
|
|
SetDownloadClient(DownloadClientType.Sabnzbd);
|
2013-02-24 22:18:48 +03:00
|
|
|
Subject.GetActiveDownloadClient().Should().BeAssignableTo<SabProvider>();
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_blackhole_as_active_client()
|
|
|
|
{
|
|
|
|
SetDownloadClient(DownloadClientType.Blackhole);
|
2013-02-24 22:18:48 +03:00
|
|
|
Subject.GetActiveDownloadClient().Should().BeAssignableTo<BlackholeProvider>();
|
2012-02-07 08:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|