Basic indexer tests are working

This commit is contained in:
kay.one 2011-05-19 21:18:51 -07:00
parent 9c1ff4af6b
commit 3e1ff7e96e
4 changed files with 63 additions and 78 deletions

View File

@ -69,6 +69,16 @@ namespace NzbDrone.Core.Test.Framework
Excpected(LogLevel.Warn, count); Excpected(LogLevel.Warn, count);
} }
internal static void IgnoreWarns()
{
Ignore(LogLevel.Warn);
}
internal static void IgnoreErrors()
{
Ignore(LogLevel.Error);
}
private static void Excpected(LogLevel level, int count) private static void Excpected(LogLevel level, int count)
{ {
var levelLogs = _logs.Where(l => l.Level == level).ToList(); var levelLogs = _logs.Where(l => l.Level == level).ToList();
@ -83,5 +93,11 @@ namespace NzbDrone.Core.Test.Framework
levelLogs.ForEach(c => _logs.Remove(c)); levelLogs.ForEach(c => _logs.Remove(c));
} }
private static void Ignore(LogLevel level)
{
var levelLogs = _logs.Where(l => l.Level == level).ToList();
levelLogs.ForEach(c => _logs.Remove(c));
}
} }
} }

View File

@ -7,6 +7,7 @@ using AutoMoq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using MbUnit.Framework; using MbUnit.Framework;
using Moq; using Moq;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.ExternalNotification; using NzbDrone.Core.Providers.ExternalNotification;
@ -22,11 +23,11 @@ namespace NzbDrone.Core.Test
public class IndexerProviderTest : TestBase public class IndexerProviderTest : TestBase
{ {
[Test] [Test]
[Row("nzbsorg.xml")] [Row("nzbsorg.xml", 0)]
[Row("nzbsrus.xml")] [Row("nzbsrus.xml", 6)]
[Row("newzbin.xml")] [Row("newzbin.xml", 1)]
[Row("nzbmatrix.xml")] [Row("nzbmatrix.xml", 1)]
public void parse_feed_xml(string fileName) public void parse_feed_xml(string fileName, int warns)
{ {
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
@ -39,21 +40,18 @@ namespace NzbDrone.Core.Test
.Setup(c => c.GetSettings(It.IsAny<Type>())) .Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings); .Returns(fakeSettings);
var exceptions = mocker.Resolve<MockIndexerProvider>().Fetch(); var parseResults = mocker.Resolve<MockIndexerProvider>().Fetch();
foreach (var exception in exceptions)
{
Console.WriteLine(exception.ToString());
}
Assert.IsEmpty(exceptions); Assert.IsNotEmpty(parseResults);
ExceptionVerification.ExcpectedWarns(warns);
} }
[Test] [Test]
[Row("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)] [Row("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)]
public void parse_feed_test_success(string title, int season, int episode, QualityTypes quality) public void custome_parser_partial_success(string title, int season, int episode, QualityTypes quality)
{ {
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
@ -64,10 +62,32 @@ namespace NzbDrone.Core.Test
.Setup(c => c.GetSettings(It.IsAny<Type>())) .Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings); .Returns(fakeSettings);
mocker.GetMock<SeriesProvider>() var fakeRssItem = Builder<SyndicationItem>.CreateNew()
.Setup(c => c.FindSeries(It.IsAny<String>())) .With(c => c.Title = new TextSyndicationContent(title))
.Returns(Builder<Series>.CreateNew().Build()); .With(c => c.Summary = new TextSyndicationContent(summary))
.Build();
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
Assert.IsNotNull(result);
Assert.AreEqual(summary, result.EpisodeTitle);
Assert.AreEqual(season, result.SeasonNumber);
Assert.AreEqual(episode, result.Episodes[0]);
Assert.AreEqual(quality, result.Quality);
}
[Test]
[Row("Adventure.Inc.DVDRip.XviD-OSiTV")]
public void custome_parser_full_parse(string title)
{
var mocker = new AutoMoqer();
const string summary = "My fake summary";
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);
var fakeRssItem = Builder<SyndicationItem>.CreateNew() var fakeRssItem = Builder<SyndicationItem>.CreateNew()
.With(c => c.Title = new TextSyndicationContent(title)) .With(c => c.Title = new TextSyndicationContent(title))
@ -78,31 +98,6 @@ namespace NzbDrone.Core.Test
Assert.IsNotNull(result); Assert.IsNotNull(result);
Assert.AreEqual(summary, result.EpisodeTitle); Assert.AreEqual(summary, result.EpisodeTitle);
}
[Test]
[Row("Adventure.Inc.DVDRip.XviD-OSiTV")]
public void parse_feed_test_fail(string title)
{
var mocker = new AutoMoqer();
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
mocker.GetMock<IndexerProvider>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);
mocker.GetMock<SeriesProvider>(MockBehavior.Strict);
var fakeRssItem = Builder<SyndicationItem>.CreateNew()
.With(c => c.Title = new TextSyndicationContent(title))
.Build();
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
Assert.IsNull(result);
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
} }
@ -119,6 +114,8 @@ namespace NzbDrone.Core.Test
.Returns(fakeSettings); .Returns(fakeSettings);
mocker.Resolve<TestUrlIndexer>().Fetch(); mocker.Resolve<TestUrlIndexer>().Fetch();
ExceptionVerification.IgnoreWarns();
} }
[Test] [Test]
@ -146,19 +143,14 @@ namespace NzbDrone.Core.Test
.Returns<Series>(null); .Returns<Series>(null);
var indexer = mocker.Resolve<MockIndexerProvider>(); var indexer = mocker.Resolve<MockIndexerProvider>();
indexer.ProcessItem(new SyndicationItem { Title = new TextSyndicationContent("Adventure.Inc.S01E18.DVDRip.XviD-OSiTV") }); //indexer.ProcessItem(new SyndicationItem { Title = new TextSyndicationContent("Adventure.Inc.S01E18.DVDRip.XviD-OSiTV") });
} }
} }
public class MockIndexerProvider : IndexerProviderBase public class MockIndexerProvider : IndexerProviderBase
{ {
public MockIndexerProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, public MockIndexerProvider(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider)
EpisodeProvider episodeProvider, ConfigProvider configProvider, : base(httpProvider, configProvider, indexerProvider)
HttpProvider httpProvider, IndexerProvider indexerProvider,
HistoryProvider historyProvider, SabProvider sabProvider, IEnumerable<ExternalNotificationProviderBase> externalNotificationProvider)
: base(seriesProvider, seasonProvider, episodeProvider,
configProvider, httpProvider, indexerProvider, historyProvider,
sabProvider, externalNotificationProvider)
{ {
} }
@ -177,10 +169,6 @@ namespace NzbDrone.Core.Test
get { return "Mocked Indexer"; } get { return "Mocked Indexer"; }
} }
public override bool SupportsBacklog
{
get { return false; }
}
protected override string NzbDownloadUrl(SyndicationItem item) protected override string NzbDownloadUrl(SyndicationItem item)
{ {
@ -190,13 +178,8 @@ namespace NzbDrone.Core.Test
public class TestUrlIndexer : IndexerProviderBase public class TestUrlIndexer : IndexerProviderBase
{ {
public TestUrlIndexer(SeriesProvider seriesProvider, SeasonProvider seasonProvider, public TestUrlIndexer(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider)
EpisodeProvider episodeProvider, ConfigProvider configProvider, : base(httpProvider, configProvider, indexerProvider)
HttpProvider httpProvider, IndexerProvider indexerProvider,
HistoryProvider historyProvider, SabProvider sabProvider, IEnumerable<ExternalNotificationProviderBase> externalNotificationProvider)
: base(seriesProvider, seasonProvider, episodeProvider,
configProvider, httpProvider, indexerProvider, historyProvider,
sabProvider, externalNotificationProvider)
{ {
} }
@ -205,11 +188,6 @@ namespace NzbDrone.Core.Test
get { return "All Urls"; } get { return "All Urls"; }
} }
public override bool SupportsBacklog
{
get { return false; }
}
protected override string[] Urls protected override string[] Urls
{ {
get { return new[] { "http://rss.nzbmatrix.com/rss.php?cat=TV" }; } get { return new[] { "http://rss.nzbmatrix.com/rss.php?cat=TV" }; }
@ -223,13 +201,8 @@ namespace NzbDrone.Core.Test
public class CustomParserIndexer : IndexerProviderBase public class CustomParserIndexer : IndexerProviderBase
{ {
public CustomParserIndexer(SeriesProvider seriesProvider, SeasonProvider seasonProvider, public CustomParserIndexer(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider)
EpisodeProvider episodeProvider, ConfigProvider configProvider, : base(httpProvider, configProvider, indexerProvider)
HttpProvider httpProvider, IndexerProvider indexerProvider,
HistoryProvider historyProvider, SabProvider sabProvider, IEnumerable<ExternalNotificationProviderBase> externalNotificationProvider)
: base(seriesProvider, seasonProvider, episodeProvider,
configProvider, httpProvider, indexerProvider, historyProvider,
sabProvider, externalNotificationProvider)
{ {
} }
@ -238,10 +211,7 @@ namespace NzbDrone.Core.Test
get { return "Custom parser"; } get { return "Custom parser"; }
} }
public override bool SupportsBacklog
{
get { return false; }
}
protected override string[] Urls protected override string[] Urls
{ {
@ -255,6 +225,7 @@ namespace NzbDrone.Core.Test
protected override Model.EpisodeParseResult CustomParser(SyndicationItem item, Model.EpisodeParseResult currentResult) protected override Model.EpisodeParseResult CustomParser(SyndicationItem item, Model.EpisodeParseResult currentResult)
{ {
if (currentResult == null) currentResult = new EpisodeParseResult();
currentResult.EpisodeTitle = item.Summary.Text; currentResult.EpisodeTitle = item.Summary.Text;
return currentResult; return currentResult;
} }

View File

@ -221,18 +221,16 @@ namespace NzbDrone.Core.Test
var parsResult = new EpisodeParseResult() var parsResult = new EpisodeParseResult()
{ {
SeriesId = 12,
AirDate = DateTime.Now, AirDate = DateTime.Now,
Episodes = episodes.ToList(), Episodes = episodes.ToList(),
Proper = proper, Proper = proper,
Quality = quality, Quality = quality,
SeasonNumber = seasons, SeasonNumber = seasons,
EpisodeTitle = title, EpisodeTitle = title,
FolderName = "My Series Name"
}; };
//Act //Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult); var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult, "My Series Name");
//Assert //Assert
Assert.AreEqual(excpected, actual); Assert.AreEqual(excpected, actual);