Added inventory provider with basic tests
This commit is contained in:
parent
53e6b60382
commit
849beef5a2
|
@ -0,0 +1,182 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.ServiceModel.Syndication;
|
||||
using AutoMoq;
|
||||
using FizzWare.NBuilder;
|
||||
using MbUnit.Framework;
|
||||
using Moq;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Providers.ExternalNotification;
|
||||
using NzbDrone.Core.Providers.Indexer;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class InventoryProviderTest : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void not_monitored_series_should_be_skipped()
|
||||
{
|
||||
var parseResult = new EpisodeParseResult()
|
||||
{
|
||||
CleanTitle = "Title",
|
||||
EpisodeTitle = "EpisodeTitle",
|
||||
Language = LanguageType.English,
|
||||
Proper = true,
|
||||
Quality = QualityTypes.Bluray720,
|
||||
Episodes = new List<int> { 3 },
|
||||
SeasonNumber = 12
|
||||
};
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(c => c.Monitored = false)
|
||||
.With(d => d.CleanTitle = parseResult.CleanTitle)
|
||||
.Build();
|
||||
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
|
||||
mocker.GetMock<SeriesProvider>()
|
||||
.Setup(p => p.FindSeries(It.IsAny<String>()))
|
||||
.Returns(series);
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<InventoryProvider>().IsNeeded(parseResult);
|
||||
|
||||
//Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void no_db_series_should_be_skipped()
|
||||
{
|
||||
var parseResult = new EpisodeParseResult()
|
||||
{
|
||||
CleanTitle = "Title",
|
||||
EpisodeTitle = "EpisodeTitle",
|
||||
Language = LanguageType.English,
|
||||
Proper = true,
|
||||
Quality = QualityTypes.Bluray720,
|
||||
Episodes = new List<int> { 3 },
|
||||
SeasonNumber = 12
|
||||
};
|
||||
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
|
||||
mocker.GetMock<SeriesProvider>()
|
||||
.Setup(p => p.FindSeries(It.IsAny<String>()))
|
||||
.Returns<Series>(null);
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<InventoryProvider>().IsNeeded(parseResult);
|
||||
|
||||
//Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void unwannted_quality_should_be_skipped()
|
||||
{
|
||||
var parseResult = new EpisodeParseResult()
|
||||
{
|
||||
CleanTitle = "Title",
|
||||
EpisodeTitle = "EpisodeTitle",
|
||||
Language = LanguageType.English,
|
||||
Proper = true,
|
||||
Quality = QualityTypes.Bluray720,
|
||||
Episodes = new List<int> { 3 },
|
||||
SeasonNumber = 12
|
||||
};
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(c => c.Monitored = true)
|
||||
.With(d => d.CleanTitle = parseResult.CleanTitle)
|
||||
.Build();
|
||||
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
mocker.GetMock<SeriesProvider>()
|
||||
.Setup(p => p.FindSeries(It.IsAny<String>()))
|
||||
.Returns(series);
|
||||
|
||||
mocker.GetMock<SeriesProvider>()
|
||||
.Setup(p => p.QualityWanted(series.SeriesId, parseResult.Quality))
|
||||
.Returns(false);
|
||||
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<InventoryProvider>().IsNeeded(parseResult);
|
||||
|
||||
//Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void unwannted_file_should_be_skipped()
|
||||
{
|
||||
|
||||
var parseResult = new EpisodeParseResult()
|
||||
{
|
||||
CleanTitle = "Title",
|
||||
EpisodeTitle = "EpisodeTitle",
|
||||
Language = LanguageType.English,
|
||||
Proper = true,
|
||||
Quality = QualityTypes.Bluray720,
|
||||
Episodes = new List<int> { 3 },
|
||||
SeasonNumber = 12
|
||||
};
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(c => c.Monitored = true)
|
||||
.With(d => d.CleanTitle = parseResult.CleanTitle)
|
||||
.Build();
|
||||
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.With(c => c.EpisodeNumber = parseResult.Episodes[0])
|
||||
.With(c => c.SeasonNumber = parseResult.SeasonNumber)
|
||||
.Build();
|
||||
|
||||
|
||||
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
|
||||
mocker.GetMock<SeriesProvider>()
|
||||
.Setup(p => p.FindSeries(It.IsAny<String>()))
|
||||
.Returns(series);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(p => p.GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber))
|
||||
.Returns(episode);
|
||||
|
||||
|
||||
mocker.GetMock<SeriesProvider>()
|
||||
.Setup(p => p.QualityWanted(series.SeriesId, parseResult.Quality))
|
||||
.Returns(true);
|
||||
|
||||
mocker.GetMock<SeasonProvider>()
|
||||
.Setup(p => p.IsIgnored(series.SeriesId, parseResult.SeasonNumber))
|
||||
.Returns(false);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(p => p.IsNeeded(parseResult, episode))
|
||||
.Returns(false);
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<InventoryProvider>().IsNeeded(parseResult);
|
||||
|
||||
//Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -85,6 +85,7 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="InventoryProviderTest.cs" />
|
||||
<Compile Include="Framework\AutoMoq\AutoMoqer.cs" />
|
||||
<Compile Include="Framework\AutoMoq\AutoMoqerTest.cs" />
|
||||
<Compile Include="Framework\AutoMoq\Unity\AutoMockingBuilderStrategy.cs">
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace NzbDrone.Core.Model
|
|||
internal string CleanTitle { get; set; }
|
||||
|
||||
internal int SeasonNumber { get; set; }
|
||||
|
||||
|
||||
internal List<int> Episodes { get; set; }
|
||||
|
||||
internal string EpisodeTitle { get; set; }
|
||||
|
@ -22,6 +22,8 @@ namespace NzbDrone.Core.Model
|
|||
|
||||
public LanguageType Language { get; set; }
|
||||
|
||||
public string NzbUrl { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (Episodes == null)
|
||||
|
|
|
@ -172,7 +172,7 @@
|
|||
<Compile Include="Model\SabnzbdInfoModel.cs" />
|
||||
<Compile Include="Providers\ExternalNotification\ExternalNotificationProviderBase.cs" />
|
||||
<Compile Include="Providers\ExternalNotification\XbmcNotificationProvider.cs" />
|
||||
<Compile Include="Providers\Indexer\IsNeededProvider.cs" />
|
||||
<Compile Include="Providers\Indexer\InventoryProvider.cs" />
|
||||
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" />
|
||||
<Compile Include="Providers\AutoConfigureProvider.cs" />
|
||||
<Compile Include="Providers\Indexer\NzbMatrix.cs" />
|
||||
|
|
|
@ -76,6 +76,7 @@ namespace NzbDrone.Core.Providers.Indexer
|
|||
var parsedEpisode = ParseFeed(item);
|
||||
if (parsedEpisode != null)
|
||||
{
|
||||
parsedEpisode.NzbUrl = NzbDownloadUrl(item);
|
||||
result.Add(parsedEpisode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Helpers;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Repository;
|
||||
using System.ServiceModel.Syndication;
|
||||
|
||||
namespace NzbDrone.Core.Providers.Indexer
|
||||
{
|
||||
public class IsNeededProvider
|
||||
public class InventoryProvider
|
||||
{
|
||||
private readonly SeriesProvider _seriesProvider;
|
||||
private readonly SeasonProvider _seasonProvider;
|
||||
|
@ -21,7 +16,7 @@ namespace NzbDrone.Core.Providers.Indexer
|
|||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public IsNeededProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, HistoryProvider historyProvider, SabProvider sabProvider)
|
||||
public InventoryProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, HistoryProvider historyProvider, SabProvider sabProvider)
|
||||
{
|
||||
_seriesProvider = seriesProvider;
|
||||
_seasonProvider = seasonProvider;
|
||||
|
@ -30,9 +25,16 @@ namespace NzbDrone.Core.Providers.Indexer
|
|||
_sabProvider = sabProvider;
|
||||
}
|
||||
|
||||
|
||||
internal bool IsNeeded(EpisodeParseResult parseResult, Series series)
|
||||
internal bool IsNeeded(EpisodeParseResult parseResult)
|
||||
{
|
||||
var series = _seriesProvider.FindSeries(parseResult.CleanTitle);
|
||||
|
||||
if (series == null)
|
||||
{
|
||||
Logger.Trace("{0} is not mapped to any series in DB. skipping", parseResult.CleanTitle);
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var episodeNumber in parseResult.Episodes)
|
||||
{
|
||||
//Todo: How to handle full season files? Currently the episode list is completely empty for these releases
|
||||
|
@ -87,7 +89,7 @@ namespace NzbDrone.Core.Providers.Indexer
|
|||
Logger.Debug("Episode {0} is not needed. skipping.", parseResult);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (_historyProvider.Exists(episodeInfo.EpisodeId, parseResult.Quality, parseResult.Proper))
|
||||
{
|
||||
Logger.Debug("Episode {0} is in history. skipping.", parseResult);
|
Loading…
Reference in New Issue