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