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