From c50fb84216c3d69eea110306b6cea4bb80e3a855 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 14 Jan 2014 11:58:53 -0800 Subject: [PATCH] Some test cleanup for season search --- .../IndexerIntegrationTests.cs | 1 - .../IndexerTests/SeasonSearchFixture.cs | 73 +++++++++---------- .../Indexers/IndexerFetchService.cs | 6 +- .../Indexers/IndexerParsingService.cs | 18 ----- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 - 5 files changed, 37 insertions(+), 62 deletions(-) delete mode 100644 src/NzbDrone.Core/Indexers/IndexerParsingService.cs diff --git a/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs b/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs index 2857add44..1d12f233e 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/IntegrationTests/IndexerIntegrationTests.cs @@ -20,7 +20,6 @@ namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests public void SetUp() { UseRealHttp(); - Mocker.SetConstant(new IndexerParsingService()); } [Test] diff --git a/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs index 7c8a87485..0d35576d2 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs @@ -1,17 +1,14 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Runtime.Remoting.Messaging; -using System.Text; using FizzWare.NBuilder; +using FluentValidation.Results; using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Indexers; -using NzbDrone.Core.Indexers.Newznab; -using NzbDrone.Core.Indexers.Omgwtfnzbs; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Tv; using NzbDrone.Test.Common; @@ -21,52 +18,44 @@ namespace NzbDrone.Core.Test.IndexerTests public class SeasonSearchFixture : TestBase { private Series _series; - private IIndexer _newznab; - private IIndexer _omgwtfnzbs; [SetUp] public void Setup() { _series = Builder.CreateNew().Build(); - _newznab = new Newznab(); - - _newznab.Definition = new IndexerDefinition(); - _newznab.Definition.Name = "nzbs.org"; - _newznab.Definition.Settings = new NewznabSettings - { - ApiKey = "", - Url = "http://nzbs.org" - }; - - _omgwtfnzbs = new Omgwtfnzbs(); - - _omgwtfnzbs.Definition = new IndexerDefinition(); - _omgwtfnzbs.Definition.Name = "omgwtfnzbs"; - _omgwtfnzbs.Definition.Settings = new OmgwtfnzbsSettings - { - ApiKey = "", - Username = "NzbDrone" - }; + Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())).Returns(""); } - private void WithResults(int count) + private IndexerBase WithIndexer(bool paging, int resultCount) { - var results = Builder.CreateListOfSize(count) + var results = Builder.CreateListOfSize(resultCount) .Build(); - Mocker.GetMock() - .Setup(s => s.Parse(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(results); + var indexer = Mocker.GetMock>(); - Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())).Returns(""); + indexer.Setup(s => s.Parser.Process(It.IsAny(), It.IsAny())) + .Returns(results); + + indexer.Setup(s => s.GetSeasonSearchUrls(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(new List { "http://www.nzbdrone.com" }); + + indexer.SetupGet(s => s.SupportsPaging).Returns(paging); + + var definition = new IndexerDefinition(); + definition.Name = "Test"; + + indexer.SetupGet(s => s.Definition) + .Returns(definition); + + return indexer.Object; } [Test] public void should_not_use_offset_if_result_count_is_less_than_90() { - WithResults(25); - Subject.Fetch(_newznab, new SeasonSearchCriteria { Series = _series, SceneTitle = _series.Title }); + var indexer = WithIndexer(true, 25); + Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitle = _series.Title }); Mocker.GetMock().Verify(v => v.DownloadString(It.IsAny()), Times.Once()); } @@ -74,8 +63,8 @@ namespace NzbDrone.Core.Test.IndexerTests [Test] public void should_not_use_offset_for_sites_that_do_not_support_it() { - WithResults(25); - Subject.Fetch(_omgwtfnzbs, new SeasonSearchCriteria { Series = _series, SceneTitle = _series.Title }); + var indexer = WithIndexer(false, 125); + Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitle = _series.Title }); Mocker.GetMock().Verify(v => v.DownloadString(It.IsAny()), Times.Once()); } @@ -83,10 +72,18 @@ namespace NzbDrone.Core.Test.IndexerTests [Test] public void should_not_use_offset_if_its_already_tried_10_times() { - WithResults(100); - Subject.Fetch(_newznab, new SeasonSearchCriteria { Series = _series, SceneTitle = _series.Title }); + var indexer = WithIndexer(true, 100); + Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitle = _series.Title }); Mocker.GetMock().Verify(v => v.DownloadString(It.IsAny()), Times.Exactly(11)); } } + + public class TestIndexerSettings : IProviderConfig + { + public ValidationResult Validate() + { + throw new NotImplementedException(); + } + } } diff --git a/src/NzbDrone.Core/Indexers/IndexerFetchService.cs b/src/NzbDrone.Core/Indexers/IndexerFetchService.cs index 8dc19cd35..089559701 100644 --- a/src/NzbDrone.Core/Indexers/IndexerFetchService.cs +++ b/src/NzbDrone.Core/Indexers/IndexerFetchService.cs @@ -22,12 +22,10 @@ namespace NzbDrone.Core.Indexers { private readonly Logger _logger; private readonly IHttpProvider _httpProvider; - private readonly IIndexerParsingService _indexerParsingService; - public FetchFeedService(IHttpProvider httpProvider, IIndexerParsingService indexerParsingService, Logger logger) + public FetchFeedService(IHttpProvider httpProvider, Logger logger) { _httpProvider = httpProvider; - _indexerParsingService = indexerParsingService; _logger = logger; } @@ -107,7 +105,7 @@ namespace NzbDrone.Core.Indexers var xml = _httpProvider.DownloadString(url); if (!string.IsNullOrWhiteSpace(xml)) { - result.AddRange(_indexerParsingService.Parse(indexer, xml, url)); + result.AddRange(indexer.Parser.Process(xml, url)); } else { diff --git a/src/NzbDrone.Core/Indexers/IndexerParsingService.cs b/src/NzbDrone.Core/Indexers/IndexerParsingService.cs deleted file mode 100644 index 09530baae..000000000 --- a/src/NzbDrone.Core/Indexers/IndexerParsingService.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; -using NzbDrone.Core.Parser.Model; - -namespace NzbDrone.Core.Indexers -{ - public interface IIndexerParsingService - { - IEnumerable Parse(IIndexer indexer, string xml, string url); - } - - public class IndexerParsingService : IIndexerParsingService - { - public IEnumerable Parse(IIndexer indexer, string xml, string url) - { - return indexer.Parser.Process(xml, url); - } - } -} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index cda67438f..7967454d8 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -270,7 +270,6 @@ -