Searching will be more picky now to ensure the proper series and season (and episode if relevant)

This commit is contained in:
Mark McDowall 2011-11-16 22:32:44 -08:00
parent 067d735448
commit 30e21ecd16
5 changed files with 507 additions and 52 deletions

View File

@ -26,9 +26,18 @@ namespace NzbDrone.Core.Test.ProviderTests
public void processResults_ParseResult_should_return_after_match()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
.TheFirst(1)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int>{1})
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var series = Builder<Series>.CreateNew().Build();
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = series.SeriesId)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -39,7 +48,9 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker.GetMock<DownloadProvider>()
.Setup(c => c.DownloadReport(It.IsAny<EpisodeParseResult>())).Returns(true);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
@ -51,16 +62,24 @@ namespace NzbDrone.Core.Test.ProviderTests
Times.Once());
}
[Test]
public void processResults_higher_quality_should_be_called_first()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(10)
.All().With(c => c.Quality = new Quality(QualityTypes.DVD, true))
.Random(1).With(c => c.Quality = new Quality(QualityTypes.Bluray1080p, true))
.Random(1)
.With(c => c.Quality = new Quality(QualityTypes.Bluray1080p, true))
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int> { 1 })
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var series = Builder<Series>.CreateNew().Build();
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = series.SeriesId)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -76,6 +95,9 @@ namespace NzbDrone.Core.Test.ProviderTests
c.DownloadReport(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.Bluray1080p)))
.Returns(true);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
@ -87,18 +109,26 @@ namespace NzbDrone.Core.Test.ProviderTests
Times.Once());
}
[Test]
public void processResults_when_same_quality_proper_should_be_called_first()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(20)
.All().With(c => c.Quality = new Quality(QualityTypes.DVD, false))
.All()
.With(c => c.Quality = new Quality(QualityTypes.DVD, false))
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int> { 1 })
.Random(1).With(c => c.Quality = new Quality(QualityTypes.DVD, true))
.Build();
parseResults.Where(c => c.Quality.Proper).Should().HaveCount(1);
var episode = Builder<Episode>.CreateNew().Build();
var series = Builder<Series>.CreateNew().Build();
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = series.SeriesId)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -108,6 +138,8 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker.GetMock<DownloadProvider>()
.Setup(c => c.DownloadReport(It.Is<EpisodeParseResult>(p => p.Quality.Proper))).Returns(true);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
@ -120,20 +152,31 @@ namespace NzbDrone.Core.Test.ProviderTests
Times.Once());
}
[Test]
public void processResults_when_not_needed_should_check_the_rest()
public void processResults_when_quality_is_not_needed_should_check_the_rest()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.All()
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int> { 1 })
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var series = Builder<Series>.CreateNew().Build();
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = series.SeriesId)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
@ -144,20 +187,31 @@ namespace NzbDrone.Core.Test.ProviderTests
ExceptionVerification.ExcpectedWarns(1);
}
[Test]
public void processResults_failed_IsNeeded_should_check_the_rest()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.All()
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int> { 1 })
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var series = Builder<Series>.CreateNew().Build();
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = series.SeriesId)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Throws(new Exception());
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
@ -173,9 +227,18 @@ namespace NzbDrone.Core.Test.ProviderTests
public void processResults_failed_download_should_not_check_the_rest()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.All()
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int> { 1 })
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var series = Builder<Series>.CreateNew().Build();
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = series.SeriesId)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -185,6 +248,9 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker.GetMock<DownloadProvider>()
.Setup(c => c.DownloadReport(It.IsAny<EpisodeParseResult>())).Throws(new Exception());
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
@ -205,8 +271,11 @@ namespace NzbDrone.Core.Test.ProviderTests
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var series = Builder<Series>.CreateNew()
.Build();
var episode = Builder<Episode>.CreateNew()
.With(c => c.Series = Builder<Series>.CreateNew().Build())
.With(c => c.Series = series)
.With(c => c.SeasonNumber = 12)
.Build();
@ -216,6 +285,9 @@ namespace NzbDrone.Core.Test.ProviderTests
.Setup(c => c.GetEpisode(episode.EpisodeId))
.Returns(episode);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
var indexer1 = new Mock<IndexerBase>();
indexer1.Setup(c => c.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber))
.Returns(parseResults).Verifiable();
@ -234,9 +306,6 @@ namespace NzbDrone.Core.Test.ProviderTests
.Setup(c => c.GetSeries(It.IsAny<int>()))
.Returns(episode.Series);
mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
mocker.GetMock<SceneMappingProvider>()
.Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
@ -246,8 +315,7 @@ namespace NzbDrone.Core.Test.ProviderTests
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Exactly(8));
ExceptionVerification.ExcpectedWarns(1);
indexer1.VerifyAll();
indexer2.VerifyAll();
@ -259,8 +327,11 @@ namespace NzbDrone.Core.Test.ProviderTests
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var series = Builder<Series>.CreateNew().With(s => s.SeriesId = 71256)
.Build();
var episode = Builder<Episode>.CreateNew()
.With(c => c.Series = Builder<Series>.CreateNew().With(s => s.SeriesId = 71256).Build())
.With(c => c.Series = series)
.With(c => c.SeasonNumber = 12)
.Build();
@ -270,6 +341,9 @@ namespace NzbDrone.Core.Test.ProviderTests
.Setup(c => c.GetEpisode(episode.EpisodeId))
.Returns(episode);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
var indexer1 = new Mock<IndexerBase>();
indexer1.Setup(c => c.FetchEpisode("The Daily Show", episode.SeasonNumber, episode.EpisodeNumber))
.Returns(parseResults).Verifiable();
@ -288,20 +362,14 @@ namespace NzbDrone.Core.Test.ProviderTests
.Setup(c => c.GetSeries(It.IsAny<int>()))
.Returns(episode.Series);
mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
mocker.GetMock<SceneMappingProvider>()
.Setup(s => s.GetSceneName(71256)).Returns("The Daily Show");
//Act
mocker.Resolve<SearchProvider>().EpisodeSearch(new ProgressNotification("Test"), episode.EpisodeId);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Exactly(8));
ExceptionVerification.ExcpectedWarns(1);
indexer1.VerifyAll();
indexer2.VerifyAll();
@ -348,9 +416,6 @@ namespace NzbDrone.Core.Test.ProviderTests
.Setup(c => c.GetSeries(It.IsAny<int>()))
.Returns(episode.Series);
mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
mocker.GetMock<SceneMappingProvider>()
.Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
@ -360,8 +425,6 @@ namespace NzbDrone.Core.Test.ProviderTests
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Exactly(8));
ExceptionVerification.ExcpectedWarns(1);
ExceptionVerification.ExcpectedErrors(1);
@ -394,8 +457,10 @@ namespace NzbDrone.Core.Test.ProviderTests
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var series = Builder<Series>.CreateNew().Build();
var episode = Builder<Episode>.CreateNew()
.With(c => c.Series = Builder<Series>.CreateNew().Build())
.With(c => c.Series = series)
.With(c => c.SeasonNumber = 12)
.Build();
@ -405,6 +470,9 @@ namespace NzbDrone.Core.Test.ProviderTests
.Setup(c => c.GetEpisode(episode.EpisodeId))
.Returns(episode);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
var indexer1 = new Mock<IndexerBase>();
indexer1.Setup(c => c.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber))
.Returns(parseResults).Verifiable();
@ -415,9 +483,6 @@ namespace NzbDrone.Core.Test.ProviderTests
.Setup(c => c.GetEnabledIndexers())
.Returns(indexers);
mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
mocker.GetMock<SceneMappingProvider>()
.Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
@ -433,5 +498,134 @@ namespace NzbDrone.Core.Test.ProviderTests
ExceptionVerification.ExcpectedWarns(1);
indexer1.VerifyAll();
}
[Test]
public void processResults_should_return_false_when_series_is_null()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(1)
.All()
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int> { 1 })
.Build();
Series series = null;
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
//Assert
mocker.VerifyAllMocks();
result.Should().BeFalse();
ExceptionVerification.ExcpectedWarns(1);
}
[Test]
public void processResults_should_return_false_when_seriesId_doesnt_match()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(1)
.All()
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int> { 1 })
.Build();
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 100)
.Build();
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
//Assert
mocker.VerifyAllMocks();
result.Should().BeFalse();
ExceptionVerification.ExcpectedWarns(1);
}
[Test]
public void processResults_should_return_false_when_seasonNumber_doesnt_match()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(1)
.All()
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int> { 1 })
.Build();
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 100)
.Build();
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = series.SeriesId)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
//Assert
mocker.VerifyAllMocks();
result.Should().BeFalse();
ExceptionVerification.ExcpectedWarns(1);
}
[Test]
public void processResults_should_return_false_when_episodeNumber_doesnt_match()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(1)
.All()
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumbers = new List<int> { 1 })
.Build();
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 100)
.Build();
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = series.SeriesId)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 2)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
//Assert
mocker.VerifyAllMocks();
result.Should().BeFalse();
ExceptionVerification.ExcpectedWarns(1);
}
}
}

View File

@ -39,6 +39,7 @@ namespace NzbDrone.Core.Test.ProviderTests
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.All()
.With(e => e.EpisodeNumbers = Builder<int>.CreateListOfSize(2).Build().ToList())
.With(e => e.SeasonNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -74,6 +75,9 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker.GetMock<DownloadProvider>()
.Setup(s => s.DownloadReport(It.IsAny<EpisodeParseResult>())).Returns(true);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().PartialSeasonSearch(notification, 1, 1);
@ -152,6 +156,8 @@ namespace NzbDrone.Core.Test.ProviderTests
.All()
.With(e => e.EpisodeNumbers = Builder<int>.CreateListOfSize(2).Build().ToList())
.With(e => e.Series = series)
.With(e => e.CleanTitle = "title")
.With(e => e.SeasonNumber = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
@ -164,8 +170,11 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker.GetMock<DownloadProvider>()
.Setup(s => s.DownloadReport(It.IsAny<EpisodeParseResult>())).Returns(true);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessPartialSeasonSearchResults(notification, parseResults);
var result = mocker.Resolve<SearchProvider>().ProcessPartialSeasonSearchResults(notification, parseResults, series, 1);
//Assert
result.Should().HaveCount(8);
@ -175,7 +184,7 @@ namespace NzbDrone.Core.Test.ProviderTests
}
[Test]
public void ProcessPartialSeasonSearchResults_failure()
public void ProcessPartialSeasonSearchResults_should_return_empty_list_when_quality_is_not_wanted()
{
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
@ -197,8 +206,114 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker.GetMock<InventoryProvider>()
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessPartialSeasonSearchResults(notification, parseResults);
var result = mocker.Resolve<SearchProvider>().ProcessPartialSeasonSearchResults(notification, parseResults, series, 1);
//Assert
result.Should().HaveCount(0);
mocker.VerifyAllMocks();
mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()), Times.Never());
}
[Test]
public void ProcessPartialSeasonSearchResults_should_return_empty_list_when_is_wrong_season()
{
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.With(s => s.Title = "Title1")
.Build();
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.TheFirst(1)
.With(p => p.CleanTitle = "title")
.With(p => p.SeasonNumber = 2)
.With(p => p.FullSeason = true)
.With(p => p.EpisodeNumbers = null)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
var notification = new ProgressNotification("Season Search");
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessPartialSeasonSearchResults(notification, parseResults, series, 1);
//Assert
result.Should().HaveCount(0);
mocker.VerifyAllMocks();
mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()), Times.Never());
}
[Test]
public void ProcessPartialSeasonSearchResults_should_return_empty_list_when_series_is_null()
{
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.With(s => s.Title = "Title1")
.Build();
Series findSeries = null;
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.TheFirst(1)
.With(p => p.CleanTitle = "title")
.With(p => p.SeasonNumber = 1)
.With(p => p.FullSeason = true)
.With(p => p.EpisodeNumbers = null)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
var notification = new ProgressNotification("Season Search");
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(findSeries);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessPartialSeasonSearchResults(notification, parseResults, series, 1);
//Assert
result.Should().HaveCount(0);
mocker.VerifyAllMocks();
mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()), Times.Never());
}
[Test]
public void ProcessPartialSeasonSearchResults_should_return_empty_list_when_series_mismatch()
{
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.With(s => s.Title = "Title1")
.Build();
var findSeries = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 2)
.With(s => s.Title = "Title1")
.Build();
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.TheFirst(1)
.With(p => p.CleanTitle = "title")
.With(p => p.SeasonNumber = 1)
.With(p => p.FullSeason = true)
.With(p => p.EpisodeNumbers = null)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
var notification = new ProgressNotification("Season Search");
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(findSeries);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessPartialSeasonSearchResults(notification, parseResults, series, 1);
//Assert
result.Should().HaveCount(0);

View File

@ -78,6 +78,9 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker.GetMock<DownloadProvider>()
.Setup(s => s.DownloadReport(It.IsAny<EpisodeParseResult>())).Returns(true);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().SeasonSearch(notification, 1, 1);
@ -167,6 +170,9 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker.GetMock<DownloadProvider>()
.Setup(s => s.DownloadReport(It.IsAny<EpisodeParseResult>())).Returns(true);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessSeasonSearchResults(notification, series, 1, parseResults);
@ -176,7 +182,7 @@ namespace NzbDrone.Core.Test.ProviderTests
}
[Test]
public void ProcessSeasonSearchResults_failure()
public void ProcessSeasonSearchResults_should_return_false_when_quality_is_not_wanted()
{
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
@ -198,6 +204,113 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker.GetMock<InventoryProvider>()
.Setup(s => s.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessSeasonSearchResults(notification, series, 1, parseResults);
//Assert
result.Should().BeFalse();
ExceptionVerification.ExcpectedWarns(1);
mocker.VerifyAllMocks();
}
[Test]
public void ProcessSeasonSearchResults_should_return_false_when_series_is_null()
{
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.With(s => s.Title = "Title1")
.Build();
Series findSeries = null;
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.TheFirst(1)
.With(p => p.CleanTitle = "title")
.With(p => p.SeasonNumber = 1)
.With(p => p.FullSeason = true)
.With(p => p.EpisodeNumbers = null)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
var notification = new ProgressNotification("Season Search");
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(findSeries);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessSeasonSearchResults(notification, series, 1, parseResults);
//Assert
result.Should().BeFalse();
ExceptionVerification.ExcpectedWarns(1);
mocker.VerifyAllMocks();
}
[Test]
public void ProcessSeasonSearchResults_should_return_false_when_series_doesnt_match()
{
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.With(s => s.Title = "Title1")
.Build();
Series findSeries = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 2)
.With(s => s.Title = "Title1")
.Build();
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.TheFirst(1)
.With(p => p.CleanTitle = "title")
.With(p => p.SeasonNumber = 1)
.With(p => p.FullSeason = true)
.With(p => p.EpisodeNumbers = null)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
var notification = new ProgressNotification("Season Search");
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(findSeries);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessSeasonSearchResults(notification, series, 1, parseResults);
//Assert
result.Should().BeFalse();
ExceptionVerification.ExcpectedWarns(1);
mocker.VerifyAllMocks();
}
[Test]
public void ProcessSeasonSearchResults_should_return_false_when_seasonNumber_doesnt_match()
{
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.With(s => s.Title = "Title1")
.Build();
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.All()
.With(p => p.SeasonNumber = 2)
.TheFirst(1)
.With(p => p.CleanTitle = "title")
.With(p => p.FullSeason = true)
.With(p => p.EpisodeNumbers = null)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
var notification = new ProgressNotification("Season Search");
mocker.GetMock<SeriesProvider>()
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(series);
//Act
var result = mocker.Resolve<SearchProvider>().ProcessSeasonSearchResults(notification, series, 1, parseResults);

View File

@ -49,7 +49,9 @@ namespace NzbDrone.Core.Providers.Indexer
if (searchModel.SearchType == SearchType.SeasonSearch)
{
searchUrls.Add(String.Format("{0}&limit=100&q={1}&season{2}", url, searchModel.SeriesTitle, searchModel.SeasonNumber));
//Todo: Allow full season searching to process individual episodes
//searchUrls.Add(String.Format("{0}&limit=100&q={1}&season{2}", url, searchModel.SeriesTitle, searchModel.SeasonNumber));
searchUrls.Add(String.Format("{0}&limit=100&q={1}+Season", url, searchModel.SeriesTitle));
}
}

View File

@ -92,15 +92,15 @@ namespace NzbDrone.Core.Providers
notification.CurrentMessage = "Processing search results";
var reportsToProcess = reports.Where(p => p.FullSeason && p.SeasonNumber == seasonNumber).ToList();
var fullSeasonReportsToProcess = reports.Where(p => p.FullSeason && p.SeasonNumber == seasonNumber).ToList();
reportsToProcess.ForEach(c =>
fullSeasonReportsToProcess.ForEach(c =>
{
c.Series = series;
c.EpisodeNumbers = episodeNumbers.ToList();
});
return ProcessSeasonSearchResults(notification, series, seasonNumber, reportsToProcess);
//Todo: Handle non-full season reports
return ProcessSeasonSearchResults(notification, series, seasonNumber, fullSeasonReportsToProcess);
}
public bool ProcessSeasonSearchResults(ProgressNotification notification, Series series, int seasonNumber, IEnumerable<EpisodeParseResult> reports)
@ -110,6 +110,18 @@ namespace NzbDrone.Core.Providers
try
{
Logger.Trace("Analysing report " + episodeParseResult);
//Get the matching series
episodeParseResult.Series = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);
//If series is null or doesn't match the series we're looking for return
if (episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId)
continue;
//If SeasonNumber doesn't match or episode is not in the in the list in the parse result, skip it.
if (episodeParseResult.SeasonNumber != seasonNumber)
continue;
if (_inventoryProvider.IsQualityNeeded(episodeParseResult))
{
Logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);
@ -200,6 +212,18 @@ namespace NzbDrone.Core.Providers
try
{
Logger.Trace("Analysing report " + episodeParseResult);
//Get the matching series
var series = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);
//If series is null or doesn't match the series we're looking for return
if (series == null || series.SeriesId != episode.SeriesId)
continue;
//If SeasonNumber doesn't match or episode is not in the in the list in the parse result, skip it.
if (episodeParseResult.SeasonNumber != episode.SeasonNumber || !episodeParseResult.EpisodeNumbers.Contains(episode.EpisodeNumber))
continue;
if (_inventoryProvider.IsQualityNeeded(episodeParseResult))
{
Logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);
@ -285,15 +309,10 @@ namespace NzbDrone.Core.Providers
notification.CurrentMessage = "Processing search results";
reports.ForEach(c =>
{
c.Series = series;
});
return ProcessPartialSeasonSearchResults(notification, reports);
return ProcessPartialSeasonSearchResults(notification, reports, series, seasonNumber);
}
public List<int> ProcessPartialSeasonSearchResults(ProgressNotification notification, IEnumerable<EpisodeParseResult> reports)
public List<int> ProcessPartialSeasonSearchResults(ProgressNotification notification, IEnumerable<EpisodeParseResult> reports, Series series, int seasonNumber)
{
var successes = new List<int>();
@ -302,6 +321,18 @@ namespace NzbDrone.Core.Providers
try
{
Logger.Trace("Analysing report " + episodeParseResult);
//Get the matching series
episodeParseResult.Series = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);
//If series is null or doesn't match the series we're looking for return
if (episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId)
continue;
//If SeasonNumber doesn't match or episode is not in the in the list in the parse result, skip it.
if (episodeParseResult.SeasonNumber != seasonNumber)
continue;
if (_inventoryProvider.IsQualityNeeded(episodeParseResult))
{
Logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);