1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-30 20:05:41 +00:00
Radarr/NzbDrone.Core.Test/ProviderTests/SearchProviderTest_Episode.cs

436 lines
17 KiB
C#
Raw Normal View History

2011-05-27 03:07:32 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMoq;
using FizzWare.NBuilder;
2011-06-02 21:06:46 +00:00
using FluentAssertions;
2011-05-27 03:07:32 +00:00
using Moq;
2011-06-02 21:06:46 +00:00
using NUnit.Framework;
2011-05-27 03:07:32 +00:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
2011-05-27 03:54:28 +00:00
using NzbDrone.Core.Providers.Indexer;
2011-05-27 03:07:32 +00:00
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
2011-10-24 05:54:09 +00:00
using NzbDrone.Test.Common;
2011-05-27 03:07:32 +00:00
namespace NzbDrone.Core.Test.ProviderTests
2011-05-27 03:07:32 +00:00
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SearchProviderTest_Episode : TestBase
2011-05-27 03:07:32 +00:00
{
[Test]
2011-05-28 19:23:35 +00:00
public void processResults_ParseResult_should_return_after_match()
2011-05-27 03:07:32 +00:00
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<InventoryProvider>()
2011-05-28 19:23:35 +00:00
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(true);
2011-05-27 03:54:28 +00:00
2011-05-27 03:07:32 +00:00
mocker.GetMock<DownloadProvider>()
2011-05-27 03:54:28 +00:00
.Setup(c => c.DownloadReport(It.IsAny<EpisodeParseResult>())).Returns(true);
2011-05-28 19:23:35 +00:00
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Assert
2011-05-27 03:07:32 +00:00
mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Once());
mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
Times.Once());
2011-05-27 03:07:32 +00:00
}
[Test]
2011-05-28 19:23:35 +00:00
public void processResults_higher_quality_should_be_called_first()
2011-05-27 03:07:32 +00:00
{
2011-05-28 19:23:35 +00:00
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(10)
2011-10-18 21:46:06 +00:00
.All().With(c => c.Quality = new Quality(QualityTypes.DVD, true))
2011-10-23 05:39:14 +00:00
.Random(1).With(c => c.Quality = new Quality(QualityTypes.Bluray1080p, true))
2011-05-27 03:07:32 +00:00
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<InventoryProvider>()
2011-05-28 19:23:35 +00:00
.Setup(
c =>
c.IsQualityNeeded(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.Bluray1080p)))
.Returns(true);
2011-05-27 03:07:32 +00:00
mocker.GetMock<DownloadProvider>()
2011-05-28 19:23:35 +00:00
.Setup(
c =>
c.DownloadReport(It.Is<EpisodeParseResult>(d => d.Quality.QualityType == QualityTypes.Bluray1080p)))
.Returns(true);
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Assert
2011-05-27 03:07:32 +00:00
mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Once());
mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
Times.Once());
2011-05-27 03:07:32 +00:00
}
[Test]
2011-05-28 19:23:35 +00:00
public void processResults_when_same_quality_proper_should_be_called_first()
2011-05-27 03:07:32 +00:00
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(20)
2011-10-18 21:46:06 +00:00
.All().With(c => c.Quality = new Quality(QualityTypes.DVD, false))
2011-10-23 05:39:14 +00:00
.Random(1).With(c => c.Quality = new Quality(QualityTypes.DVD, true))
2011-05-27 03:07:32 +00:00
.Build();
2011-06-02 21:06:46 +00:00
parseResults.Where(c => c.Quality.Proper).Should().HaveCount(1);
2011-05-27 03:07:32 +00:00
var episode = Builder<Episode>.CreateNew().Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<InventoryProvider>()
2011-05-28 19:23:35 +00:00
.Setup(c => c.IsQualityNeeded(It.Is<EpisodeParseResult>(p => p.Quality.Proper))).Returns(true);
2011-05-27 03:07:32 +00:00
mocker.GetMock<DownloadProvider>()
2011-05-28 19:23:35 +00:00
.Setup(c => c.DownloadReport(It.Is<EpisodeParseResult>(p => p.Quality.Proper))).Returns(true);
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Assert
2011-05-27 03:07:32 +00:00
mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Once());
mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
Times.Once());
2011-05-27 03:07:32 +00:00
}
[Test]
2011-05-28 19:23:35 +00:00
public void processResults_when_not_needed_should_check_the_rest()
2011-05-27 03:07:32 +00:00
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<InventoryProvider>()
2011-05-28 19:23:35 +00:00
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Assert
2011-05-27 03:07:32 +00:00
mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Exactly(4));
2011-05-27 03:07:32 +00:00
ExceptionVerification.ExcpectedWarns(1);
}
[Test]
2011-05-28 19:23:35 +00:00
public void processResults_failed_IsNeeded_should_check_the_rest()
2011-05-27 03:07:32 +00:00
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<InventoryProvider>()
2011-05-28 19:23:35 +00:00
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Throws(new Exception());
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
2011-05-27 03:07:32 +00:00
2011-05-27 03:54:28 +00:00
//Assert
2011-05-27 03:07:32 +00:00
mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Exactly(4));
2011-05-27 03:07:32 +00:00
ExceptionVerification.ExcpectedErrors(4);
ExceptionVerification.ExcpectedWarns(1);
}
2011-05-27 03:54:28 +00:00
2011-05-28 19:23:35 +00:00
[Test]
public void processResults_failed_download_should_not_check_the_rest()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var episode = Builder<Episode>.CreateNew().Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<InventoryProvider>()
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(true);
mocker.GetMock<DownloadProvider>()
.Setup(c => c.DownloadReport(It.IsAny<EpisodeParseResult>())).Throws(new Exception());
//Act
mocker.Resolve<SearchProvider>().ProcessEpisodeSearchResults(new ProgressNotification("Test"), episode, parseResults);
2011-05-28 19:23:35 +00:00
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Exactly(1));
mocker.GetMock<DownloadProvider>().Verify(c => c.DownloadReport(It.IsAny<EpisodeParseResult>()),
Times.Exactly(1));
ExceptionVerification.ExcpectedErrors(1);
}
2011-05-27 03:54:28 +00:00
[Test]
2011-05-28 19:23:35 +00:00
public void start_should_search_all_providers()
2011-05-27 03:54:28 +00:00
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var episode = Builder<Episode>.CreateNew()
.With(c => c.Series = Builder<Series>.CreateNew().Build())
.With(c => c.SeasonNumber = 12)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisode(episode.EpisodeId))
.Returns(episode);
var indexer1 = new Mock<IndexerBase>();
indexer1.Setup(c => c.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber))
.Returns(parseResults).Verifiable();
var indexer2 = new Mock<IndexerBase>();
indexer2.Setup(c => c.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber))
.Returns(parseResults).Verifiable();
var indexers = new List<IndexerBase> { indexer1.Object, indexer2.Object };
mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetEnabledIndexers())
.Returns(indexers);
mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetSeries(It.IsAny<int>()))
.Returns(episode.Series);
2011-05-27 03:54:28 +00:00
mocker.GetMock<InventoryProvider>()
2011-06-22 01:12:20 +00:00
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
2011-05-27 03:54:28 +00:00
mocker.GetMock<SceneMappingProvider>()
.Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
2011-05-27 03:54:28 +00:00
//Act
mocker.Resolve<SearchProvider>().EpisodeSearch(new ProgressNotification("Test"), episode.EpisodeId);
2011-05-27 03:54:28 +00:00
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Exactly(8));
ExceptionVerification.ExcpectedWarns(1);
indexer1.VerifyAll();
indexer2.VerifyAll();
}
[Test]
public void start_should_use_scene_name_to_search()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var episode = Builder<Episode>.CreateNew()
.With(c => c.Series = Builder<Series>.CreateNew().With(s => s.SeriesId = 71256).Build())
.With(c => c.SeasonNumber = 12)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisode(episode.EpisodeId))
.Returns(episode);
var indexer1 = new Mock<IndexerBase>();
indexer1.Setup(c => c.FetchEpisode("The Daily Show", episode.SeasonNumber, episode.EpisodeNumber))
.Returns(parseResults).Verifiable();
var indexer2 = new Mock<IndexerBase>();
indexer2.Setup(c => c.FetchEpisode("The Daily Show", episode.SeasonNumber, episode.EpisodeNumber))
.Returns(parseResults).Verifiable();
var indexers = new List<IndexerBase> { indexer1.Object, indexer2.Object };
mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetEnabledIndexers())
.Returns(indexers);
mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetSeries(It.IsAny<int>()))
.Returns(episode.Series);
mocker.GetMock<InventoryProvider>()
2011-06-22 01:12:20 +00:00
.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);
2011-05-27 03:54:28 +00:00
//Assert
mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Exactly(8));
2011-05-27 03:54:28 +00:00
ExceptionVerification.ExcpectedWarns(1);
indexer1.VerifyAll();
indexer2.VerifyAll();
}
[Test]
2011-05-28 19:23:35 +00:00
public void start_failed_indexer_should_not_break_job()
2011-05-27 03:54:28 +00:00
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var episode = Builder<Episode>.CreateNew()
.With(c => c.Series = Builder<Series>.CreateNew().Build())
.With(c => c.SeasonNumber = 12)
.Build();
2011-06-22 01:12:20 +00:00
var mocker = new AutoMoqer();
2011-05-27 03:54:28 +00:00
mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisode(episode.EpisodeId))
.Returns(episode);
var indexer1 = new Mock<IndexerBase>();
indexer1.Setup(c => c.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber))
.Returns(parseResults).Verifiable();
var indexer2 = new Mock<IndexerBase>();
indexer2.Setup(c => c.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber))
.Throws(new Exception()).Verifiable();
var indexer3 = new Mock<IndexerBase>();
2011-06-22 01:12:20 +00:00
indexer3.Setup(c => c.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber))
2011-05-27 03:54:28 +00:00
.Returns(parseResults).Verifiable();
var indexers = new List<IndexerBase> { indexer1.Object, indexer2.Object, indexer3.Object };
mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetEnabledIndexers())
.Returns(indexers);
mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetSeries(It.IsAny<int>()))
.Returns(episode.Series);
2011-05-27 03:54:28 +00:00
mocker.GetMock<InventoryProvider>()
2011-06-22 01:12:20 +00:00
.Setup(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
mocker.GetMock<SceneMappingProvider>()
.Setup(s => s.GetSceneName(It.IsAny<int>())).Returns("");
2011-05-27 03:54:28 +00:00
//Act
mocker.Resolve<SearchProvider>().EpisodeSearch(new ProgressNotification("Test"), episode.EpisodeId);
2011-05-27 03:54:28 +00:00
//Assert
mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
mocker.GetMock<InventoryProvider>().Verify(c => c.IsQualityNeeded(It.IsAny<EpisodeParseResult>()),
Times.Exactly(8));
2011-05-27 03:54:28 +00:00
ExceptionVerification.ExcpectedWarns(1);
ExceptionVerification.ExcpectedErrors(1);
indexer1.VerifyAll();
indexer2.VerifyAll();
indexer3.VerifyAll();
}
[Test]
2011-05-28 19:23:35 +00:00
public void start_no_episode_found_should_return_with_error_logged()
2011-05-27 03:54:28 +00:00
{
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisode(It.IsAny<long>()))
.Returns<Episode>(null);
//Act
mocker.Resolve<SearchProvider>().EpisodeSearch(new ProgressNotification("Test"), 12);
2011-05-27 03:54:28 +00:00
//Assert
mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedErrors(1);
}
[Test]
public void episode_search_should_call_get_series()
{
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(4)
.Build();
var episode = Builder<Episode>.CreateNew()
.With(c => c.Series = Builder<Series>.CreateNew().Build())
.With(c => c.SeasonNumber = 12)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<EpisodeProvider>()
.Setup(c => c.GetEpisode(episode.EpisodeId))
.Returns(episode);
var indexer1 = new Mock<IndexerBase>();
indexer1.Setup(c => c.FetchEpisode(episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber))
.Returns(parseResults).Verifiable();
var indexers = new List<IndexerBase> { indexer1.Object };
mocker.GetMock<IndexerProvider>()
.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("");
mocker.GetMock<SeriesProvider>()
.Setup(s => s.GetSeries(It.IsAny<int>())).Returns(episode.Series);
//Act
mocker.Resolve<SearchProvider>().EpisodeSearch(new ProgressNotification("Test"), episode.EpisodeId);
//Assert
mocker.VerifyAllMocks();
ExceptionVerification.ExcpectedWarns(1);
indexer1.VerifyAll();
}
2011-05-27 03:07:32 +00:00
}
2011-05-28 19:23:35 +00:00
}