From 3e1ff7e96ee986759c8394f12a3c17904d5919be Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 19 May 2011 21:18:51 -0700 Subject: [PATCH] Basic indexer tests are working --- NzbDrone.Core.Test/EpisodeProviderTest.cs | Bin 8242 -> 6888 bytes .../Framework/ExceptionVerification.cs | 16 +++ NzbDrone.Core.Test/IndexerProviderTest.cs | 121 +++++++----------- NzbDrone.Core.Test/SabProviderTest.cs | 4 +- 4 files changed, 63 insertions(+), 78 deletions(-) diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 80f5c3c9b6f0e31d34e37d7eb26501f2f1993353..c2faea37504c2340fe9bc77d9ec539df75d6d70f 100644 GIT binary patch delta 1711 zcmb7EO>7fK6qcPI$LpQ=H?gz+!A?RGgX>jN1*)WJ2_#6V5(FeDLXbvIGK2-=O?THM zDT)M_iVKR+>!n9-+z@bV5nK_d61^hS9@|5OKu8?vd$YT&<6K}@nt3ztdvCt?GxOlc zKO_5J|Ms|UYPGfe+?HwaD`QM*T$X3F+K*%Gc3*F%NinHa)@r(GX)7k`m-a|2Pa67FZIv5% zhQn*O{xo0LP0iActuY3DJ}u?K=C7_U&uGi#$%<7$TLyQ0*(8&$F)5GVxp{6{$F)tX zZtz70fBF{DkQ9#oBLwd_3#bOX`KZwx#nGEPk3@)|j zaCNi&2TYX$lT?~xoJ)7;u(?qftDH)Ff3PSI7 zq~UGgfFm95P=z!WwTwD1=RxqWBP~djHrlhL z9cdQVRJ=FRuLX}1(guAk$!l$ZwA<4 z0ecS<+Vu@Qi6vsCJYUyLeU(qwF6c$Un;KxII|%P$@#fNd9-ZQgLOe_sKA{ksi9_9< zy`2uxj0|2U@~y)qCc&#nl1k!7@tLf^PFJL>vE#_dPSM>^20o;ez4;|qUwxJ<%nIhN z@zRYeQ%#Ol6?T-7y_+u-s?2!qySbrZN*)n(Klg5xr_Fin{Xv79^{O@WX)yAJH<4P; zzK`)y&pX~i_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FgAg9y~ zQoTkwBZ^B_%`bIQEnd@Pn)E1hbfw$)hRkY%~JsjqxPs+cEa!=`5D^wF0V zPwRZ!Z%7!lyPIH*>W{*L8Y)F5;QpbwKpUB-+>P;+IoDyTr%s@^%V~x}4c2`4ji@^G zbge0sFJjU_tDo@E8u&7c&l!i?^Z2$bKq5c-Po``_Lpay0EkGNbB%UMlnvMsi^&rX{ z4gxL7)Hw3Dq>L56O*vzfn%!q8H5(}0FdThPg;n9!s(x)wG0S^f`@vG7f>XU?5oc=3 zEoKJbsC&lx4sN#?1W_doL(zeQ8K~auv1GYoCTbHYVie6_>KbylTL^7#gW_V;c720bSne7IOZX3n%j#mx zEIBY7OhU?|)dY&ovZy>_ZK**M{#!v;h>V|3bUC-Sc3@QhCrP-qFRCv%_*H-RmzVb5 zUJtIHYhfkwDPnzaE6n0K49rf3*z`DYDGIL>yuP`S@E6<74g8;Ciq|DOj;D?2EI5G< zjv 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);