2014-01-14 03:47:45 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using FizzWare.NBuilder;
|
2014-01-14 19:58:53 +00:00
|
|
|
|
using FluentValidation.Results;
|
2014-01-14 03:47:45 +00:00
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common;
|
2014-05-11 04:37:07 +00:00
|
|
|
|
using NzbDrone.Common.Http;
|
2014-01-14 03:47:45 +00:00
|
|
|
|
using NzbDrone.Core.Indexers;
|
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2014-01-14 19:58:53 +00:00
|
|
|
|
using NzbDrone.Core.ThingiProvider;
|
2014-01-14 03:47:45 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.IndexerTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class SeasonSearchFixture : TestBase<FetchFeedService>
|
|
|
|
|
{
|
|
|
|
|
private Series _series;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
_series = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
2014-01-14 19:58:53 +00:00
|
|
|
|
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())).Returns("<xml></xml>");
|
2014-01-14 03:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-14 19:58:53 +00:00
|
|
|
|
private IndexerBase<TestIndexerSettings> WithIndexer(bool paging, int resultCount)
|
2014-01-14 03:47:45 +00:00
|
|
|
|
{
|
2014-01-14 19:58:53 +00:00
|
|
|
|
var results = Builder<ReleaseInfo>.CreateListOfSize(resultCount)
|
2014-01-14 03:47:45 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
2014-01-14 19:58:53 +00:00
|
|
|
|
var indexer = Mocker.GetMock<IndexerBase<TestIndexerSettings>>();
|
2014-01-14 03:47:45 +00:00
|
|
|
|
|
2014-01-14 19:58:53 +00:00
|
|
|
|
indexer.Setup(s => s.Parser.Process(It.IsAny<String>(), It.IsAny<String>()))
|
|
|
|
|
.Returns(results);
|
|
|
|
|
|
|
|
|
|
indexer.Setup(s => s.GetSeasonSearchUrls(It.IsAny<String>(), It.IsAny<Int32>(), It.IsAny<Int32>(), It.IsAny<Int32>()))
|
|
|
|
|
.Returns(new List<string> { "http://www.nzbdrone.com" });
|
|
|
|
|
|
2014-04-19 15:09:22 +00:00
|
|
|
|
indexer.SetupGet(s => s.SupportedPageSize).Returns(paging ? 100 : 0);
|
2014-01-14 19:58:53 +00:00
|
|
|
|
|
|
|
|
|
var definition = new IndexerDefinition();
|
|
|
|
|
definition.Name = "Test";
|
|
|
|
|
|
|
|
|
|
indexer.SetupGet(s => s.Definition)
|
|
|
|
|
.Returns(definition);
|
|
|
|
|
|
|
|
|
|
return indexer.Object;
|
2014-01-14 03:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_use_offset_if_result_count_is_less_than_90()
|
|
|
|
|
{
|
2014-01-14 19:58:53 +00:00
|
|
|
|
var indexer = WithIndexer(true, 25);
|
|
|
|
|
Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitle = _series.Title });
|
2014-01-14 03:47:45 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IHttpProvider>().Verify(v => v.DownloadString(It.IsAny<String>()), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_use_offset_for_sites_that_do_not_support_it()
|
|
|
|
|
{
|
2014-01-14 19:58:53 +00:00
|
|
|
|
var indexer = WithIndexer(false, 125);
|
|
|
|
|
Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitle = _series.Title });
|
2014-01-14 03:47:45 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IHttpProvider>().Verify(v => v.DownloadString(It.IsAny<String>()), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_use_offset_if_its_already_tried_10_times()
|
|
|
|
|
{
|
2014-01-14 19:58:53 +00:00
|
|
|
|
var indexer = WithIndexer(true, 100);
|
|
|
|
|
Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitle = _series.Title });
|
2014-01-14 03:47:45 +00:00
|
|
|
|
|
2014-01-16 03:43:49 +00:00
|
|
|
|
Mocker.GetMock<IHttpProvider>().Verify(v => v.DownloadString(It.IsAny<String>()), Times.Exactly(10));
|
2014-01-14 03:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-14 19:58:53 +00:00
|
|
|
|
|
|
|
|
|
public class TestIndexerSettings : IProviderConfig
|
|
|
|
|
{
|
|
|
|
|
public ValidationResult Validate()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-14 03:47:45 +00:00
|
|
|
|
}
|