diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 80f5c3c9b..c2faea375 100644 Binary files a/NzbDrone.Core.Test/EpisodeProviderTest.cs and b/NzbDrone.Core.Test/EpisodeProviderTest.cs differ diff --git a/NzbDrone.Core.Test/Framework/ExceptionVerification.cs b/NzbDrone.Core.Test/Framework/ExceptionVerification.cs index 6f6f27331..6de716867 100644 --- a/NzbDrone.Core.Test/Framework/ExceptionVerification.cs +++ b/NzbDrone.Core.Test/Framework/ExceptionVerification.cs @@ -69,6 +69,16 @@ namespace NzbDrone.Core.Test.Framework 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) { var levelLogs = _logs.Where(l => l.Level == level).ToList(); @@ -83,5 +93,11 @@ namespace NzbDrone.Core.Test.Framework 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)); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/IndexerProviderTest.cs b/NzbDrone.Core.Test/IndexerProviderTest.cs index 6eeadec26..aa924a42d 100644 --- a/NzbDrone.Core.Test/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/IndexerProviderTest.cs @@ -7,6 +7,7 @@ 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; @@ -22,11 +23,11 @@ namespace NzbDrone.Core.Test public class IndexerProviderTest : TestBase { [Test] - [Row("nzbsorg.xml")] - [Row("nzbsrus.xml")] - [Row("newzbin.xml")] - [Row("nzbmatrix.xml")] - public void parse_feed_xml(string fileName) + [Row("nzbsorg.xml", 0)] + [Row("nzbsrus.xml", 6)] + [Row("newzbin.xml", 1)] + [Row("nzbmatrix.xml", 1)] + public void parse_feed_xml(string fileName, int warns) { var mocker = new AutoMoqer(); @@ -39,21 +40,18 @@ namespace NzbDrone.Core.Test .Setup(c => c.GetSettings(It.IsAny())) .Returns(fakeSettings); - var exceptions = mocker.Resolve().Fetch(); + var parseResults = mocker.Resolve().Fetch(); - foreach (var exception in exceptions) - { - Console.WriteLine(exception.ToString()); - } - Assert.IsEmpty(exceptions); + Assert.IsNotEmpty(parseResults); + ExceptionVerification.ExcpectedWarns(warns); } [Test] [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(); @@ -64,10 +62,32 @@ namespace NzbDrone.Core.Test .Setup(c => c.GetSettings(It.IsAny())) .Returns(fakeSettings); - mocker.GetMock() - .Setup(c => c.FindSeries(It.IsAny())) - .Returns(Builder.CreateNew().Build()); + var fakeRssItem = Builder.CreateNew() + .With(c => c.Title = new TextSyndicationContent(title)) + .With(c => c.Summary = new TextSyndicationContent(summary)) + .Build(); + var result = mocker.Resolve().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.CreateNew().Build(); + mocker.GetMock() + .Setup(c => c.GetSettings(It.IsAny())) + .Returns(fakeSettings); var fakeRssItem = Builder.CreateNew() .With(c => c.Title = new TextSyndicationContent(title)) @@ -78,31 +98,6 @@ namespace NzbDrone.Core.Test Assert.IsNotNull(result); 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.CreateNew().Build(); - mocker.GetMock() - .Setup(c => c.GetSettings(It.IsAny())) - .Returns(fakeSettings); - - mocker.GetMock(MockBehavior.Strict); - - - var fakeRssItem = Builder.CreateNew() - .With(c => c.Title = new TextSyndicationContent(title)) - .Build(); - - var result = mocker.Resolve().ParseFeed(fakeRssItem); - - Assert.IsNull(result); ExceptionVerification.ExcpectedWarns(1); } @@ -119,6 +114,8 @@ namespace NzbDrone.Core.Test .Returns(fakeSettings); mocker.Resolve().Fetch(); + + ExceptionVerification.IgnoreWarns(); } [Test] @@ -146,19 +143,14 @@ namespace NzbDrone.Core.Test .Returns(null); var indexer = mocker.Resolve(); - 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 MockIndexerProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, - EpisodeProvider episodeProvider, ConfigProvider configProvider, - HttpProvider httpProvider, IndexerProvider indexerProvider, - HistoryProvider historyProvider, SabProvider sabProvider, IEnumerable externalNotificationProvider) - : base(seriesProvider, seasonProvider, episodeProvider, - configProvider, httpProvider, indexerProvider, historyProvider, - sabProvider, externalNotificationProvider) + public MockIndexerProvider(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider) + : base(httpProvider, configProvider, indexerProvider) { } @@ -177,10 +169,6 @@ namespace NzbDrone.Core.Test get { return "Mocked Indexer"; } } - public override bool SupportsBacklog - { - get { return false; } - } protected override string NzbDownloadUrl(SyndicationItem item) { @@ -190,13 +178,8 @@ namespace NzbDrone.Core.Test public class TestUrlIndexer : IndexerProviderBase { - public TestUrlIndexer(SeriesProvider seriesProvider, SeasonProvider seasonProvider, - EpisodeProvider episodeProvider, ConfigProvider configProvider, - HttpProvider httpProvider, IndexerProvider indexerProvider, - HistoryProvider historyProvider, SabProvider sabProvider, IEnumerable externalNotificationProvider) - : base(seriesProvider, seasonProvider, episodeProvider, - configProvider, httpProvider, indexerProvider, historyProvider, - sabProvider, externalNotificationProvider) + public TestUrlIndexer(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider) + : base(httpProvider, configProvider, indexerProvider) { } @@ -205,11 +188,6 @@ namespace NzbDrone.Core.Test get { return "All Urls"; } } - public override bool SupportsBacklog - { - get { return false; } - } - protected override string[] Urls { get { return new[] { "http://rss.nzbmatrix.com/rss.php?cat=TV" }; } @@ -223,13 +201,8 @@ namespace NzbDrone.Core.Test public class CustomParserIndexer : IndexerProviderBase { - public CustomParserIndexer(SeriesProvider seriesProvider, SeasonProvider seasonProvider, - EpisodeProvider episodeProvider, ConfigProvider configProvider, - HttpProvider httpProvider, IndexerProvider indexerProvider, - HistoryProvider historyProvider, SabProvider sabProvider, IEnumerable externalNotificationProvider) - : base(seriesProvider, seasonProvider, episodeProvider, - configProvider, httpProvider, indexerProvider, historyProvider, - sabProvider, externalNotificationProvider) + public CustomParserIndexer(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider) + : base(httpProvider, configProvider, indexerProvider) { } @@ -238,10 +211,7 @@ namespace NzbDrone.Core.Test get { return "Custom parser"; } } - public override bool SupportsBacklog - { - get { return false; } - } + protected override string[] Urls { @@ -255,6 +225,7 @@ namespace NzbDrone.Core.Test protected override Model.EpisodeParseResult CustomParser(SyndicationItem item, Model.EpisodeParseResult currentResult) { + if (currentResult == null) currentResult = new EpisodeParseResult(); currentResult.EpisodeTitle = item.Summary.Text; return currentResult; } diff --git a/NzbDrone.Core.Test/SabProviderTest.cs b/NzbDrone.Core.Test/SabProviderTest.cs index 229d2564e..8f4f37494 100644 --- a/NzbDrone.Core.Test/SabProviderTest.cs +++ b/NzbDrone.Core.Test/SabProviderTest.cs @@ -221,18 +221,16 @@ namespace NzbDrone.Core.Test var parsResult = new EpisodeParseResult() { - SeriesId = 12, AirDate = DateTime.Now, Episodes = episodes.ToList(), Proper = proper, Quality = quality, SeasonNumber = seasons, EpisodeTitle = title, - FolderName = "My Series Name" }; //Act - var actual = mocker.Resolve().GetSabTitle(parsResult); + var actual = mocker.Resolve().GetSabTitle(parsResult, "My Series Name"); //Assert Assert.AreEqual(excpected, actual);