sonarr-repo-only/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs

131 lines
4.9 KiB
C#
Raw Normal View History

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]
2013-03-28 22:07:09 +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>()))
.Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json"));
2012-12-21 17:05:50 +00:00
2013-03-28 22:07:09 +00:00
2012-12-21 17:05:50 +00:00
var parseResults = Mocker.Resolve<Nzbx>().FetchRss();
parseResults.Should().HaveCount(1);
parseResults[0].Size.Should().Be(890190951);
}
[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>()))
.Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_search.json"));
2012-12-21 17:05:50 +00:00
2013-03-28 22:07:09 +00:00
2012-12-21 17:05:50 +00:00
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(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()
{
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
var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1);
2012-12-21 17:05:50 +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>()))
.Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json"));
2012-12-21 17:05:50 +00:00
2013-03-28 22:07:09 +00:00
2012-12-21 17:05:50 +00:00
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(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_search.json"));
2012-12-21 17:05:50 +00:00
2013-03-28 22:07:09 +00:00
2012-12-21 17:05:50 +00:00
var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1);
parseResults.Should().HaveCount(1);
parseResults[0].Age.Should().Be(expectedAge);
}
[Test]
public void should_name_nzb_properly()
{
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>()))
.Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json"));
2013-03-28 22:07:09 +00:00
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
}
}