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-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;
|
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
using NzbDrone.Core.Providers.DownloadClients;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
|
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-17 05:44:06 +00:00
|
|
|
|
public class DownloadProviderFixture : CoreTest
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
2012-10-14 00:36:16 +00:00
|
|
|
|
public static object[] SabNamingCases =
|
|
|
|
|
{
|
|
|
|
|
new object[] { 1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, false, "My Series Name - 1x02 - My Episode Title [DVD]" },
|
|
|
|
|
new object[] { 1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, true, "My Series Name - 1x02 - My Episode Title [DVD] [Proper]" },
|
|
|
|
|
new object[] { 1, new[] { 2 }, "", QualityTypes.DVD, true, "My Series Name - 1x02 - [DVD] [Proper]" },
|
2013-01-01 03:45:57 +00:00
|
|
|
|
new object[] { 1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV720p, false, "My Series Name - 1x02-1x04 - My Episode Title [HDTV-720p]" },
|
|
|
|
|
new object[] { 1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV720p, true, "My Series Name - 1x02-1x04 - My Episode Title [HDTV-720p] [Proper]" },
|
|
|
|
|
new object[] { 1, new[] { 2, 4 }, "", QualityTypes.HDTV720p, true, "My Series Name - 1x02-1x04 - [HDTV-720p] [Proper]" },
|
2012-10-14 00:36:16 +00:00
|
|
|
|
};
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
|
|
private void SetDownloadClient(DownloadClientType clientType)
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<ConfigProvider>()
|
|
|
|
|
.Setup(c => c.DownloadClient)
|
|
|
|
|
.Returns(clientType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private EpisodeParseResult SetupParseResult()
|
|
|
|
|
{
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.TheFirst(1).With(s => s.OID = 12)
|
|
|
|
|
.TheNext(1).With(s => s.OID = 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()
|
2012-10-13 21:15:21 +00:00
|
|
|
|
.With(c => c.Quality = new QualityModel(QualityTypes.DVD, false))
|
2012-02-07 05:08:07 +00:00
|
|
|
|
.With(c => c.Series = Builder<Series>.CreateNew().Build())
|
|
|
|
|
.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]
|
|
|
|
|
public void Download_report_should_send_to_sab_add_to_history_mark_as_grabbed()
|
|
|
|
|
{
|
|
|
|
|
WithSuccessfullAdd();
|
|
|
|
|
SetDownloadClient(DownloadClientType.Sabnzbd);
|
|
|
|
|
|
|
|
|
|
var parseResult = SetupParseResult();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HistoryProvider>()
|
|
|
|
|
.Verify(s => s.Add(It.Is<History>(h => h.EpisodeId == 12 && h.SeriesId == 5)), Times.Once());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HistoryProvider>()
|
|
|
|
|
.Verify(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5)), Times.Once());
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-02-07 05:08:07 +00:00
|
|
|
|
.Verify(c => c.MarkEpisodeAsFetched(12));
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-02-07 05:08:07 +00:00
|
|
|
|
.Verify(c => c.MarkEpisodeAsFetched(99));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ExternalNotificationProvider>()
|
|
|
|
|
.Verify(c => c.OnGrab(It.IsAny<string>()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_download_nzb_to_blackhole_add_to_history_mark_as_grabbed()
|
|
|
|
|
{
|
|
|
|
|
WithSuccessfullAdd();
|
|
|
|
|
SetDownloadClient(DownloadClientType.Blackhole);
|
|
|
|
|
|
|
|
|
|
var parseResult = SetupParseResult();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Mocker.GetMock<SabProvider>()
|
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
|
|
|
|
|
|
|
|
|
Mocker.GetMock<BlackholeProvider>()
|
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<HistoryProvider>()
|
|
|
|
|
.Verify(s => s.Add(It.Is<History>(h => h.EpisodeId == 12 && h.SeriesId == 5)), Times.Once());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HistoryProvider>()
|
|
|
|
|
.Verify(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5)), Times.Once());
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-02-07 05:08:07 +00:00
|
|
|
|
.Verify(c => c.MarkEpisodeAsFetched(12));
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-02-07 05:08:07 +00:00
|
|
|
|
.Verify(c => c.MarkEpisodeAsFetched(99));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ExternalNotificationProvider>()
|
|
|
|
|
.Verify(c => c.OnGrab(It.IsAny<string>()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(DownloadClientType.Sabnzbd)]
|
|
|
|
|
[TestCase(DownloadClientType.Blackhole)]
|
|
|
|
|
public void Download_report_should_not_add_to_history_mark_as_grabbed_if_add_fails(DownloadClientType clientType)
|
|
|
|
|
{
|
|
|
|
|
WithFailedAdd();
|
|
|
|
|
SetDownloadClient(clientType);
|
|
|
|
|
|
|
|
|
|
var parseResult = SetupParseResult();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HistoryProvider>()
|
|
|
|
|
.Verify(s => s.Add(It.IsAny<History>()), Times.Never());
|
|
|
|
|
|
|
|
|
|
|
2013-02-22 00:47:09 +00:00
|
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2012-02-07 05:08:07 +00:00
|
|
|
|
.Verify(c => c.MarkEpisodeAsFetched(It.IsAny<int>()), Times.Never());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<ExternalNotificationProvider>()
|
|
|
|
|
.Verify(c => c.OnGrab(It.IsAny<String>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_sab_as_active_client()
|
|
|
|
|
{
|
|
|
|
|
SetDownloadClient(DownloadClientType.Sabnzbd);
|
|
|
|
|
Mocker.Resolve<DownloadProvider>().GetActiveDownloadClient().Should().BeAssignableTo<SabProvider>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_blackhole_as_active_client()
|
|
|
|
|
{
|
|
|
|
|
SetDownloadClient(DownloadClientType.Blackhole);
|
|
|
|
|
Mocker.Resolve<DownloadProvider>().GetActiveDownloadClient().Should().BeAssignableTo<BlackholeProvider>();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-14 00:36:16 +00:00
|
|
|
|
[Test, TestCaseSource("SabNamingCases")]
|
|
|
|
|
public void create_proper_sab_titles(int seasons, int[] episodes, string title, QualityTypes quality, bool proper, string expected)
|
2012-02-07 05:08:07 +00:00
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.Title = "My Series Name")
|
|
|
|
|
.Build();
|
|
|
|
|
|
2012-10-17 07:39:06 +00:00
|
|
|
|
var fakeEpisodes = new List<Episode>();
|
|
|
|
|
|
|
|
|
|
foreach(var episode in episodes)
|
2012-10-18 00:06:14 +00:00
|
|
|
|
fakeEpisodes.Add(Builder<Episode>
|
|
|
|
|
.CreateNew()
|
|
|
|
|
.With(e => e.EpisodeNumber = episode)
|
|
|
|
|
.With(e => e.Title = title)
|
|
|
|
|
.Build());
|
2012-10-17 07:39:06 +00:00
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
var parsResult = new EpisodeParseResult()
|
|
|
|
|
{
|
|
|
|
|
AirDate = DateTime.Now,
|
|
|
|
|
EpisodeNumbers = episodes.ToList(),
|
2012-10-13 21:15:21 +00:00
|
|
|
|
Quality = new QualityModel(quality, proper),
|
2012-02-07 05:08:07 +00:00
|
|
|
|
SeasonNumber = seasons,
|
|
|
|
|
Series = series,
|
2012-10-17 07:39:06 +00:00
|
|
|
|
EpisodeTitle = title,
|
|
|
|
|
Episodes = fakeEpisodes
|
2012-02-07 05:08:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-10-14 00:36:16 +00:00
|
|
|
|
Mocker.Resolve<DownloadProvider>().GetDownloadTitle(parsResult).Should().Be(expected);
|
2012-02-07 05:08:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(true, Result = "My Series Name - Season 1 [Bluray720p] [Proper]")]
|
|
|
|
|
[TestCase(false, Result = "My Series Name - Season 1 [Bluray720p]")]
|
|
|
|
|
public string create_proper_sab_season_title(bool proper)
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.Title = "My Series Name")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var parsResult = new EpisodeParseResult()
|
|
|
|
|
{
|
|
|
|
|
AirDate = DateTime.Now,
|
2012-10-13 21:15:21 +00:00
|
|
|
|
Quality = new QualityModel(QualityTypes.Bluray720p, proper),
|
2012-02-07 05:08:07 +00:00
|
|
|
|
SeasonNumber = 1,
|
|
|
|
|
Series = series,
|
|
|
|
|
EpisodeTitle = "My Episode Title",
|
|
|
|
|
FullSeason = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Mocker.Resolve<DownloadProvider>().GetDownloadTitle(parsResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(true, Result = "My Series Name - 2011-12-01 - My Episode Title [Bluray720p] [Proper]")]
|
|
|
|
|
[TestCase(false, Result = "My Series Name - 2011-12-01 - My Episode Title [Bluray720p]")]
|
|
|
|
|
public string create_proper_sab_daily_titles(bool proper)
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.With(c => c.SeriesType = SeriesType.Daily)
|
2012-02-07 05:08:07 +00:00
|
|
|
|
.With(c => c.Title = "My Series Name")
|
|
|
|
|
.Build();
|
|
|
|
|
|
2012-10-18 00:06:14 +00:00
|
|
|
|
var episode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.Title = "My Episode Title")
|
|
|
|
|
.Build();
|
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
var parsResult = new EpisodeParseResult
|
|
|
|
|
{
|
|
|
|
|
AirDate = new DateTime(2011, 12, 1),
|
2012-10-13 21:15:21 +00:00
|
|
|
|
Quality = new QualityModel(QualityTypes.Bluray720p, proper),
|
2012-02-07 05:08:07 +00:00
|
|
|
|
Series = series,
|
|
|
|
|
EpisodeTitle = "My Episode Title",
|
2012-10-18 00:06:14 +00:00
|
|
|
|
Episodes = new List<Episode>{ episode }
|
2012-02-07 05:08:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Mocker.Resolve<DownloadProvider>().GetDownloadTitle(parsResult);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-18 00:06:14 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_repeat_the_same_episode_title()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.Title = "My Series Name")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 5)
|
|
|
|
|
.TheFirst(1)
|
|
|
|
|
.With(e => e.Title = "My Episode Title (1)")
|
|
|
|
|
.TheLast(1)
|
|
|
|
|
.With(e => e.Title = "My Episode Title (2)")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var parsResult = new EpisodeParseResult
|
|
|
|
|
{
|
|
|
|
|
AirDate = DateTime.Now,
|
|
|
|
|
EpisodeNumbers = new List<int>{ 10, 11 },
|
2013-01-01 03:45:57 +00:00
|
|
|
|
Quality = new QualityModel(QualityTypes.HDTV720p, false),
|
2012-10-18 00:06:14 +00:00
|
|
|
|
SeasonNumber = 35,
|
|
|
|
|
Series = series,
|
|
|
|
|
Episodes = fakeEpisodes
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-01 03:45:57 +00:00
|
|
|
|
Mocker.Resolve<DownloadProvider>().GetDownloadTitle(parsResult).Should().Be("My Series Name - 5x01-5x02 - My Episode Title [HDTV-720p]");
|
2012-10-18 00:06:14 +00:00
|
|
|
|
}
|
2012-02-07 05:08:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|