From ac84d76ef9dd4a30435c84255aa9c1b07dbcc3e4 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 18 Feb 2012 11:20:18 -0800 Subject: [PATCH] New: When searching for episodes, newer reports are given priority over older reports of equal quality. --- .../ProcessSearchResultsFixture.cs | 35 ++++++++++++++++++- NzbDrone.Core/Providers/SearchProvider.cs | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/NzbDrone.Core.Test/ProviderTests/SearchProviderTests/ProcessSearchResultsFixture.cs b/NzbDrone.Core.Test/ProviderTests/SearchProviderTests/ProcessSearchResultsFixture.cs index d44b18034..40d79bce6 100644 --- a/NzbDrone.Core.Test/ProviderTests/SearchProviderTests/ProcessSearchResultsFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/SearchProviderTests/ProcessSearchResultsFixture.cs @@ -91,8 +91,10 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests .With(e => e.SeasonNumber = 1) .With(e => e.EpisodeNumbers = new List { 1 }) .With(c => c.Quality = new Quality(QualityTypes.DVD, true)) + .With(c => c.Age = 10) .Random(1) .With(c => c.Quality = new Quality(QualityTypes.Bluray1080p, true)) + .With(c => c.Age = 100) .Build(); WithMatchingSeries(); @@ -115,6 +117,37 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests Times.Once()); } + [Test] + public void processSearchResults_newer_report_should_be_called_first() + { + var parseResults = Builder.CreateListOfSize(5) + .All() + .With(e => e.SeasonNumber = 1) + .With(e => e.EpisodeNumbers = new List { 1 }) + .With(c => c.Quality = new Quality(QualityTypes.Bluray1080p, true)) + .With(c => c.Age = 300) + .Build(); + + parseResults[2].Age = 100; + + + WithMatchingSeries(); + WithSuccessfulDownload(); + + Mocker.GetMock() + .Setup(s => s.IsSatisfiedBy(It.IsAny())).Returns(true); + + //Act + var result = Mocker.Resolve().ProcessSearchResults(MockNotification, parseResults, _matchingSeries, 1, 1); + + //Assert + result.Should().HaveCount(1); + + + Mocker.GetMock().Verify(c => c.DownloadReport(It.Is(d => d.Age != 100)), Times.Never()); + Mocker.GetMock().Verify(c => c.DownloadReport(It.Is(d => d.Age == 100)), Times.Once()); + } + [Test] public void processSearchResults_when_quality_is_not_needed_should_check_the_rest() { @@ -233,7 +266,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests .With(e => e.EpisodeNumbers = new List { 5 }) .With(c => c.Quality = new Quality(QualityTypes.DVD, true)) .TheLast(1) - .With(e => e.EpisodeNumbers = new List { 1,2,3,4,5 }) + .With(e => e.EpisodeNumbers = new List { 1, 2, 3, 4, 5 }) .Build(); WithMatchingSeries(); diff --git a/NzbDrone.Core/Providers/SearchProvider.cs b/NzbDrone.Core/Providers/SearchProvider.cs index 95e64141f..982a982b5 100644 --- a/NzbDrone.Core/Providers/SearchProvider.cs +++ b/NzbDrone.Core/Providers/SearchProvider.cs @@ -231,7 +231,7 @@ namespace NzbDrone.Core.Providers { var successes = new List(); - foreach (var episodeParseResult in reports.OrderByDescending(c => c.Quality)) + foreach (var episodeParseResult in reports.OrderByDescending(c => c.Quality).ThenBy(c => c.Age)) { try {