From 0ae0bd43be3a4ceb603ccb5b3943f117613b1aa5 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Wed, 19 Nov 2014 20:04:47 +0100 Subject: [PATCH] Implemented indexer integration tests for a couple of public indexers. --- .../IndexerIntegrationTests.cs | 179 ++++++++++++++++-- 1 file changed, 160 insertions(+), 19 deletions(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs b/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs index 443e998b5..cd2fcd964 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs @@ -1,70 +1,211 @@ using System.Collections.Generic; +using System.Linq; using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common; using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers.Eztv; +using NzbDrone.Core.Indexers.Fanzub; +using NzbDrone.Core.Indexers.KickassTorrents; using NzbDrone.Core.Indexers.Newznab; +using NzbDrone.Core.Indexers.Nyaa; using NzbDrone.Core.Indexers.Wombles; +using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; -using NUnit.Framework; using NzbDrone.Core.ThingiProvider; using NzbDrone.Test.Common.Categories; -using System.Linq; namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests { [IntegrationTest] - public class IndexerIntegrationTests : CoreTest + public class IndexerIntegrationTests : CoreTest { + private SingleEpisodeSearchCriteria _singleSearchCriteria; + private AnimeEpisodeSearchCriteria _animeSearchCriteria; + [SetUp] public void SetUp() { UseRealHttp(); + + _singleSearchCriteria = new SingleEpisodeSearchCriteria() + { + SceneTitles = new List { "Person of Interest" }, + SeasonNumber = 1, + EpisodeNumber = 1 + }; + + _animeSearchCriteria = new AnimeEpisodeSearchCriteria() + { + SceneTitles = new List { "Steins;Gate" }, + AbsoluteEpisodeNumber = 1 + }; + } + + [Test] + public void wombles_fetch_recent() + { + var indexer = Mocker.Resolve(); + + indexer.Definition = new IndexerDefinition + { + Name = "MyIndexer", + Settings = NullConfig.Instance + }; + + var result = indexer.FetchRecent(); + + ValidateResult(result); + } + + [Test] + public void fanzub_fetch_recent() + { + Assert.Inconclusive("Fanzub Down"); + + var indexer = Mocker.Resolve(); + + indexer.Definition = new IndexerDefinition + { + Name = "MyIndexer", + Settings = NullConfig.Instance + }; + + var result = indexer.FetchRecent(); + + ValidateResult(result); } [Test] - public void wombles_rss() + public void fanzub_search_single() { - Subject.Definition = new IndexerDefinition + Assert.Inconclusive("Fanzub Down"); + + var indexer = Mocker.Resolve(); + + indexer.Definition = new IndexerDefinition { - Name = "Wombles", + Name = "MyIndexer", Settings = NullConfig.Instance }; - var result = Subject.FetchRecent(); + var result = indexer.Fetch(_animeSearchCriteria); - ValidateResult(result, skipSize: true, skipInfo: true); + ValidateResult(result); } - private void ValidateResult(IList reports, bool skipSize = false, bool skipInfo = false) + [Test] + public void kickass_fetch_recent() + { + var indexer = Mocker.Resolve(); + + indexer.Definition = new IndexerDefinition + { + Name = "MyIndexer", + Settings = new KickassTorrentsSettings() + }; + + var result = indexer.FetchRecent(); + + ValidateTorrentResult(result, hasSize: true); + } + + [Test] + public void kickass_search_single() + { + var indexer = Mocker.Resolve(); + + indexer.Definition = new IndexerDefinition + { + Name = "MyIndexer", + Settings = new KickassTorrentsSettings() + }; + + var result = indexer.Fetch(_singleSearchCriteria); + + ValidateTorrentResult(result, hasSize: true, hasMagnet: true); + } + + [Test] + public void eztv_fetch_recent() + { + var indexer = Mocker.Resolve(); + + indexer.Definition = new IndexerDefinition + { + Name = "MyIndexer", + Settings = new EztvSettings() + }; + + var result = indexer.FetchRecent(); + + ValidateTorrentResult(result, hasSize: true, hasMagnet: true); + } + + [Test] + public void nyaa_fetch_recent() + { + var indexer = Mocker.Resolve(); + + indexer.Definition = new IndexerDefinition + { + Name = "MyIndexer", + Settings = new NyaaSettings() + }; + + var result = indexer.FetchRecent(); + + ValidateTorrentResult(result, hasSize: true); + } + + [Test] + public void nyaa_search_single() + { + var indexer = Mocker.Resolve(); + + indexer.Definition = new IndexerDefinition + { + Name = "MyIndexer", + Settings = new NyaaSettings() + }; + + var result = indexer.Fetch(_animeSearchCriteria); + + ValidateTorrentResult(result, hasSize: true); + } + + private void ValidateResult(IList reports, bool hasSize = false, bool hasInfoUrl = false) { reports.Should().NotBeEmpty(); - reports.Should().NotContain(c => string.IsNullOrWhiteSpace(c.Title)); - reports.Should().NotContain(c => string.IsNullOrWhiteSpace(c.DownloadUrl)); + reports.Should().OnlyContain(c => c.Title.IsNotNullOrWhiteSpace()); reports.Should().OnlyContain(c => c.PublishDate.Year > 2000); + reports.Should().OnlyContain(c => c.DownloadUrl.IsNotNullOrWhiteSpace()); reports.Should().OnlyContain(c => c.DownloadUrl.StartsWith("http")); - if (!skipInfo) + if (hasInfoUrl) { - reports.Should().NotContain(c => string.IsNullOrWhiteSpace(c.InfoUrl)); + reports.Should().OnlyContain(c => c.InfoUrl.IsNotNullOrWhiteSpace()); } - if (!skipSize) + if (hasSize) { reports.Should().OnlyContain(c => c.Size > 0); } } - private void ValidateTorrentResult(IList reports, bool skipSize = false, bool skipInfo = false) + private void ValidateTorrentResult(IList reports, bool hasSize = false, bool hasInfoUrl = false, bool hasMagnet = false) { reports.Should().OnlyContain(c => c.GetType() == typeof(TorrentInfo)); - ValidateResult(reports, skipSize, skipInfo); + ValidateResult(reports, hasSize, hasInfoUrl); - reports.Should().OnlyContain(c => c.DownloadUrl.EndsWith(".torrent")); + reports.Should().OnlyContain(c => c.DownloadProtocol == DownloadProtocol.Torrent); - reports.Cast().Should().OnlyContain(c => c.MagnetUrl.StartsWith("magnet:")); - reports.Cast().Should().NotContain(c => string.IsNullOrWhiteSpace(c.InfoHash)); + if (hasMagnet) + { + reports.Cast().Should().OnlyContain(c => c.MagnetUrl.StartsWith("magnet:")); + } } }