2013-01-24 09:36:37 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Common;
|
2013-02-24 09:48:52 +03:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-03-05 08:33:34 +03:00
|
|
|
using NzbDrone.Core.Download.Clients;
|
|
|
|
using NzbDrone.Core.Download.Clients.Nzbget;
|
2013-03-28 22:05:43 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-01-24 09:36:37 +03:00
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTests
|
|
|
|
{
|
2013-03-28 22:05:43 +03:00
|
|
|
public class QueueFixture : CoreTest
|
2013-01-24 09:36:37 +03:00
|
|
|
{
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2013-02-24 22:39:31 +03:00
|
|
|
var fakeConfig = Mocker.GetMock<IConfigService>();
|
2013-01-24 09:36:37 +03: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.NzbgetBacklogTvPriority).Returns(PriorityType.Normal);
|
|
|
|
fakeConfig.SetupGet(c => c.NzbgetRecentTvPriority).Returns(PriorityType.High);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void WithFullQueue()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
2013-01-24 10:38:16 +03:00
|
|
|
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>()))
|
2013-03-28 22:05:43 +03:00
|
|
|
.Returns(ReadAllText("Files", "Nzbget", "Queue.txt"));
|
2013-01-24 09:36:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void WithEmptyQueue()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
2013-01-24 10:38:16 +03:00
|
|
|
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>()))
|
2013-03-28 22:05:43 +03:00
|
|
|
.Returns(ReadAllText("Files", "Nzbget", "Queue_empty.txt"));
|
2013-01-24 09:36:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void WithFailResponse()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<HttpProvider>()
|
2013-01-24 10:38:16 +03:00
|
|
|
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>()))
|
2013-03-28 22:05:43 +03:00
|
|
|
.Returns(ReadAllText("Files", "Nzbget", "JsonError.txt"));
|
2013-01-24 09:36:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_no_items_when_queue_is_empty()
|
|
|
|
{
|
|
|
|
WithEmptyQueue();
|
|
|
|
|
|
|
|
Mocker.Resolve<NzbgetProvider>()
|
|
|
|
.GetQueue()
|
|
|
|
.Should()
|
|
|
|
.BeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_item_when_queue_has_item()
|
|
|
|
{
|
|
|
|
WithFullQueue();
|
|
|
|
|
|
|
|
Mocker.Resolve<NzbgetProvider>()
|
|
|
|
.GetQueue()
|
|
|
|
.Should()
|
|
|
|
.HaveCount(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_throw_when_error_is_returned()
|
|
|
|
{
|
|
|
|
WithFailResponse();
|
|
|
|
|
|
|
|
Assert.Throws<ApplicationException>(() => Mocker.Resolve<NzbgetProvider>().GetQueue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|