From 7dd846b9e9969762338d01433fa1dda3415f61c1 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 21 Dec 2012 09:05:50 -0800 Subject: [PATCH] More tests for nzbx --- .../IndexerFixture.cs} | 100 +++------------ .../IndexerTests/NzbxFixture.cs | 119 ++++++++++++++++++ NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 3 +- 3 files changed, 138 insertions(+), 84 deletions(-) rename NzbDrone.Core.Test/{IndexerTests.cs => IndexerTests/IndexerFixture.cs} (88%) create mode 100644 NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs diff --git a/NzbDrone.Core.Test/IndexerTests.cs b/NzbDrone.Core.Test/IndexerTests/IndexerFixture.cs similarity index 88% rename from NzbDrone.Core.Test/IndexerTests.cs rename to NzbDrone.Core.Test/IndexerTests/IndexerFixture.cs index cd50d82c7..c325cb3e3 100644 --- a/NzbDrone.Core.Test/IndexerTests.cs +++ b/NzbDrone.Core.Test/IndexerTests/IndexerFixture.cs @@ -20,12 +20,27 @@ using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.ProviderTests; using NzbDrone.Test.Common; -namespace NzbDrone.Core.Test +namespace NzbDrone.Core.Test.IndexerTests { [TestFixture] // ReSharper disable InconsistentNaming - public class IndexerTests : CoreTest + public class IndexerFixture : CoreTest { + private void WithConfiguredIndexers() + { + Mocker.GetMock().SetupGet(c => c.NzbsOrgHash).Returns("MockedConfigValue"); + Mocker.GetMock().SetupGet(c => c.NzbsOrgUId).Returns("MockedConfigValue"); + + Mocker.GetMock().SetupGet(c => c.NzbsrusHash).Returns("MockedConfigValue"); + Mocker.GetMock().SetupGet(c => c.NzbsrusUId).Returns("MockedConfigValue"); + + Mocker.GetMock().SetupGet(c => c.FileSharingTalkUid).Returns("MockedConfigValue"); + Mocker.GetMock().SetupGet(c => c.FileSharingTalkSecret).Returns("MockedConfigValue"); + + Mocker.GetMock().SetupGet(c => c.OmgwtfnzbsUsername).Returns("MockedConfigValue"); + Mocker.GetMock().SetupGet(c => c.OmgwtfnzbsApiKey).Returns("MockedConfigValue"); + } + [TestCase("nzbsrus.xml")] [TestCase("newznab.xml")] [TestCase("wombles.xml")] @@ -59,21 +74,6 @@ namespace NzbDrone.Core.Test parseResults.Should().OnlyContain(s => s.Age >= 0); } - private void WithConfiguredIndexers() - { - Mocker.GetMock().SetupGet(c => c.NzbsOrgHash).Returns("MockedConfigValue"); - Mocker.GetMock().SetupGet(c => c.NzbsOrgUId).Returns("MockedConfigValue"); - - Mocker.GetMock().SetupGet(c => c.NzbsrusHash).Returns("MockedConfigValue"); - Mocker.GetMock().SetupGet(c => c.NzbsrusUId).Returns("MockedConfigValue"); - - Mocker.GetMock().SetupGet(c => c.FileSharingTalkUid).Returns("MockedConfigValue"); - Mocker.GetMock().SetupGet(c => c.FileSharingTalkSecret).Returns("MockedConfigValue"); - - Mocker.GetMock().SetupGet(c => c.OmgwtfnzbsUsername).Returns("MockedConfigValue"); - Mocker.GetMock().SetupGet(c => c.OmgwtfnzbsApiKey).Returns("MockedConfigValue"); - } - [Test] public void custome_parser_partial_success() { @@ -229,38 +229,6 @@ namespace NzbDrone.Core.Test parseResults[0].Size.Should().Be(236820890); } - [Test] - public void size_nzbx_recent() - { - WithConfiguredIndexers(); - - Mocker.GetMock() - .Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json")); - - //Act - var parseResults = Mocker.Resolve().FetchRss(); - - parseResults.Should().HaveCount(1); - parseResults[0].Size.Should().Be(890190951); - } - - [Test] - public void size_nzbx_search() - { - WithConfiguredIndexers(); - - Mocker.GetMock() - .Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json")); - - //Act - var parseResults = Mocker.Resolve().FetchEpisode("30 Rock", 1, 1); - - parseResults.Should().HaveCount(1); - parseResults[0].Size.Should().Be(418067671); - } - [Test] public void Server_Unavailable_503_should_not_log_exception() { @@ -520,39 +488,5 @@ namespace NzbDrone.Core.Test parseResults.Should().HaveCount(1); parseResults[0].NzbInfoUrl.Should().Be("http://omgwtfnzbs.com/details.php?id=OAl4g"); } - - [Test] - public void nzbx_parse_recent() - { - WithConfiguredIndexers(); - - Mocker.GetMock() - .Setup(h => h.DownloadString(It.IsAny(), It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_recent.json")); - - var parseResults = Mocker.Resolve().FetchRss(); - - parseResults.Should().NotBeEmpty(); - parseResults.Should().OnlyContain(s => s.Indexer == "nzbx"); - parseResults.Should().OnlyContain(s => !String.IsNullOrEmpty(s.OriginalString)); - parseResults.Should().OnlyContain(s => s.Age >= 0); - } - - [Test] - public void nzbx_parse_search() - { - WithConfiguredIndexers(); - - Mocker.GetMock() - .Setup(h => h.DownloadString(It.IsAny(), It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_search.json")); - - var parseResults = Mocker.Resolve().FetchEpisode("30 Rock", 1, 1); - - parseResults.Should().NotBeEmpty(); - parseResults.Should().OnlyContain(s => s.Indexer == "nzbx"); - parseResults.Should().OnlyContain(s => !String.IsNullOrEmpty(s.OriginalString)); - parseResults.Should().OnlyContain(s => s.Age >= 0); - } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs b/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs new file mode 100644 index 000000000..683e38c27 --- /dev/null +++ b/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs @@ -0,0 +1,119 @@ +using System; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Net; +using System.ServiceModel.Syndication; +using System.Threading; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Common; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Providers.Indexer; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Test.ProviderTests; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.IndexerTests +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class NzbxFixture : CoreTest + { + [Test] + public void should_get_size_when_parsing_recent_feed() + { + Mocker.GetMock() + .Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny())) + .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json")); + + //Act + var parseResults = Mocker.Resolve().FetchRss(); + + parseResults.Should().HaveCount(1); + parseResults[0].Size.Should().Be(890190951); + } + + [Test] + public void should_get_size_when_parsing_search_results() + { + Mocker.GetMock() + .Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny())) + .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json")); + + //Act + var parseResults = Mocker.Resolve().FetchEpisode("30 Rock", 1, 1); + + parseResults.Should().HaveCount(1); + parseResults[0].Size.Should().Be(418067671); + } + + [Test] + public void should_be_able_parse_results_from_recent_feed() + { + Mocker.GetMock() + .Setup(h => h.DownloadString(It.IsAny(), It.IsAny())) + .Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_recent.json")); + + var parseResults = Mocker.Resolve().FetchRss(); + + parseResults.Should().NotBeEmpty(); + parseResults.Should().OnlyContain(s => s.Indexer == "nzbx"); + parseResults.Should().OnlyContain(s => !String.IsNullOrEmpty(s.OriginalString)); + parseResults.Should().OnlyContain(s => s.Age >= 0); + } + + [Test] + public void should_be_able_to_parse_results_from_search_results() + { + Mocker.GetMock() + .Setup(h => h.DownloadString(It.IsAny(), It.IsAny())) + .Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_search.json")); + + var parseResults = Mocker.Resolve().FetchEpisode("30 Rock", 1, 1); + + parseResults.Should().NotBeEmpty(); + parseResults.Should().OnlyContain(s => s.Indexer == "nzbx"); + parseResults.Should().OnlyContain(s => !String.IsNullOrEmpty(s.OriginalString)); + parseResults.Should().OnlyContain(s => s.Age >= 0); + } + + [Test] + public void should_get_postedDate_when_parsing_recent_feed() + { + var expectedAge = DateTime.Today.Subtract(new DateTime(2012, 12, 21)).Days; + + Mocker.GetMock() + .Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny())) + .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json")); + + //Act + var parseResults = Mocker.Resolve().FetchRss(); + + parseResults.Should().HaveCount(1); + parseResults[0].Age.Should().Be(expectedAge); + } + + [Test] + public void should_get_postedDate_when_parsing_search_results() + { + var expectedAge = DateTime.Today.Subtract(new DateTime(2012, 2, 11)).Days; + + Mocker.GetMock() + .Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny())) + .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json")); + + //Act + var parseResults = Mocker.Resolve().FetchEpisode("30 Rock", 1, 1); + + parseResults.Should().HaveCount(1); + parseResults[0].Age.Should().Be(expectedAge); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index eab2fe1bc..0861a3045 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -139,6 +139,7 @@ + @@ -231,7 +232,7 @@ - +