1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00

More tests for nzbx

This commit is contained in:
Mark McDowall 2012-12-21 09:05:50 -08:00
parent 117edd4286
commit 7dd846b9e9
3 changed files with 138 additions and 84 deletions

View File

@ -20,12 +20,27 @@
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<ConfigProvider>().SetupGet(c => c.NzbsOrgHash).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsOrgUId).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsrusHash).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsrusUId).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.FileSharingTalkUid).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.FileSharingTalkSecret).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.OmgwtfnzbsUsername).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.OmgwtfnzbsApiKey).Returns("MockedConfigValue");
}
[TestCase("nzbsrus.xml")]
[TestCase("newznab.xml")]
[TestCase("wombles.xml")]
@ -59,21 +74,6 @@ public void parse_feed_xml(string fileName)
parseResults.Should().OnlyContain(s => s.Age >= 0);
}
private void WithConfiguredIndexers()
{
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsOrgHash).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsOrgUId).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsrusHash).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsrusUId).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.FileSharingTalkUid).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.FileSharingTalkSecret).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.OmgwtfnzbsUsername).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.OmgwtfnzbsApiKey).Returns("MockedConfigValue");
}
[Test]
public void custome_parser_partial_success()
{
@ -229,38 +229,6 @@ public void size_omgwtfnzbs()
parseResults[0].Size.Should().Be(236820890);
}
[Test]
public void size_nzbx_recent()
{
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json"));
//Act
var parseResults = Mocker.Resolve<Nzbx>().FetchRss();
parseResults.Should().HaveCount(1);
parseResults[0].Size.Should().Be(890190951);
}
[Test]
public void size_nzbx_search()
{
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json"));
//Act
var parseResults = Mocker.Resolve<Nzbx>().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 @@ public void should_get_nzbInfoUrl_for_omgwtfnzbs()
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<HttpProvider>()
.Setup(h => h.DownloadString(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_recent.json"));
var parseResults = Mocker.Resolve<Nzbx>().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<HttpProvider>()
.Setup(h => h.DownloadString(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_search.json"));
var parseResults = Mocker.Resolve<Nzbx>().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);
}
}
}

View File

@ -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<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json"));
//Act
var parseResults = Mocker.Resolve<Nzbx>().FetchRss();
parseResults.Should().HaveCount(1);
parseResults[0].Size.Should().Be(890190951);
}
[Test]
public void should_get_size_when_parsing_search_results()
{
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json"));
//Act
var parseResults = Mocker.Resolve<Nzbx>().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<HttpProvider>()
.Setup(h => h.DownloadString(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_recent.json"));
var parseResults = Mocker.Resolve<Nzbx>().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<HttpProvider>()
.Setup(h => h.DownloadString(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_search.json"));
var parseResults = Mocker.Resolve<Nzbx>().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<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json"));
//Act
var parseResults = Mocker.Resolve<Nzbx>().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<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json"));
//Act
var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1);
parseResults.Should().HaveCount(1);
parseResults[0].Age.Should().Be(expectedAge);
}
}
}

View File

@ -139,6 +139,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="IndexerTests\NzbxFixture.cs" />
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />
<Compile Include="ProviderTests\SearchProviderTests\GetSeriesTitleFixture.cs" />
<Compile Include="ProviderTests\TvRageMappingProviderTests\FindMatchingTvRageSeriesFixture.cs" />
@ -231,7 +232,7 @@
<Compile Include="EpisodeStatusTest.cs" />
<Compile Include="JobTests\ImportNewSeriesJobTest.cs" />
<Compile Include="JobTests\DiskScanJobTest.cs" />
<Compile Include="IndexerTests.cs" />
<Compile Include="IndexerTests\IndexerFixture.cs" />
<Compile Include="ProviderTests\DecisionEngineTests\AllowedDownloadSpecificationFixture.cs" />
<Compile Include="ProviderTests\JobProviderTests\JobProviderFixture.cs" />
<Compile Include="QualityTest.cs" />