more search cleanup.

pull/4/head
kay.one 12 years ago
parent ef5f565a4d
commit 40a959a309

@ -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);
}
}

@ -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.Test.Common;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
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();
}
}
}

@ -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);
}
}
}

@ -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());

@ -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,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
{

@ -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.Test.Common;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
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());

@ -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());
}
}
}

@ -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;

@ -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
{
}

@ -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" />

@ -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);
}
}
}

@ -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());
}
}
}

@ -7,9 +7,9 @@ using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.ExternalNotification;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Providers.Search;
namespace NzbDrone.Core
{

@ -1,23 +1,25 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Providers.Search
namespace NzbDrone.Core.IndexerSearch
{
public class DailyEpisodeSearch : SearchBase
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public DailyEpisodeSearch(IEpisodeService episodeService, DownloadProvider downloadProvider, IIndexerService indexerService,
SceneMappingService sceneMappingService, DownloadDirector downloadDirector,
ISceneMappingService sceneMappingService, IDownloadDirector downloadDirector,
ISeriesRepository seriesRepository)
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
downloadDirector)
@ -28,12 +30,11 @@ namespace NzbDrone.Core.Providers.Search
{
}
public override List<EpisodeParseResult> PerformSearch(Series series, dynamic options, ProgressNotification notification)
public override List<EpisodeParseResult> PerformSearch(Series series, List<Episode> episodes, ProgressNotification notification)
{
if (options.Episode == null)
throw new ArgumentException("Episode is invalid");
var episode = episodes.Single();
notification.CurrentMessage = "Looking for " + options.Episode;
notification.CurrentMessage = "Looking for " + episode;
var reports = new List<EpisodeParseResult>();
var title = GetSearchTitle(series);
@ -42,13 +43,13 @@ namespace NzbDrone.Core.Providers.Search
{
try
{
reports.AddRange(indexer.FetchDailyEpisode(title, options.Episode.AirDate));
reports.AddRange(indexer.FetchDailyEpisode(title, episode.AirDate.Value));
}
catch (Exception e)
{
logger.ErrorException(String.Format("An error has occurred while searching for {0} - {1:yyyy-MM-dd} from: {2}",
series.Title, options.Episode.AirDate, indexer.Name), e);
series.Title, episode.AirDate, indexer.Name), e);
}
});

@ -1,23 +1,24 @@
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.Indexers;
using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Providers.Search
namespace NzbDrone.Core.IndexerSearch
{
public class EpisodeSearch : SearchBase
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public EpisodeSearch(IEpisodeService episodeService, DownloadProvider downloadProvider, IIndexerService indexerService,
SceneMappingService sceneMappingService, DownloadDirector downloadDirector,
ISceneMappingService sceneMappingService, IDownloadDirector downloadDirector,
ISeriesRepository seriesRepository)
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
downloadDirector)
@ -28,29 +29,27 @@ namespace NzbDrone.Core.Providers.Search
{
}
public override List<EpisodeParseResult> PerformSearch(Series series, dynamic options, ProgressNotification notification)
public override List<EpisodeParseResult> PerformSearch(Series series, List<Episode> episodes, ProgressNotification notification)
{
//Todo: Daily and Anime or separate them out?
//Todo: Epsiodes that use scene numbering
if (options.Episode == null)
throw new ArgumentException("Episode is invalid");
var episode = episodes.Single();
notification.CurrentMessage = "Looking for " + options.Episode;
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;
if (series.UseSceneNumbering)
{
if (options.Episode.SceneSeasonNumber > 0 && options.Episode.SceneEpisodeNumber > 0)
if (episode.SceneSeasonNumber > 0 && episode.SceneEpisodeNumber > 0)
{
logger.Trace("Using Scene Numbering for: {0}", options.Episode);
seasonNumber = options.Episode.SceneSeasonNumber;
episodeNumber = options.Episode.SceneEpisodeNumber;
logger.Trace("Using Scene Numbering for: {0}", episode);
seasonNumber = episode.SceneSeasonNumber;
episodeNumber = episode.SceneEpisodeNumber;
}
}
@ -64,7 +63,7 @@ namespace NzbDrone.Core.Providers.Search
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.Episode.SeasonNumber, options.Episode.EpisodeNumber, indexer.Name), e);
series.Title, episode.SeasonNumber, episode.EpisodeNumber, indexer.Name), e);
}
});

@ -1,26 +1,24 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Providers.Search
namespace NzbDrone.Core.IndexerSearch
{
public class PartialSeasonSearch : SearchBase
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public PartialSeasonSearch(IEpisodeService episodeService, DownloadProvider downloadProvider, IIndexerService indexerService,
SceneMappingService sceneMappingService, DownloadDirector downloadDirector,
ISceneMappingService sceneMappingService, IDownloadDirector downloadDirector,
ISeriesRepository seriesRepository)
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
downloadDirector)
@ -31,20 +29,17 @@ namespace NzbDrone.Core.Providers.Search
{
}
public override List<EpisodeParseResult> PerformSearch(Series series, dynamic options, ProgressNotification notification)
public override List<EpisodeParseResult> PerformSearch(Series series, List<Episode> episodes, ProgressNotification notification)
{
if (options.SeasonNumber == null || options.SeasonNumber < 0)
throw new ArgumentException("SeasonNumber is invalid");
if (options.Episodes == null)
throw new ArgumentException("Episodes were not provided");
List<Episode> episodes = options.Episodes;
var seasons = episodes.Select(c => c.SeasonNumber).Distinct().ToList();
if (!episodes.Any())
throw new ArgumentException("Episodes were not provided");
if (seasons.Count > 1)
{
throw new ArgumentOutOfRangeException("episodes", "episode list contains episodes from more than one season");
}
notification.CurrentMessage = String.Format("Looking for {0} - Season {1}", series.Title, options.SeasonNumber);
var seasonNumber = seasons[0];
notification.CurrentMessage = String.Format("Looking for {0} - Season {1}", series.Title, seasonNumber);
var reports = new List<EpisodeParseResult>();
object reportsLock = new object();
@ -62,7 +57,7 @@ namespace NzbDrone.Core.Providers.Search
{
lock (reportsLock)
{
reports.AddRange(indexer.FetchPartialSeason(title, options.SeasonNumber, prefix));
reports.AddRange(indexer.FetchPartialSeason(title, seasonNumber, prefix));
}
}
@ -71,7 +66,7 @@ namespace NzbDrone.Core.Providers.Search
logger.ErrorException(
String.Format(
"An error has occurred while searching for {0} Season {1:00} Prefix: {2} from: {3}",
series.Title, options.SeasonNumber, prefix, indexer.Name),
series.Title, seasonNumber, prefix, indexer.Name),
e);
}
});

@ -1,17 +1,17 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.ReferenceData;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Providers.Search
namespace NzbDrone.Core.IndexerSearch
{
public abstract class SearchBase
{
@ -19,14 +19,14 @@ namespace NzbDrone.Core.Providers.Search
protected readonly IEpisodeService _episodeService;
protected readonly DownloadProvider _downloadProvider;
protected readonly IIndexerService _indexerService;
protected readonly SceneMappingService _sceneMappingService;
protected readonly DownloadDirector DownloadDirector;
protected readonly ISceneMappingService _sceneMappingService;
protected readonly IDownloadDirector DownloadDirector;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
protected SearchBase(ISeriesRepository seriesRepository, IEpisodeService episodeService, DownloadProvider downloadProvider,
IIndexerService indexerService, SceneMappingService sceneMappingService,
DownloadDirector downloadDirector)
IIndexerService indexerService, ISceneMappingService sceneMappingService,
IDownloadDirector downloadDirector)
{
_seriesRepository = seriesRepository;
_episodeService = episodeService;
@ -40,10 +40,10 @@ namespace NzbDrone.Core.Providers.Search
{
}
public abstract List<EpisodeParseResult> PerformSearch(Series series, dynamic options, ProgressNotification notification);
public abstract List<EpisodeParseResult> PerformSearch(Series series, List<Episode> episodes, ProgressNotification notification);
public abstract bool IsEpisodeMatch(Series series, dynamic options, EpisodeParseResult episodeParseResult);
public virtual List<Int32> Search(Series series, dynamic options, ProgressNotification notification)
public virtual List<int> Search(Series series, dynamic options, ProgressNotification notification)
{
if (options == null)
throw new ArgumentNullException(options);

@ -1,8 +1,8 @@
using System;
using NLog;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Search;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Jobs.Implementations

@ -11,13 +11,13 @@ namespace NzbDrone.Core.MetadataSource
{
public class TvRageMappingProvider
{
private readonly SceneMappingService _sceneMappingService;
private readonly ISceneMappingService _sceneMappingService;
private readonly TvRageProxy _tvRageProxy;
private readonly IEpisodeService _episodeService;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public TvRageMappingProvider(SceneMappingService sceneMappingService,
public TvRageMappingProvider(ISceneMappingService sceneMappingService,
TvRageProxy tvRageProxy, IEpisodeService episodeService)
{
_sceneMappingService = sceneMappingService;

@ -212,6 +212,10 @@
<Compile Include="Helpers\SabnzbdPriorityTypeConverter.cs" />
<Compile Include="Helpers\XElementHelper.cs" />
<Compile Include="History\HistoryRepository.cs" />
<Compile Include="IndexerSearch\DailyEpisodeSearch.cs" />
<Compile Include="IndexerSearch\EpisodeSearch.cs" />
<Compile Include="IndexerSearch\PartialSeasonSearch.cs" />
<Compile Include="IndexerSearch\SearchBase.cs" />
<Compile Include="Indexers\IndexerRepository.cs" />
<Compile Include="Indexers\NewznabRepository.cs" />
<Compile Include="Instrumentation\LogInjectionModule.cs" />
@ -322,10 +326,6 @@
<Compile Include="Indexers\Omgwtfnzbs.cs" />
<Compile Include="Indexers\Wombles.cs" />
<Compile Include="Providers\RecycleBinProvider.cs" />
<Compile Include="Providers\Search\DailyEpisodeSearch.cs" />
<Compile Include="Providers\Search\PartialSeasonSearch.cs" />
<Compile Include="Providers\Search\EpisodeSearch.cs" />
<Compile Include="Providers\Search\SearchBase.cs" />
<Compile Include="Tv\SeasonService.cs" />
<Compile Include="Instrumentation\TrimLogsJob.cs" />
<Compile Include="Lifecycle\AppUpdateJob.cs" />

@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Search;
namespace NzbDrone.Core.Providers
{

@ -5,7 +5,15 @@ using NzbDrone.Core.Lifecycle;
namespace NzbDrone.Core.ReferenceData
{
public class SceneMappingService : IInitializable
public interface ISceneMappingService
{
void UpdateMappings();
string GetSceneName(int tvdbId, int seasonNumber = -1);
Nullable<Int32> GetTvDbId(string cleanName);
string GetCleanName(int tvdbId);
}
public class SceneMappingService : IInitializable, ISceneMappingService
{
private readonly ISceneMappingRepository _repository;
private readonly ISceneMappingProxy _sceneMappingProxy;

Loading…
Cancel
Save