2012-02-07 05:08:07 +00:00
|
|
|
|
using System.Collections.Generic;
|
2011-11-18 02:36:53 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
using NzbDrone.Core.Providers.DecisionEngine;
|
2011-11-18 02:36:53 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2012-04-23 06:31:11 +00:00
|
|
|
|
using NzbDrone.Core.Repository.Search;
|
2011-11-18 02:36:53 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.SearchProviderTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
public class ProcessSearchResultsFixture : CoreTest
|
|
|
|
|
{
|
|
|
|
|
private Series _matchingSeries = null;
|
|
|
|
|
private Series _mismatchedSeries = null;
|
|
|
|
|
private Series _nullSeries = null;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void setup()
|
|
|
|
|
{
|
|
|
|
|
_matchingSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.SeriesId = 79488)
|
|
|
|
|
.With(s => s.Title = "30 Rock")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_mismatchedSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.SeriesId = 12345)
|
|
|
|
|
.With(s => s.Title = "Not 30 Rock")
|
|
|
|
|
.Build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithMatchingSeries()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(_matchingSeries);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithMisMatchedSeries()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(_mismatchedSeries);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithNullSeries()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(s => s.FindSeries(It.IsAny<string>())).Returns(_nullSeries);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithSuccessfulDownload()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<DownloadProvider>()
|
|
|
|
|
.Setup(s => s.DownloadReport(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithFailingDownload()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<DownloadProvider>()
|
|
|
|
|
.Setup(s => s.DownloadReport(It.IsAny<EpisodeParseResult>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithQualityNeeded()
|
|
|
|
|
{
|
2012-02-07 05:08:07 +00:00
|
|
|
|
Mocker.GetMock<AllowedDownloadSpecification>()
|
|
|
|
|
.Setup(s => s.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
2012-04-20 06:42:13 +00:00
|
|
|
|
.Returns(ReportRejectionType.None);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithQualityNotNeeded()
|
|
|
|
|
{
|
2012-02-07 05:08:07 +00:00
|
|
|
|
Mocker.GetMock<AllowedDownloadSpecification>()
|
|
|
|
|
.Setup(s => s.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
|
2012-04-20 06:42:13 +00:00
|
|
|
|
.Returns(ReportRejectionType.ExistingQualityIsEqualOrBetter);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void processSearchResults_higher_quality_should_be_called_first()
|
|
|
|
|
{
|
|
|
|
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 1 })
|
|
|
|
|
.With(c => c.Quality = new Quality(QualityTypes.DVD, true))
|
2012-02-18 19:20:18 +00:00
|
|
|
|
.With(c => c.Age = 10)
|
2011-11-18 02:36:53 +00:00
|
|
|
|
.Random(1)
|
|
|
|
|
.With(c => c.Quality = new Quality(QualityTypes.Bluray1080p, true))
|
2012-02-18 19:20:18 +00:00
|
|
|
|
.With(c => c.Age = 100)
|
2011-11-18 02:36:53 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
WithMatchingSeries();
|
|
|
|
|
WithSuccessfulDownload();
|
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
Mocker.GetMock<AllowedDownloadSpecification>()
|
|
|
|
|
.Setup(s => s.IsSatisfiedBy(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.Bluray1080p)))
|
2012-04-20 06:42:13 +00:00
|
|
|
|
.Returns(ReportRejectionType.None);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-04-23 06:31:11 +00:00
|
|
|
|
var result = Mocker.Resolve<SearchProvider>().ProcessSearchResults(new ProgressNotification("Test"), parseResults, new SearchResult(), _matchingSeries, 1, 1);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-04-20 06:42:13 +00:00
|
|
|
|
result.Should().HaveCount(parseResults.Count);
|
|
|
|
|
result.Should().Contain(s => s.Success);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
Mocker.GetMock<AllowedDownloadSpecification>().Verify(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()),
|
2011-11-18 02:36:53 +00:00
|
|
|
|
Times.Once());
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
|
|
|
|
|
Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-18 19:20:18 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void processSearchResults_newer_report_should_be_called_first()
|
|
|
|
|
{
|
|
|
|
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 1 })
|
|
|
|
|
.With(c => c.Quality = new Quality(QualityTypes.Bluray1080p, true))
|
|
|
|
|
.With(c => c.Age = 300)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
parseResults[2].Age = 100;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WithMatchingSeries();
|
|
|
|
|
WithSuccessfulDownload();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<AllowedDownloadSpecification>()
|
2012-04-20 06:42:13 +00:00
|
|
|
|
.Setup(s => s.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())).Returns(ReportRejectionType.None);
|
2012-02-18 19:20:18 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-04-23 06:31:11 +00:00
|
|
|
|
var result = Mocker.Resolve<SearchProvider>().ProcessSearchResults(MockNotification, parseResults, new SearchResult(), _matchingSeries, 1, 1);
|
2012-02-18 19:20:18 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-04-20 06:42:13 +00:00
|
|
|
|
result.Should().HaveCount(parseResults.Count);
|
|
|
|
|
result.Should().Contain(s => s.Success);
|
2012-02-18 19:20:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.Is<EpisodeParseResult>(d => d.Age != 100)), Times.Never());
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.Is<EpisodeParseResult>(d => d.Age == 100)), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-18 02:36:53 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void processSearchResults_when_quality_is_not_needed_should_check_the_rest()
|
|
|
|
|
{
|
|
|
|
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 1 })
|
|
|
|
|
.With(c => c.Quality = new Quality(QualityTypes.DVD, true))
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
WithMatchingSeries();
|
|
|
|
|
WithQualityNotNeeded();
|
|
|
|
|
|
|
|
|
|
//Act
|
2012-04-23 06:31:11 +00:00
|
|
|
|
var result = Mocker.Resolve<SearchProvider>().ProcessSearchResults(new ProgressNotification("Test"), parseResults, new SearchResult(), _matchingSeries, 1, 1);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-04-20 06:42:13 +00:00
|
|
|
|
result.Should().HaveCount(parseResults.Count);
|
|
|
|
|
result.Should().NotContain(s => s.Success);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
Mocker.GetMock<AllowedDownloadSpecification>().Verify(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()),
|
2011-11-18 02:36:53 +00:00
|
|
|
|
Times.Exactly(5));
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
|
|
|
|
|
Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void processSearchResults_should_skip_if_series_is_null()
|
|
|
|
|
{
|
|
|
|
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 1 })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
WithNullSeries();
|
|
|
|
|
|
|
|
|
|
//Act
|
2012-04-23 06:31:11 +00:00
|
|
|
|
var result = Mocker.Resolve<SearchProvider>().ProcessSearchResults(new ProgressNotification("Test"), parseResults, new SearchResult(), _matchingSeries, 1, 1);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-04-20 06:42:13 +00:00
|
|
|
|
result.Should().HaveCount(parseResults.Count);
|
|
|
|
|
result.Should().NotContain(s => s.Success);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
|
|
|
|
|
Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void processSearchResults_should_skip_if_series_is_mismatched()
|
|
|
|
|
{
|
|
|
|
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 1 })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
WithMisMatchedSeries();
|
|
|
|
|
|
|
|
|
|
//Act
|
2012-04-23 06:31:11 +00:00
|
|
|
|
var result = Mocker.Resolve<SearchProvider>().ProcessSearchResults(new ProgressNotification("Test"), parseResults, new SearchResult(), _matchingSeries, 1, 1);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-04-20 06:42:13 +00:00
|
|
|
|
result.Should().HaveCount(parseResults.Count);
|
|
|
|
|
result.Should().NotContain(s => s.Success);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
|
|
|
|
|
Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void processSearchResults_should_skip_if_season_doesnt_match()
|
|
|
|
|
{
|
|
|
|
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 2)
|
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 1 })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
WithMatchingSeries();
|
|
|
|
|
|
|
|
|
|
//Act
|
2012-04-23 06:31:11 +00:00
|
|
|
|
var result = Mocker.Resolve<SearchProvider>().ProcessSearchResults(new ProgressNotification("Test"), parseResults, new SearchResult(), _matchingSeries, 1, 1);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-04-20 06:42:13 +00:00
|
|
|
|
result.Should().HaveCount(parseResults.Count);
|
|
|
|
|
result.Should().NotContain(s => s.Success);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
|
|
|
|
|
Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void processSearchResults_should_skip_if_episodeNumber_doesnt_match()
|
|
|
|
|
{
|
|
|
|
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 2 })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
WithMatchingSeries();
|
|
|
|
|
|
|
|
|
|
//Act
|
2012-04-23 06:31:11 +00:00
|
|
|
|
var result = Mocker.Resolve<SearchProvider>().ProcessSearchResults(new ProgressNotification("Test"), parseResults, new SearchResult(), _matchingSeries, 1, 1);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-04-20 06:42:13 +00:00
|
|
|
|
result.Should().HaveCount(parseResults.Count);
|
|
|
|
|
result.Should().NotContain(s => s.Success);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
|
|
|
|
|
Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void processSearchResults_should_skip_if_any_episodeNumber_was_already_added_to_download_queue()
|
|
|
|
|
{
|
|
|
|
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(2)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 5 })
|
|
|
|
|
.With(c => c.Quality = new Quality(QualityTypes.DVD, true))
|
|
|
|
|
.TheLast(1)
|
2012-02-18 19:20:18 +00:00
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 1, 2, 3, 4, 5 })
|
2011-11-18 02:36:53 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
WithMatchingSeries();
|
|
|
|
|
WithQualityNeeded();
|
|
|
|
|
WithSuccessfulDownload();
|
|
|
|
|
|
|
|
|
|
//Act
|
2012-04-23 06:31:11 +00:00
|
|
|
|
var result = Mocker.Resolve<SearchProvider>().ProcessSearchResults(new ProgressNotification("Test"), parseResults, new SearchResult(), _matchingSeries, 1);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-04-20 06:42:13 +00:00
|
|
|
|
result.Should().HaveCount(parseResults.Count);
|
|
|
|
|
result.Should().Contain(s => s.Success);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
|
|
|
|
|
Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void processSearchResults_should_try_next_if_download_fails()
|
|
|
|
|
{
|
|
|
|
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(2)
|
|
|
|
|
.All()
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumbers = new List<int> { 1 })
|
|
|
|
|
.With(c => c.Quality = new Quality(QualityTypes.DVD, true))
|
|
|
|
|
.TheLast(1)
|
|
|
|
|
.With(c => c.Quality = new Quality(QualityTypes.SDTV, true))
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
WithMatchingSeries();
|
|
|
|
|
WithQualityNeeded();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DownloadProvider>()
|
|
|
|
|
.Setup(s => s.DownloadReport(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.DVD)))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DownloadProvider>()
|
|
|
|
|
.Setup(s => s.DownloadReport(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.SDTV)))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
//Act
|
2012-04-23 06:31:11 +00:00
|
|
|
|
var result = Mocker.Resolve<SearchProvider>().ProcessSearchResults(new ProgressNotification("Test"), parseResults, new SearchResult(), _matchingSeries, 1);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-04-20 06:42:13 +00:00
|
|
|
|
result.Should().HaveCount(parseResults.Count);
|
|
|
|
|
result.Should().Contain(s => s.Success);
|
2011-11-18 02:36:53 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
|
|
|
|
|
Times.Exactly(2));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|