EpisodeSearchJob bug fixes/tests
This commit is contained in:
parent
4e8dd47e27
commit
5a812801b7
|
@ -0,0 +1,153 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using AutoMoq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using Gallio.Framework;
|
||||||
|
using MbUnit.Framework;
|
||||||
|
using MbUnit.Framework.ContractVerifiers;
|
||||||
|
using Moq;
|
||||||
|
using NzbDrone.Core.Model;
|
||||||
|
using NzbDrone.Core.Model.Notification;
|
||||||
|
using NzbDrone.Core.Providers;
|
||||||
|
using NzbDrone.Core.Providers.Jobs;
|
||||||
|
using NzbDrone.Core.Repository;
|
||||||
|
using NzbDrone.Core.Repository.Quality;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
public class EpisodeSearchJobTest : TestBase
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void ParseResult_should_return_after_match()
|
||||||
|
{
|
||||||
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(5)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var episode = Builder<Episode>.CreateNew().Build();
|
||||||
|
|
||||||
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
|
|
||||||
|
mocker.GetMock<InventoryProvider>()
|
||||||
|
.Setup(c => c.IsNeeded(It.IsAny<EpisodeParseResult>())).Returns(true)
|
||||||
|
.AtMostOnce();
|
||||||
|
|
||||||
|
mocker.GetMock<DownloadProvider>()
|
||||||
|
.Setup(c => c.DownloadReport(It.IsAny<EpisodeParseResult>())).Returns(true)
|
||||||
|
.AtMostOnce();
|
||||||
|
|
||||||
|
mocker.Resolve<EpisodeSearchJob>().ProcessResults(new ProgressNotification("Test"), episode, parseResults);
|
||||||
|
|
||||||
|
|
||||||
|
mocker.VerifyAllMocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void higher_quality_should_be_called_first()
|
||||||
|
{
|
||||||
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(2)
|
||||||
|
.WhereTheFirst(1).Has(c => c.Quality = QualityTypes.Bluray1080p)
|
||||||
|
.AndTheNext(1).Has(c => c.Quality = QualityTypes.DVD)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var episode = Builder<Episode>.CreateNew().Build();
|
||||||
|
|
||||||
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
|
|
||||||
|
mocker.GetMock<InventoryProvider>()
|
||||||
|
.Setup(c => c.IsNeeded(parseResults[0])).Returns(true)
|
||||||
|
.AtMostOnce();
|
||||||
|
|
||||||
|
mocker.GetMock<DownloadProvider>()
|
||||||
|
.Setup(c => c.DownloadReport(parseResults[0])).Returns(true)
|
||||||
|
.AtMostOnce();
|
||||||
|
|
||||||
|
mocker.Resolve<EpisodeSearchJob>().ProcessResults(new ProgressNotification("Test"), episode, parseResults);
|
||||||
|
|
||||||
|
|
||||||
|
mocker.VerifyAllMocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void when_same_quality_proper_should_be_called_first()
|
||||||
|
{
|
||||||
|
var parseResults = Builder<EpisodeParseResult>.CreateListOfSize(20)
|
||||||
|
.WhereAll().Have(c => c.Quality = QualityTypes.DVD)
|
||||||
|
.And(c => c.Proper = false)
|
||||||
|
.WhereRandom(1).Has(c => c.Proper = true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
Assert.Count(1, parseResults.Where(c => c.Proper));
|
||||||
|
|
||||||
|
var episode = Builder<Episode>.CreateNew().Build();
|
||||||
|
|
||||||
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
|
|
||||||
|
mocker.GetMock<InventoryProvider>()
|
||||||
|
.Setup(c => c.IsNeeded(It.Is<EpisodeParseResult>(p => p.Proper))).Returns(true)
|
||||||
|
.AtMostOnce();
|
||||||
|
|
||||||
|
mocker.GetMock<DownloadProvider>()
|
||||||
|
.Setup(c => c.DownloadReport(It.Is<EpisodeParseResult>(p => p.Proper))).Returns(true)
|
||||||
|
.AtMostOnce();
|
||||||
|
|
||||||
|
mocker.Resolve<EpisodeSearchJob>().ProcessResults(new ProgressNotification("Test"), episode, parseResults);
|
||||||
|
|
||||||
|
|
||||||
|
mocker.VerifyAllMocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void when_not_needed_should_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.IsNeeded(It.IsAny<EpisodeParseResult>())).Returns(false);
|
||||||
|
|
||||||
|
mocker.Resolve<EpisodeSearchJob>().ProcessResults(new ProgressNotification("Test"), episode, parseResults);
|
||||||
|
|
||||||
|
|
||||||
|
mocker.VerifyAllMocks();
|
||||||
|
mocker.GetMock<InventoryProvider>().Verify(c => c.IsNeeded(It.IsAny<EpisodeParseResult>()), Times.Exactly(4));
|
||||||
|
|
||||||
|
ExceptionVerification.ExcpectedWarns(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void failed_is_neede_should_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.IsNeeded(It.IsAny<EpisodeParseResult>())).Throws(new Exception());
|
||||||
|
|
||||||
|
mocker.Resolve<EpisodeSearchJob>().ProcessResults(new ProgressNotification("Test"), episode, parseResults);
|
||||||
|
|
||||||
|
|
||||||
|
mocker.VerifyAllMocks();
|
||||||
|
mocker.GetMock<InventoryProvider>().Verify(c => c.IsNeeded(It.IsAny<EpisodeParseResult>()), Times.Exactly(4));
|
||||||
|
|
||||||
|
ExceptionVerification.ExcpectedErrors(4);
|
||||||
|
ExceptionVerification.ExcpectedWarns(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -86,6 +86,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DownloadProviderTest.cs" />
|
<Compile Include="DownloadProviderTest.cs" />
|
||||||
|
<Compile Include="EpisodeSearchJobTest.cs" />
|
||||||
<Compile Include="EpisodeStatusTest.cs" />
|
<Compile Include="EpisodeStatusTest.cs" />
|
||||||
<Compile Include="ImportNewSeriesJobTest.cs" />
|
<Compile Include="ImportNewSeriesJobTest.cs" />
|
||||||
<Compile Include="DiskScanJobTest.cs" />
|
<Compile Include="DiskScanJobTest.cs" />
|
||||||
|
|
|
@ -12,20 +12,23 @@ namespace NzbDrone.Core.Providers
|
||||||
private readonly SeasonProvider _seasonProvider;
|
private readonly SeasonProvider _seasonProvider;
|
||||||
private readonly EpisodeProvider _episodeProvider;
|
private readonly EpisodeProvider _episodeProvider;
|
||||||
private readonly HistoryProvider _historyProvider;
|
private readonly HistoryProvider _historyProvider;
|
||||||
private readonly SabProvider _sabProvider;
|
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public InventoryProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, HistoryProvider historyProvider, SabProvider sabProvider)
|
public InventoryProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, HistoryProvider historyProvider)
|
||||||
{
|
{
|
||||||
_seriesProvider = seriesProvider;
|
_seriesProvider = seriesProvider;
|
||||||
_seasonProvider = seasonProvider;
|
_seasonProvider = seasonProvider;
|
||||||
_episodeProvider = episodeProvider;
|
_episodeProvider = episodeProvider;
|
||||||
_historyProvider = historyProvider;
|
_historyProvider = historyProvider;
|
||||||
_sabProvider = sabProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool IsNeeded(EpisodeParseResult parseResult)
|
public InventoryProvider()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool IsNeeded(EpisodeParseResult parseResult)
|
||||||
{
|
{
|
||||||
var series = _seriesProvider.FindSeries(parseResult.CleanTitle);
|
var series = _seriesProvider.FindSeries(parseResult.CleanTitle);
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
|
|
||||||
public void ProcessResults(ProgressNotification notification, Episode episode, IEnumerable<EpisodeParseResult> reports)
|
public void ProcessResults(ProgressNotification notification, Episode episode, IEnumerable<EpisodeParseResult> reports)
|
||||||
{
|
{
|
||||||
foreach (var episodeParseResult in reports.OrderBy(c => c.Quality).ThenBy(c => c.Proper))
|
foreach (var episodeParseResult in reports.OrderByDescending(c => c.Quality).ThenByDescending(c => c.Proper))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue