more search cleanup.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model;
|
||||
@@ -8,45 +9,88 @@ using NzbDrone.Core.Test.Framework;
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class AllowedDownloadSpecificationFixture : CoreTest
|
||||
public class AllowedDownloadSpecificationFixture : CoreTest<DownloadDirector>
|
||||
{
|
||||
private EpisodeParseResult parseResult;
|
||||
private EpisodeParseResult _parseResult;
|
||||
|
||||
private Mock<IFetchableSpecification> pass1;
|
||||
private Mock<IFetchableSpecification> pass2;
|
||||
private Mock<IFetchableSpecification> pass3;
|
||||
private Mock<IFetchableSpecification> _pass1;
|
||||
private Mock<IFetchableSpecification> _pass2;
|
||||
private Mock<IFetchableSpecification> _pass3;
|
||||
|
||||
private Mock<IFetchableSpecification> fail1;
|
||||
private Mock<IFetchableSpecification> fail2;
|
||||
private Mock<IFetchableSpecification> fail3;
|
||||
private Mock<IFetchableSpecification> _fail1;
|
||||
private Mock<IFetchableSpecification> _fail2;
|
||||
private Mock<IFetchableSpecification> _fail3;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
pass1 = new Mock<IFetchableSpecification>();
|
||||
pass2 = new Mock<IFetchableSpecification>();
|
||||
pass3 = new Mock<IFetchableSpecification>();
|
||||
_pass1 = new Mock<IFetchableSpecification>();
|
||||
_pass2 = new Mock<IFetchableSpecification>();
|
||||
_pass3 = new Mock<IFetchableSpecification>();
|
||||
|
||||
fail1 = new Mock<IFetchableSpecification>();
|
||||
fail2 = new Mock<IFetchableSpecification>();
|
||||
fail3 = new Mock<IFetchableSpecification>();
|
||||
_fail1 = new Mock<IFetchableSpecification>();
|
||||
_fail2 = new Mock<IFetchableSpecification>();
|
||||
_fail3 = new Mock<IFetchableSpecification>();
|
||||
|
||||
pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(true);
|
||||
pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(true);
|
||||
pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(true);
|
||||
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(true);
|
||||
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(true);
|
||||
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(true);
|
||||
|
||||
fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||
fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||
fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||
|
||||
parseResult = new EpisodeParseResult();
|
||||
_parseResult = new EpisodeParseResult();
|
||||
|
||||
}
|
||||
|
||||
private void GivenSpecifications(params Mock<IFetchableSpecification>[] mocks)
|
||||
{
|
||||
Mocker.SetConstant(mocks.Select(c => c.Object));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_call_all_specifications()
|
||||
{
|
||||
throw new InvalidAsynchronousStateException();
|
||||
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
||||
|
||||
Subject.GetDownloadDecision(_parseResult);
|
||||
|
||||
_fail1.Verify(c => c.IsSatisfiedBy(_parseResult), Times.Once());
|
||||
_fail2.Verify(c => c.IsSatisfiedBy(_parseResult), Times.Once());
|
||||
_fail3.Verify(c => c.IsSatisfiedBy(_parseResult), Times.Once());
|
||||
_pass1.Verify(c => c.IsSatisfiedBy(_parseResult), Times.Once());
|
||||
_pass2.Verify(c => c.IsSatisfiedBy(_parseResult), Times.Once());
|
||||
_pass3.Verify(c => c.IsSatisfiedBy(_parseResult), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_rejected_if_one_of_specs_fail()
|
||||
{
|
||||
GivenSpecifications(_pass1, _fail1, _pass2, _pass3);
|
||||
|
||||
var result = Subject.GetDownloadDecision(_parseResult);
|
||||
|
||||
result.Approved.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_pass_if_all_specs_pass()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3);
|
||||
|
||||
var result = Subject.GetDownloadDecision(_parseResult);
|
||||
|
||||
result.Approved.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_same_number_of_rejections_as_specs_that_failed()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
||||
|
||||
var result = Subject.GetDownloadDecision(_parseResult);
|
||||
result.Rejections.Should().HaveCount(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-16
@@ -1,17 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Search;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.SearchTests.DailyEpisodeSearchTests
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests.DailyEpisodeSearchTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CheckReportFixture : TestBase
|
||||
public class IndexerDailyEpisodeSearchFixture : CoreTest<DailyEpisodeSearch>
|
||||
{
|
||||
private Series _series;
|
||||
private Episode _episode;
|
||||
@@ -43,8 +42,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests.DailyEpisodeSearchTests
|
||||
{
|
||||
_episodeParseResult.AirDate = null;
|
||||
|
||||
Mocker.Resolve<DailyEpisodeSearch>()
|
||||
.IsEpisodeMatch(_series, new { Episode = _episode }, _episodeParseResult).Should().BeFalse();
|
||||
Subject.IsEpisodeMatch(_series, new { Episode = _episode }, _episodeParseResult).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -52,18 +50,16 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests.DailyEpisodeSearchTests
|
||||
{
|
||||
_episodeParseResult.AirDate = _episode.AirDate.Value.AddDays(-10);
|
||||
|
||||
Mocker.Resolve<DailyEpisodeSearch>()
|
||||
.IsEpisodeMatch(_series, new { Episode = _episode }, _episodeParseResult)
|
||||
.Should()
|
||||
.BeFalse();
|
||||
Subject.IsEpisodeMatch(_series, new { Episode = _episode }, _episodeParseResult)
|
||||
.Should()
|
||||
.BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_return_error_when_airDates_match()
|
||||
{
|
||||
Mocker.Resolve<DailyEpisodeSearch>()
|
||||
.IsEpisodeMatch(_series, new { Episode = _episode }, _episodeParseResult)
|
||||
.Should().BeFalse();
|
||||
Subject.IsEpisodeMatch(_series, new {Episode = _episode}, _episodeParseResult)
|
||||
.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests.DailyEpisodeSearchTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class IndexerDailyEpisodeSearch_EpisodeMatch : IndexerSearchTestBase<DailyEpisodeSearch>
|
||||
{
|
||||
[Test]
|
||||
public void should_fetch_results_from_indexers()
|
||||
{
|
||||
WithValidIndexers();
|
||||
|
||||
|
||||
Subject.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_log_error_when_fetching_from_indexer_fails()
|
||||
{
|
||||
WithBrokenIndexers();
|
||||
|
||||
Mocker.Resolve<DailyEpisodeSearch>()
|
||||
.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(0);
|
||||
|
||||
ExceptionVerification.ExpectedErrors(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
-39
@@ -1,52 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Search;
|
||||
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.SearchTests.EpisodeSearchTests
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests.EpisodeSearchTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PerformSearchFixture : PerformSearchTestBase
|
||||
public class IndexerEpisodeSearchFixture : IndexerSearchTestBase<EpisodeSearch>
|
||||
{
|
||||
[Test]
|
||||
public void should_throw_if_episode_is_null()
|
||||
{
|
||||
Episode nullEpisode = null;
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
Mocker.Resolve<EpisodeSearch>()
|
||||
.PerformSearch(_series, new { Episode = nullEpisode }, notification));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fetch_results_from_indexers()
|
||||
{
|
||||
WithValidIndexers();
|
||||
|
||||
Mocker.Resolve<EpisodeSearch>()
|
||||
.PerformSearch(_series, new {Episode = _episode}, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
Subject
|
||||
.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_log_error_when_fetching_from_indexer_fails()
|
||||
{
|
||||
WithInvalidIndexers();
|
||||
WithBrokenIndexers();
|
||||
|
||||
Mocker.Resolve<EpisodeSearch>()
|
||||
.PerformSearch(_series, new { Episode = _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(0);
|
||||
Subject
|
||||
.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(0);
|
||||
|
||||
ExceptionVerification.ExpectedErrors(2);
|
||||
}
|
||||
@@ -60,10 +45,10 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests.EpisodeSearchTests
|
||||
|
||||
WithValidIndexers();
|
||||
|
||||
Mocker.Resolve<EpisodeSearch>()
|
||||
.PerformSearch(_series, new { Episode = _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
Subject
|
||||
.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
|
||||
_indexer1.Verify(v => v.FetchEpisode(_series.Title, 10, 5), Times.Once());
|
||||
_indexer2.Verify(v => v.FetchEpisode(_series.Title, 10, 5), Times.Once());
|
||||
@@ -78,10 +63,10 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests.EpisodeSearchTests
|
||||
|
||||
WithValidIndexers();
|
||||
|
||||
Mocker.Resolve<EpisodeSearch>()
|
||||
.PerformSearch(_series, new { Episode = _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
Subject
|
||||
.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
|
||||
_indexer1.Verify(v => v.FetchEpisode(_series.Title, _episode.SeasonNumber, _episode.EpisodeNumber), Times.Once());
|
||||
_indexer2.Verify(v => v.FetchEpisode(_series.Title, _episode.SeasonNumber, _episode.EpisodeNumber), Times.Once());
|
||||
@@ -94,10 +79,10 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests.EpisodeSearchTests
|
||||
|
||||
WithValidIndexers();
|
||||
|
||||
Mocker.Resolve<EpisodeSearch>()
|
||||
.PerformSearch(_series, new { Episode = _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
Subject
|
||||
.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
|
||||
_indexer1.Verify(v => v.FetchEpisode(_series.Title, _episode.SeasonNumber, _episode.EpisodeNumber), Times.Once());
|
||||
_indexer2.Verify(v => v.FetchEpisode(_series.Title, _episode.SeasonNumber, _episode.EpisodeNumber), Times.Once());
|
||||
+6
-6
@@ -1,16 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Search;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.SearchTests.EpisodeSearchTests
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests.EpisodeSearchTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CheckReportFixture : TestBase
|
||||
public class IndexerEpisodeSearch_EpisodeMatch : TestBase
|
||||
{
|
||||
private Series _series;
|
||||
private Episode _episode;
|
||||
@@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests.EpisodeSearchTests
|
||||
Mocker.Resolve<EpisodeSearch>()
|
||||
.IsEpisodeMatch(_series, new { Episode = _episode }, _episodeParseResult)
|
||||
.Should()
|
||||
.BeFalse();
|
||||
.BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
+1
-8
@@ -1,18 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.ReferenceData;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Search;
|
||||
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.SearchTests
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests
|
||||
{
|
||||
public class GetSearchTitleFixture : TestBase
|
||||
{
|
||||
+8
-18
@@ -1,25 +1,22 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.SearchTests
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests
|
||||
{
|
||||
public class PerformSearchTestBase : TestBase
|
||||
public abstract class IndexerSearchTestBase<TSearch> : CoreTest<TSearch>
|
||||
where TSearch : SearchBase
|
||||
{
|
||||
protected Series _series;
|
||||
protected Episode _episode;
|
||||
protected List<Episode> _episodes;
|
||||
protected ProgressNotification notification = new ProgressNotification("Testing");
|
||||
|
||||
protected Mock<IndexerBase> _indexer1;
|
||||
@@ -40,13 +37,6 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests
|
||||
.With(e => e.Series = _series)
|
||||
.Build();
|
||||
|
||||
_episodes = Builder<Episode>
|
||||
.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(e => e.SeriesId = _series.Id)
|
||||
.With(e => e.Series = _series)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
_parseResults = Builder<EpisodeParseResult>
|
||||
.CreateListOfSize(10)
|
||||
@@ -78,7 +68,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests
|
||||
.Returns(_parseResults);
|
||||
}
|
||||
|
||||
protected void WithInvalidIndexers()
|
||||
protected void WithBrokenIndexers()
|
||||
{
|
||||
_indexer1.Setup(c => c.FetchEpisode(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
||||
.Throws(new Exception());
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests.PartialSeasonSearchTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PartialSeasonSearchFixture : IndexerSearchTestBase<PartialSeasonSearch>
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void should_fetch_results_from_indexers()
|
||||
{
|
||||
WithValidIndexers();
|
||||
|
||||
Subject.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_log_error_when_fetching_from_indexer_fails()
|
||||
{
|
||||
WithBrokenIndexers();
|
||||
|
||||
Subject.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(0);
|
||||
|
||||
ExceptionVerification.ExpectedErrors(4);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_hit_each_indexer_once_for_each_prefix()
|
||||
{
|
||||
WithValidIndexers();
|
||||
|
||||
Subject.PerformSearch(_series, new List<Episode> { _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
|
||||
_indexer1.Verify(v => v.FetchPartialSeason(_series.Title, 1, 0), Times.Once());
|
||||
_indexer1.Verify(v => v.FetchPartialSeason(_series.Title, 1, 1), Times.Once());
|
||||
_indexer2.Verify(v => v.FetchPartialSeason(_series.Title, 1, 0), Times.Once());
|
||||
_indexer2.Verify(v => v.FetchPartialSeason(_series.Title, 1, 1), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-6
@@ -1,18 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Search;
|
||||
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.SearchTests.PartialSeasonSearchTests
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests.PartialSeasonSearchTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CheckReportFixture : TestBase
|
||||
public class PartialSeasonSearch_EpisodeMatch : TestBase
|
||||
{
|
||||
private Series _series;
|
||||
private List<Episode> _episodes;
|
||||
+5
-1
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
@@ -230,3 +230,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests
|
||||
{
|
||||
}
|
||||
+12
-14
@@ -1,41 +1,39 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.ReferenceData;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Providers.Search;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.SearchTests
|
||||
namespace NzbDrone.Core.Test.IndexerSearchTests
|
||||
{
|
||||
public class TestSearch : SearchBase
|
||||
{
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public TestSearch(ISeriesService seriesService, IEpisodeService episodeService, DownloadProvider downloadProvider,
|
||||
IIndexerService indexerService, SceneMappingService sceneMappingService,
|
||||
IIndexerService indexerService, ISceneMappingService sceneMappingService,
|
||||
DownloadDirector downloadDirector, ISeriesRepository seriesRepository)
|
||||
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
|
||||
downloadDirector)
|
||||
{
|
||||
}
|
||||
|
||||
public override List<EpisodeParseResult> PerformSearch(Series series, dynamic options, Model.Notification.ProgressNotification notification)
|
||||
public override List<EpisodeParseResult> PerformSearch(Series series, List<Episode> episodes, Model.Notification.ProgressNotification notification)
|
||||
{
|
||||
if (options.Episode == null)
|
||||
throw new ArgumentException("Episode is invalid");
|
||||
|
||||
notification.CurrentMessage = "Looking for " + options.Episode;
|
||||
var episode = episodes.Single();
|
||||
|
||||
var reports = new List<EpisodeParseResult>();
|
||||
var title = GetSearchTitle(series);
|
||||
|
||||
var seasonNumber = options.Episode.SeasonNumber;
|
||||
var episodeNumber = options.Episode.EpisodeNumber;
|
||||
var seasonNumber = episode.SeasonNumber;
|
||||
var episodeNumber = episode.EpisodeNumber;
|
||||
|
||||
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
|
||||
{
|
||||
@@ -47,7 +45,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.ErrorException(String.Format("An error has occurred while searching for {0}-S{1:00}E{2:00} from: {3}",
|
||||
series.Title, options.SeasonNumber, options.EpisodeNumber, indexer.Name), e);
|
||||
series.Title, episode.SeasonNumber, episode.EpisodeNumber, indexer.Name), e);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -136,6 +136,16 @@
|
||||
<Compile Include="Framework\CoreTest.cs" />
|
||||
<Compile Include="Framework\ObjectDbTest.cs" />
|
||||
<Compile Include="HelperTests\XElementHelperTests\ConvertToTFixture.cs" />
|
||||
<Compile Include="IndexerSearchTests\DailyEpisodeSearchTests\IndexerDailyEpisodeSearchFixture.cs" />
|
||||
<Compile Include="IndexerSearchTests\DailyEpisodeSearchTests\IndexerDailyEpisodeSearch_EpisodeMatch.cs" />
|
||||
<Compile Include="IndexerSearchTests\EpisodeSearchTests\IndexerEpisodeSearchFixture.cs" />
|
||||
<Compile Include="IndexerSearchTests\EpisodeSearchTests\IndexerEpisodeSearch_EpisodeMatch.cs" />
|
||||
<Compile Include="IndexerSearchTests\GetSearchTitleFixture.cs" />
|
||||
<Compile Include="IndexerSearchTests\IndexerSearchTestBase.cs" />
|
||||
<Compile Include="IndexerSearchTests\PartialSeasonSearchTests\PartialSeasonSearchFixture.cs" />
|
||||
<Compile Include="IndexerSearchTests\PartialSeasonSearchTests\PartialSeasonSearch_EpisodeMatch.cs" />
|
||||
<Compile Include="IndexerSearchTests\ProcessResultsFixture.cs" />
|
||||
<Compile Include="IndexerSearchTests\TestSearch.cs" />
|
||||
<Compile Include="IndexerTests\NzbxFixture.cs" />
|
||||
<Compile Include="JobTests\JobRepositoryFixture.cs" />
|
||||
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />
|
||||
@@ -146,16 +156,6 @@
|
||||
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\QueueFixture.cs" />
|
||||
<Compile Include="ProviderTests\DownloadProviderTests\ContainsRecentEpisode.cs" />
|
||||
<Compile Include="RootFolderTests\FreeSpaceOnDrivesFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\ProcessResultsFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\DailyEpisodeSearchTests\CheckReportFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\EpisodeSearchTests\CheckReportFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\EpisodeSearchTests\PerformSearchFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\GetSearchTitleFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\DailyEpisodeSearchTests\PerformSearchFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\PartialSeasonSearchTests\CheckReportFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\PartialSeasonSearchTests\PerformSearchFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\PerformSearchTestBase.cs" />
|
||||
<Compile Include="ProviderTests\SearchTests\TestSearch.cs" />
|
||||
<Compile Include="ProviderTests\TvRageMappingProviderTests\FindMatchingTvRageSeriesFixture.cs" />
|
||||
<Compile Include="ProviderTests\TvRageMappingProviderTests\ProcessResultsFixture.cs" />
|
||||
<Compile Include="ProviderTests\TvRageProviderTests\GetSeriesFixture.cs" />
|
||||
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Search;
|
||||
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.SearchTests.DailyEpisodeSearchTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PerformSearchFixture : PerformSearchTestBase
|
||||
{
|
||||
[Test]
|
||||
public void should_throw_if_episode_is_null()
|
||||
{
|
||||
Episode nullEpisode = null;
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
Mocker.Resolve<DailyEpisodeSearch>()
|
||||
.PerformSearch(_series, new { Episode = nullEpisode }, notification));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fetch_results_from_indexers()
|
||||
{
|
||||
WithValidIndexers();
|
||||
|
||||
Mocker.Resolve<DailyEpisodeSearch>()
|
||||
.PerformSearch(_series, new {Episode = _episode}, notification)
|
||||
.Should()
|
||||
.HaveCount(20);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_log_error_when_fetching_from_indexer_fails()
|
||||
{
|
||||
WithInvalidIndexers();
|
||||
|
||||
Mocker.Resolve<DailyEpisodeSearch>()
|
||||
.PerformSearch(_series, new { Episode = _episode }, notification)
|
||||
.Should()
|
||||
.HaveCount(0);
|
||||
|
||||
ExceptionVerification.ExpectedErrors(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Search;
|
||||
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.SearchTests.PartialSeasonSearchTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PerformSearchFixture : PerformSearchTestBase
|
||||
{
|
||||
[Test]
|
||||
public void should_throw_if_season_number_is_less_than_zero()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
Mocker.Resolve<PartialSeasonSearch>()
|
||||
.PerformSearch(_series, new
|
||||
{
|
||||
SeasonNumber = -1,
|
||||
Episodes = new List<Episode>{ new Episode() }
|
||||
}, notification));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_episodes_is_empty()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
Mocker.Resolve<PartialSeasonSearch>()
|
||||
.PerformSearch(_series, new { SeasonNumber = 10, Episodes = new List<Episode>() }, notification));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fetch_results_from_indexers()
|
||||
{
|
||||
WithValidIndexers();
|
||||
|
||||
Mocker.Resolve<PartialSeasonSearch>()
|
||||
.PerformSearch(_series, new { SeasonNumber = 1, Episodes = _episodes }, notification)
|
||||
.Should()
|
||||
.HaveCount(40);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_log_error_when_fetching_from_indexer_fails()
|
||||
{
|
||||
WithInvalidIndexers();
|
||||
|
||||
Mocker.Resolve<PartialSeasonSearch>()
|
||||
.PerformSearch(_series, new { SeasonNumber = 1, Episodes = _episodes }, notification)
|
||||
.Should()
|
||||
.HaveCount(0);
|
||||
|
||||
ExceptionVerification.ExpectedErrors(4);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_hit_each_indexer_once_for_each_prefix()
|
||||
{
|
||||
WithValidIndexers();
|
||||
|
||||
Mocker.Resolve<PartialSeasonSearch>()
|
||||
.PerformSearch(_series, new { SeasonNumber = 1, Episodes = _episodes }, notification)
|
||||
.Should()
|
||||
.HaveCount(40);
|
||||
|
||||
_indexer1.Verify(v => v.FetchPartialSeason(_series.Title, 1, 0), Times.Once());
|
||||
_indexer1.Verify(v => v.FetchPartialSeason(_series.Title, 1, 1), Times.Once());
|
||||
_indexer2.Verify(v => v.FetchPartialSeason(_series.Title, 1, 0), Times.Once());
|
||||
_indexer2.Verify(v => v.FetchPartialSeason(_series.Title, 1, 1), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user