From 0d582f12fb35be3340d3c7f0039aa0ab44bbd977 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 22 Jan 2012 19:01:16 -0800 Subject: [PATCH] Fixed 503 Http errors not marking the test as ignored. --- NzbDrone.Core.Test/IndexerTests.cs | 48 ++++++------------- NzbDrone.Test.Common/ExceptionVerification.cs | 11 +++++ 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/NzbDrone.Core.Test/IndexerTests.cs b/NzbDrone.Core.Test/IndexerTests.cs index a60547e2c..50abce19d 100644 --- a/NzbDrone.Core.Test/IndexerTests.cs +++ b/NzbDrone.Core.Test/IndexerTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Net; using System.ServiceModel.Syndication; @@ -17,7 +16,6 @@ using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.ProviderTests; using NzbDrone.Test.Common; -using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Core.Test { @@ -32,7 +30,7 @@ namespace NzbDrone.Core.Test [TestCase("nzbmatrix.xml", 2)] public void parse_feed_xml(string fileName, int warns) { - + Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) @@ -63,7 +61,7 @@ namespace NzbDrone.Core.Test [Test] public void newzbin_parses_languae() { - + Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) @@ -88,7 +86,6 @@ namespace NzbDrone.Core.Test [Test] public void newzbin_rss_fetch() { - Mocker.Resolve(); var fakeSettings = Builder.CreateNew().Build(); Mocker.GetMock() @@ -117,7 +114,7 @@ namespace NzbDrone.Core.Test parseResults.Should().OnlyContain(s => s.Indexer == newzbinProvider.Name); parseResults.Should().OnlyContain(s => !String.IsNullOrEmpty(s.OriginalString)); - ExceptionVerification.MarkInconclusive(typeof(WebException)); + Mark503Inconclusive(); ExceptionVerification.IgnoreWarns(); } @@ -125,8 +122,6 @@ namespace NzbDrone.Core.Test [TestCase("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)] public void custome_parser_partial_success(string title, int season, int episode, QualityTypes quality) { - - const string summary = "My fake summary"; var fakeSettings = Builder.CreateNew().Build(); @@ -152,8 +147,6 @@ namespace NzbDrone.Core.Test [TestCase("Adventure.Inc.DVDRip.XviD-OSiTV")] public void custome_parser_full_parse(string title) { - - const string summary = "My fake summary"; var fakeSettings = Builder.CreateNew().Build(); @@ -176,7 +169,6 @@ namespace NzbDrone.Core.Test [Test] public void downloadFeed() { - Mocker.SetConstant(new HttpProvider()); var fakeSettings = Builder.CreateNew().Build(); @@ -205,8 +197,8 @@ namespace NzbDrone.Core.Test Mocker.Resolve(); var result = Mocker.Resolve().FetchEpisode(title, season, episode); - - ExceptionVerification.MarkInconclusive(typeof(WebException)); + + Mark503Inconclusive(); result.Should().NotBeEmpty(); result.Should().OnlyContain(r => r.SeasonNumber == season); @@ -220,8 +212,6 @@ namespace NzbDrone.Core.Test [TestCase("In plain Sight", 1, 11, Ignore = true)] public void newzbin_search_returns_valid_results(string title, int season, int episode) { - - Mocker.GetMock() .SetupGet(c => c.NewzbinUsername) .Returns("nzbdrone"); @@ -234,21 +224,16 @@ namespace NzbDrone.Core.Test var result = Mocker.Resolve().FetchEpisode(title, season, episode); - ExceptionVerification.MarkInconclusive(typeof(WebException)); - ExceptionVerification.IgnoreWarns(); + Mark503Inconclusive(); result.Should().NotBeEmpty(); result.Should().OnlyContain(r => r.CleanTitle == Parser.NormalizeTitle(title)); result.Should().OnlyContain(r => r.SeasonNumber == season); result.Should().OnlyContain(r => r.EpisodeNumbers.Contains(episode)); - - } [Test] public void nzbmatrix_search_returns_valid_results() { - - Mocker.GetMock() .SetupGet(c => c.NzbMatrixUsername) .Returns(""); @@ -261,7 +246,7 @@ namespace NzbDrone.Core.Test var result = Mocker.Resolve().FetchEpisode("Simpsons", 21, 23); - ExceptionVerification.MarkInconclusive(typeof(WebException)); + Mark503Inconclusive(); result.Should().NotBeEmpty(); result.Should().OnlyContain(r => r.CleanTitle == "simpsons"); @@ -273,7 +258,7 @@ namespace NzbDrone.Core.Test [Test] public void nzbmatrix_multi_word_search_returns_valid_results() { - + Mocker.GetMock() .SetupGet(c => c.NzbMatrixUsername) @@ -287,7 +272,7 @@ namespace NzbDrone.Core.Test var result = Mocker.Resolve().FetchEpisode("Blue Bloods", 1, 19); - ExceptionVerification.MarkInconclusive(typeof(WebException)); + Mark503Inconclusive(); result.Should().NotBeEmpty(); result.Should().OnlyContain(r => r.CleanTitle == "bluebloods"); @@ -309,9 +294,6 @@ namespace NzbDrone.Core.Test [Test] public void size_newzbin() { - //Setup - - Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) .Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\newzbin.xml")); @@ -327,7 +309,7 @@ namespace NzbDrone.Core.Test public void size_nzbmatrix() { //Setup - + Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) @@ -344,7 +326,7 @@ namespace NzbDrone.Core.Test public void size_nzbsorg() { //Setup - + Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) @@ -361,7 +343,7 @@ namespace NzbDrone.Core.Test public void size_nzbsrus() { //Setup - + Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) @@ -383,7 +365,7 @@ namespace NzbDrone.Core.Test .Throws(new WebException("503")); Mocker.Resolve().FetchRss(); - + ExceptionVerification.ExpectedErrors(0); ExceptionVerification.ExpectedWarns(1); } @@ -401,10 +383,10 @@ namespace NzbDrone.Core.Test ExceptionVerification.ExpectedWarns(0); } - [TearDown] - public void TearDown() + private static void Mark503Inconclusive() { ExceptionVerification.MarkInconclusive(typeof(WebException)); + ExceptionVerification.MarkInconclusive("The remote server returned an error: (503) Server Unavailable."); } } } diff --git a/NzbDrone.Test.Common/ExceptionVerification.cs b/NzbDrone.Test.Common/ExceptionVerification.cs index ead7ee9e9..b044dbbd1 100644 --- a/NzbDrone.Test.Common/ExceptionVerification.cs +++ b/NzbDrone.Test.Common/ExceptionVerification.cs @@ -86,6 +86,17 @@ namespace NzbDrone.Test.Common } } + public static void MarkInconclusive(string text) + { + var inconclusiveLogs = _logs.Where(l => l.Message.Contains(text)).ToList(); + + if (inconclusiveLogs.Count != 0) + { + inconclusiveLogs.ForEach(c => _logs.Remove(c)); + Assert.Inconclusive(GetLogsString(inconclusiveLogs)); + } + } + private static void Excpected(LogLevel level, int count) { var levelLogs = _logs.Where(l => l.Level == level).ToList();