1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-03-11 14:59:46 +02:00

75 lines
2.9 KiB
C#
Raw Normal View History

2013-03-31 23:22:16 -07:00
using System;
2013-07-07 20:24:27 -07:00
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
2013-02-23 22:48:52 -08:00
using NzbDrone.Core.Configuration;
2013-03-04 21:33:34 -08:00
using NzbDrone.Core.Download.Clients.Nzbget;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
2013-07-07 20:24:27 -07:00
using NzbDrone.Core.Tv;
2013-03-31 23:22:16 -07:00
namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetProviderTests
{
public class DownloadNzbFixture : CoreTest
{
private const string _url = "http://www.nzbdrone.com";
private const string _title = "30 Rock - S01E01 - Pilot [HDTV-720p]";
private RemoteEpisode _remoteEpisode;
[SetUp]
public void Setup()
{
2013-02-24 11:39:31 -08:00
var fakeConfig = Mocker.GetMock<IConfigService>();
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);
_remoteEpisode = new RemoteEpisode();
_remoteEpisode.Report = new ReportInfo();
_remoteEpisode.Report.Title = _title;
_remoteEpisode.Report.NzbUrl = _url;
2013-07-07 20:24:27 -07:00
_remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
2013-07-25 20:25:24 -07:00
.With(e => e.AirDate = DateTime.Today.ToString(Episode.AIR_DATE_FORMAT))
2013-07-07 20:24:27 -07:00
.Build()
.ToList();
}
private void WithFailResponse()
{
2013-04-10 16:41:45 -07:00
Mocker.GetMock<IHttpProvider>()
2013-01-23 23:38:16 -08:00
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>()))
.Returns(ReadAllText("Files", "Nzbget", "JsonError.txt"));
}
[Test]
public void should_add_item_to_queue()
{
2013-04-10 16:41:45 -07:00
Mocker.GetMock<IHttpProvider>()
2013-01-23 23:38:16 -08:00
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass",
2013-07-04 23:40:37 -07:00
It.Is<String>(c => c.Equals("{\"method\":\"appendurl\",\"params\":[\"30 Rock - S01E01 - Pilot [HDTV-720p]\",\"TV\",50,false,\"http://www.nzbdrone.com\"]}"))))
.Returns("{\"version\": \"1.1\",\"result\": true}");
Mocker.Resolve<NzbgetClient>()
.DownloadNzb(_remoteEpisode)
.Should()
.BeTrue();
}
[Test]
public void should_throw_when_error_is_returned()
{
WithFailResponse();
Assert.Throws<ApplicationException>(() => Mocker.Resolve<NzbgetClient>().DownloadNzb(_remoteEpisode));
}
}
}