2013-04-01 06:22:16 +00:00
|
|
|
using System;
|
2013-07-08 03:24:27 +00:00
|
|
|
using System.Linq;
|
|
|
|
using FizzWare.NBuilder;
|
2013-01-24 06:36:37 +00:00
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Common;
|
2013-09-19 00:24:50 +00:00
|
|
|
using NzbDrone.Common.Serializer;
|
2013-02-24 06:48:52 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-03-05 05:33:34 +00:00
|
|
|
using NzbDrone.Core.Download.Clients.Nzbget;
|
2013-07-08 03:15:15 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-03-28 19:05:43 +00:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-07-08 03:24:27 +00:00
|
|
|
using NzbDrone.Core.Tv;
|
2013-01-24 06:36:37 +00:00
|
|
|
|
2013-04-01 06:22:16 +00:00
|
|
|
namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetProviderTests
|
2013-01-24 06:36:37 +00:00
|
|
|
{
|
2013-03-28 19:05:43 +00:00
|
|
|
public class DownloadNzbFixture : CoreTest
|
2013-01-24 06:36:37 +00:00
|
|
|
{
|
2013-07-08 03:15:15 +00:00
|
|
|
private const string _url = "http://www.nzbdrone.com";
|
2013-08-25 19:41:40 +00:00
|
|
|
private const string _title = "30.Rock.S01E01.Pilot.720p.hdtv";
|
2013-07-08 03:15:15 +00:00
|
|
|
private RemoteEpisode _remoteEpisode;
|
|
|
|
|
2013-01-24 06:36:37 +00:00
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2013-02-24 19:39:31 +00:00
|
|
|
var fakeConfig = Mocker.GetMock<IConfigService>();
|
2013-01-24 06:36:37 +00:00
|
|
|
fakeConfig.SetupGet(c => c.NzbgetHost).Returns("192.168.5.55");
|
|
|
|
fakeConfig.SetupGet(c => c.NzbgetPort).Returns(6789);
|
|
|
|
fakeConfig.SetupGet(c => c.NzbgetUsername).Returns("nzbget");
|
|
|
|
fakeConfig.SetupGet(c => c.NzbgetPassword).Returns("pass");
|
|
|
|
fakeConfig.SetupGet(c => c.NzbgetTvCategory).Returns("TV");
|
|
|
|
fakeConfig.SetupGet(c => c.NzbgetRecentTvPriority).Returns(PriorityType.High);
|
|
|
|
|
2013-07-08 03:15:15 +00:00
|
|
|
_remoteEpisode = new RemoteEpisode();
|
2013-09-13 23:17:58 +00:00
|
|
|
_remoteEpisode.Release = new ReleaseInfo();
|
|
|
|
_remoteEpisode.Release.Title = _title;
|
|
|
|
_remoteEpisode.Release.DownloadUrl = _url;
|
2013-07-08 03:24:27 +00:00
|
|
|
|
|
|
|
_remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
|
|
|
.All()
|
2013-07-26 03:25:24 +00:00
|
|
|
.With(e => e.AirDate = DateTime.Today.ToString(Episode.AIR_DATE_FORMAT))
|
2013-07-08 03:24:27 +00:00
|
|
|
.Build()
|
|
|
|
.ToList();
|
2013-07-08 03:15:15 +00:00
|
|
|
}
|
2013-03-28 19:05:43 +00:00
|
|
|
|
2013-01-24 06:36:37 +00:00
|
|
|
private void WithFailResponse()
|
|
|
|
{
|
2013-04-10 23:41:45 +00:00
|
|
|
Mocker.GetMock<IHttpProvider>()
|
2013-01-24 07:38:16 +00:00
|
|
|
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>()))
|
2013-03-28 19:05:43 +00:00
|
|
|
.Returns(ReadAllText("Files", "Nzbget", "JsonError.txt"));
|
2013-01-24 06:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_add_item_to_queue()
|
|
|
|
{
|
2013-09-19 00:24:50 +00:00
|
|
|
|
|
|
|
var command = new JsonRequest
|
|
|
|
{
|
|
|
|
Method = "appendurl",
|
|
|
|
Params = new object[] { "30.Rock.S01E01.Pilot.720p.hdtv.nzb", "TV", 50, false, "http://www.nzbdrone.com" }
|
|
|
|
};
|
|
|
|
|
2013-04-10 23:41:45 +00:00
|
|
|
Mocker.GetMock<IHttpProvider>()
|
2013-01-24 07:38:16 +00:00
|
|
|
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass",
|
2013-09-19 00:24:50 +00:00
|
|
|
It.Is<String>(c => c.Equals(command.ToJson()))))
|
2013-01-24 06:36:37 +00:00
|
|
|
.Returns("{\"version\": \"1.1\",\"result\": true}");
|
|
|
|
|
2013-08-17 23:27:18 +00:00
|
|
|
Mocker.Resolve<NzbgetClient>().DownloadNzb(_remoteEpisode);
|
2013-01-24 06:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_throw_when_error_is_returned()
|
|
|
|
{
|
|
|
|
WithFailResponse();
|
|
|
|
|
2013-07-08 03:15:15 +00:00
|
|
|
Assert.Throws<ApplicationException>(() => Mocker.Resolve<NzbgetClient>().DownloadNzb(_remoteEpisode));
|
2013-01-24 06:36:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|