2012-12-21 17:05:50 +00:00
|
|
|
|
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;
|
2013-02-23 04:37:23 +00:00
|
|
|
|
using NzbDrone.Core.Indexers;
|
2012-12-21 17:05:50 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
2013-03-07 01:51:47 +00:00
|
|
|
|
|
2012-12-21 17:05:50 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Core.Test.ProviderTests;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.IndexerTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 05:44:06 +00:00
|
|
|
|
public class NzbxFixture : CoreTest
|
2012-12-21 17:05:50 +00:00
|
|
|
|
{
|
|
|
|
|
[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>()))
|
2013-03-28 19:05:43 +00:00
|
|
|
|
.Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json"));
|
2012-12-21 17:05:50 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var parseResults = Mocker.Resolve<Nzbx>().FetchRss();
|
|
|
|
|
|
|
|
|
|
parseResults.Should().HaveCount(1);
|
|
|
|
|
parseResults[0].Size.Should().Be(890190951);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-28 19:05:43 +00:00
|
|
|
|
[Test]
|
2012-12-21 17:05:50 +00:00
|
|
|
|
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>()))
|
2013-03-28 19:05:43 +00:00
|
|
|
|
.Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_search.json"));
|
2012-12-21 17:05:50 +00:00
|
|
|
|
|
|
|
|
|
//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>()))
|
2013-03-28 19:05:43 +00:00
|
|
|
|
.Returns(ReadAllText("Files", "Rss", "nzbx_recent.json"));
|
2012-12-21 17:05:50 +00:00
|
|
|
|
|
|
|
|
|
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()
|
2013-03-28 19:05:43 +00:00
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(h => h.DownloadString(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
|
|
|
|
|
.Returns(ReadAllText("Files", "Rss", "nzbx_search.json"));
|
2012-12-21 17:05:50 +00:00
|
|
|
|
|
2013-03-28 19:05:43 +00:00
|
|
|
|
var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1);
|
2012-12-21 17:05:50 +00:00
|
|
|
|
|
2013-03-28 19:05:43 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2012-12-21 17:05:50 +00:00
|
|
|
|
|
|
|
|
|
[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>()))
|
2013-03-28 19:05:43 +00:00
|
|
|
|
.Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json"));
|
2012-12-21 17:05:50 +00:00
|
|
|
|
|
|
|
|
|
//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>()))
|
2013-03-28 19:05:43 +00:00
|
|
|
|
.Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_search.json"));
|
2012-12-21 17:05:50 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1);
|
|
|
|
|
|
|
|
|
|
parseResults.Should().HaveCount(1);
|
|
|
|
|
parseResults[0].Age.Should().Be(expectedAge);
|
|
|
|
|
}
|
2013-01-17 06:47:57 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_name_nzb_properly()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
|
|
|
|
.Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>()))
|
2013-03-28 19:05:43 +00:00
|
|
|
|
.Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json"));
|
2013-01-17 06:47:57 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var parseResults = Mocker.Resolve<Nzbx>().FetchRss();
|
|
|
|
|
|
|
|
|
|
parseResults.Should().HaveCount(1);
|
|
|
|
|
parseResults[0].NzbUrl.Should().EndWith(parseResults[0].OriginalString);
|
|
|
|
|
}
|
2012-12-21 17:05:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|