using System; using System.Collections.Generic; using FizzWare.NBuilder; using FluentValidation.Results; using Moq; using NUnit.Framework; using NzbDrone.Common.Http; using NzbDrone.Core.Indexers; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Tv; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.IndexerTests { [TestFixture] public class SeasonSearchFixture : TestBase { private Series _series; [SetUp] public void Setup() { _series = Builder.CreateNew().Build(); var response = new HttpResponse(null, new HttpHeader(), "", System.Net.HttpStatusCode.OK); Mocker.GetMock() .Setup(s => s.Get(It.IsAny())).Returns(response); } private IndexerBase WithIndexer(bool paging, int resultCount) { var results = Builder.CreateListOfSize(resultCount) .Build(); var indexer = Mocker.GetMock>(); 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.SupportedPageSize).Returns(paging ? 100 : 0); 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() { var indexer = WithIndexer(true, 25); Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitles = new List{_series.Title} }); Mocker.GetMock().Verify(v => v.Get(It.IsAny()), Times.Once()); } [Test] public void should_not_use_offset_for_sites_that_do_not_support_it() { var indexer = WithIndexer(false, 125); Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitles = new List { _series.Title } }); Mocker.GetMock().Verify(v => v.Get(It.IsAny()), Times.Once()); } [Test] public void should_not_use_offset_if_its_already_tried_10_times() { var indexer = WithIndexer(true, 100); Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitles = new List { _series.Title } }); Mocker.GetMock().Verify(v => v.Get(It.IsAny()), Times.Exactly(10)); } } public class TestIndexerSettings : IProviderConfig { public ValidationResult Validate() { throw new NotImplementedException(); } } }