mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
Xbmc Refactored
This commit is contained in:
parent
76fb548ccd
commit
b99e62c5ba
38 changed files with 1501 additions and 1521 deletions
75
NzbDrone.Core.Test/NotificationTests/GrowlProviderTest.cs
Normal file
75
NzbDrone.Core.Test/NotificationTests/GrowlProviderTest.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Notifications;
|
||||
using NzbDrone.Core.Notifications.Growl;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
{
|
||||
[Explicit]
|
||||
[TestFixture]
|
||||
public class GrowlProviderTest : CoreTest
|
||||
{
|
||||
[Test]
|
||||
public void Register_should_add_new_application_to_local_growl_instance()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
Mocker.Resolve<GrowlProvider>().Register("localhost", 23053, "");
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNotification_should_send_a_message_to_local_growl_instance()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
Mocker.Resolve<GrowlProvider>().TestNotification("localhost", 23053, "");
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnGrab_should_send_a_message_to_local_growl_instance()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
Mocker.Resolve<GrowlProvider>().SendNotification("Episode Grabbed", "Series Title - 1x05 - Episode Title", "GRAB", "localhost", 23053, "");
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnDownload_should_send_a_message_to_local_growl_instance()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
Mocker.Resolve<GrowlProvider>().SendNotification("Episode Downloaded", "Series Title - 1x05 - Episode Title", "DOWNLOAD", "localhost", 23053, "");
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ namespace NzbDrone.Core.Test.NotificationTests
|
|||
{
|
||||
_notifications = new List<INotification>();
|
||||
|
||||
_notifications.Add(new Xbmc(null, null));
|
||||
_notifications.Add(new Notifications.Xbmc.Xbmc(null, null));
|
||||
_notifications.Add(new PlexClient(null));
|
||||
_notifications.Add(new PlexServer(null));
|
||||
_notifications.Add(new Email(null));
|
||||
|
@ -49,8 +49,8 @@ namespace NzbDrone.Core.Test.NotificationTests
|
|||
{
|
||||
Mocker.SetConstant<INotificationRepository>(Mocker.Resolve<NotificationRepository>());
|
||||
|
||||
Mocker.GetMock<IContainer>().Setup(s => s.Resolve(typeof (Xbmc)))
|
||||
.Returns(new Xbmc(null, null));
|
||||
Mocker.GetMock<IContainer>().Setup(s => s.Resolve(typeof(Notifications.Xbmc.Xbmc)))
|
||||
.Returns(new Notifications.Xbmc.Xbmc(null, null));
|
||||
|
||||
Mocker.GetMock<IContainer>().Setup(s => s.Resolve(typeof(PlexClient)))
|
||||
.Returns(new PlexClient(null));
|
||||
|
|
153
NzbDrone.Core.Test/NotificationTests/PlexProviderTest.cs
Normal file
153
NzbDrone.Core.Test/NotificationTests/PlexProviderTest.cs
Normal file
|
@ -0,0 +1,153 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Notifications.Plex;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class PlexProviderTest : CoreTest
|
||||
{
|
||||
private PlexClientSettings _clientSettings;
|
||||
|
||||
public void WithClientCredentials()
|
||||
{
|
||||
_clientSettings.Username = "plex";
|
||||
_clientSettings.Password = "plex";
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_clientSettings = new PlexClientSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 3000
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSectionKeys_should_return_single_section_key_when_only_one_show_section()
|
||||
{
|
||||
var response = "<MediaContainer size=\"1\" mediaTagPrefix=\"/system/bundle/media/flags/\" mediaTagVersion=\"1329809559\" title1=\"Plex Library\" identifier=\"com.plexapp.plugins.library\"><Directory refreshing=\"0\" key=\"5\" type=\"show\" title=\"TV Shows\" art=\"/:/resources/show-fanart.jpg\" agent=\"com.plexapp.agents.thetvdb\" scanner=\"Plex Series Scanner\" language=\"en\" updatedAt=\"1329810350\"><Location path=\"C:/Test/TV\"/></Directory></MediaContainer>";
|
||||
Stream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(response));
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadStream("http://localhost:32400/library/sections", null))
|
||||
.Returns(stream);
|
||||
|
||||
|
||||
var result = Mocker.Resolve<PlexProvider>().GetSectionKeys("localhost:32400");
|
||||
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
result.First().Should().Be(5);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSectionKeys_should_return_single_section_key_when_only_one_show_section_with_other_sections()
|
||||
{
|
||||
|
||||
|
||||
var response = "<MediaContainer size=\"1\" mediaTagPrefix=\"/system/bundle/media/flags/\" mediaTagVersion=\"1329809559\" title1=\"Plex Library\" identifier=\"com.plexapp.plugins.library\"><Directory refreshing=\"0\" key=\"5\" type=\"show\" title=\"TV Shows\" art=\"/:/resources/show-fanart.jpg\" agent=\"com.plexapp.agents.thetvdb\" scanner=\"Plex Series Scanner\" language=\"en\" updatedAt=\"1329810350\"><Location path=\"C:/Test/TV\"/></Directory><Directory refreshing=\"0\" key=\"7\" type=\"movie\" title=\"TV Shows\" art=\"/:/resources/show-fanart.jpg\" agent=\"com.plexapp.agents.thetvdb\" scanner=\"Plex Series Scanner\" language=\"en\" updatedAt=\"1329810350\"><Location path=\"C:/Test/TV\"/></Directory></MediaContainer>";
|
||||
Stream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(response));
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadStream("http://localhost:32400/library/sections", null))
|
||||
.Returns(stream);
|
||||
|
||||
|
||||
var result = Mocker.Resolve<PlexProvider>().GetSectionKeys("localhost:32400");
|
||||
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
result.First().Should().Be(5);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSectionKeys_should_return_multiple_section_keys_when_there_are_multiple_show_sections()
|
||||
{
|
||||
|
||||
|
||||
var response = "<MediaContainer size=\"1\" mediaTagPrefix=\"/system/bundle/media/flags/\" mediaTagVersion=\"1329809559\" title1=\"Plex Library\" identifier=\"com.plexapp.plugins.library\"><Directory refreshing=\"0\" key=\"5\" type=\"show\" title=\"TV Shows\" art=\"/:/resources/show-fanart.jpg\" agent=\"com.plexapp.agents.thetvdb\" scanner=\"Plex Series Scanner\" language=\"en\" updatedAt=\"1329810350\"><Location path=\"C:/Test/TV\"/></Directory><Directory refreshing=\"0\" key=\"6\" type=\"show\" title=\"TV Shows\" art=\"/:/resources/show-fanart.jpg\" agent=\"com.plexapp.agents.thetvdb\" scanner=\"Plex Series Scanner\" language=\"en\" updatedAt=\"1329810350\"><Location path=\"C:/Test/TV\"/></Directory></MediaContainer>";
|
||||
Stream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(response));
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadStream("http://localhost:32400/library/sections", null))
|
||||
.Returns(stream);
|
||||
|
||||
|
||||
var result = Mocker.Resolve<PlexProvider>().GetSectionKeys("localhost:32400");
|
||||
|
||||
|
||||
result.Should().HaveCount(2);
|
||||
result.First().Should().Be(5);
|
||||
result.Last().Should().Be(6);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateSection_should_update_section()
|
||||
{
|
||||
|
||||
|
||||
var response = "";
|
||||
Stream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(response));
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadString("http://localhost:32400/library/sections/5/refresh"))
|
||||
.Returns(response);
|
||||
|
||||
|
||||
Mocker.Resolve<PlexProvider>().UpdateSection("localhost:32400", 5);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Notify_should_send_notification()
|
||||
{
|
||||
|
||||
const string header = "Test Header";
|
||||
const string message = "Test Message";
|
||||
|
||||
var expectedUrl = String.Format("http://localhost:3000/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification({0}, {1}))", header, message);
|
||||
|
||||
var fakeHttp = Mocker.GetMock<IHttpProvider>();
|
||||
fakeHttp.Setup(s => s.DownloadString(expectedUrl))
|
||||
.Returns("ok");
|
||||
|
||||
|
||||
Mocker.Resolve<PlexProvider>().Notify(_clientSettings, header, message);
|
||||
|
||||
|
||||
fakeHttp.Verify(v => v.DownloadString(expectedUrl), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Notify_should_send_notification_with_credentials_when_configured()
|
||||
{
|
||||
WithClientCredentials();
|
||||
|
||||
const string header = "Test Header";
|
||||
const string message = "Test Message";
|
||||
|
||||
var expectedUrl = String.Format("http://localhost:3000/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification({0}, {1}))", header, message);
|
||||
|
||||
var fakeHttp = Mocker.GetMock<IHttpProvider>();
|
||||
fakeHttp.Setup(s => s.DownloadString(expectedUrl, "plex", "plex"))
|
||||
.Returns("ok");
|
||||
|
||||
|
||||
Mocker.Resolve<PlexProvider>().Notify(_clientSettings, header, message);
|
||||
|
||||
|
||||
fakeHttp.Verify(v => v.DownloadString(expectedUrl, "plex", "plex"), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
148
NzbDrone.Core.Test/NotificationTests/ProwlProviderTest.cs
Normal file
148
NzbDrone.Core.Test/NotificationTests/ProwlProviderTest.cs
Normal file
|
@ -0,0 +1,148 @@
|
|||
using System;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Notifications.Prowl;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
using Prowlin;
|
||||
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
{
|
||||
[Explicit]
|
||||
[TestFixture]
|
||||
public class ProwlProviderTest : CoreTest
|
||||
{
|
||||
private const string _apiKey = "c3bdc0f48168f72d546cc6872925b160f5cbffc1";
|
||||
private const string _apiKey2 = "46a710a46b111b0b8633819b0d8a1e0272a3affa";
|
||||
|
||||
private const string _badApiKey = "1234567890abcdefghijklmnopqrstuvwxyz1234";
|
||||
|
||||
[Test]
|
||||
public void Verify_should_return_true_for_a_valid_apiKey()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ProwlProvider>().Verify(_apiKey);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Verify_should_return_false_for_an_invalid_apiKey()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ProwlProvider>().Verify(_badApiKey);
|
||||
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendNotification_should_return_true_for_a_valid_apiKey()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendNotification_should_return_false_for_an_invalid_apiKey()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _badApiKey);
|
||||
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendNotification_should_alert_with_high_priority()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (High)", _apiKey, NotificationPriority.High);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendNotification_should_alert_with_VeryLow_priority()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (VeryLow)", _apiKey, NotificationPriority.VeryLow);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendNotification_should_have_a_call_back_url()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey, NotificationPriority.Normal, "http://www.nzbdrone.com");
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendNotification_should_return_true_for_two_valid_apiKey()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _apiKey2);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendNotification_should_return_true_for_valid_apiKey_with_bad_apiKey()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _badApiKey);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model.Xbmc;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc
|
||||
{
|
||||
[TestFixture]
|
||||
public class GetJsonVersionFixture : CoreTest<XbmcService>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
}
|
||||
|
||||
[TestCase(3)]
|
||||
[TestCase(2)]
|
||||
[TestCase(0)]
|
||||
public void should_get_version_from_major_only(int number)
|
||||
{
|
||||
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":" + number + "}}";
|
||||
|
||||
var fakeHttp = Mocker.GetMock<IHttpProvider>();
|
||||
fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>()))
|
||||
.Returns(message);
|
||||
|
||||
Subject.GetJsonVersion(_settings).Should().Be(new XbmcVersion(number));
|
||||
}
|
||||
|
||||
[TestCase(5, 0, 0)]
|
||||
[TestCase(6, 0, 0)]
|
||||
[TestCase(6, 1, 0)]
|
||||
[TestCase(6, 0, 23)]
|
||||
[TestCase(0, 0, 0)]
|
||||
public void should_get_version_from_semantic_version(int major, int minor, int patch)
|
||||
{
|
||||
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":{\"major\":" + major + ",\"minor\":" + minor + ",\"patch\":" + patch + "}}}";
|
||||
|
||||
var fakeHttp = Mocker.GetMock<IHttpProvider>();
|
||||
fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>()))
|
||||
.Returns(message);
|
||||
|
||||
Subject.GetJsonVersion(_settings).Should().Be(new XbmcVersion(major, minor, patch));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_version_zero_when_an_error_is_received()
|
||||
{
|
||||
var message = "{\"error\":{\"code\":-32601,\"message\":\"Method not found.\"},\"id\":10,\"jsonrpc\":\"2.0\"}";
|
||||
|
||||
var fakeHttp = Mocker.GetMock<IHttpProvider>();
|
||||
fakeHttp.Setup(s => s.PostCommand("localhost:8080", "xbmc", "xbmc", It.IsAny<string>()))
|
||||
.Returns(message);
|
||||
|
||||
Subject.GetJsonVersion(_settings).Should().Be(new XbmcVersion(0));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
||||
{
|
||||
[TestFixture]
|
||||
public class ActivePlayersFixture : CoreTest<HttpApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
private string _expectedUrl;
|
||||
|
||||
private void WithNoActivePlayers()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(_expectedUrl, _settings.Username, _settings.Password))
|
||||
.Returns("<html><li>Filename:[Nothing Playing]</html>");
|
||||
}
|
||||
|
||||
private void WithVideoPlayerActive()
|
||||
{
|
||||
var activePlayers = @"<html><li>Filename:C:\Test\TV\2 Broke Girls\Season 01\2 Broke Girls - S01E01 - Pilot [SDTV].avi" +
|
||||
"<li>PlayStatus:Playing<li>VideoNo:0<li>Type:Video<li>Thumb:special://masterprofile/Thumbnails/Video/a/auto-a664d5a2.tbn" +
|
||||
"<li>Time:00:06<li>Duration:21:35<li>Percentage:0<li>File size:183182590<li>Changed:True</html>";
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(_expectedUrl, _settings.Username, _settings.Password))
|
||||
.Returns(activePlayers);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
|
||||
_expectedUrl = String.Format("http://{0}/xbmcCmds/xbmcHttp?command={1}", _settings.Address, "getcurrentlyplaying");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void _should_be_empty_when_no_active_players()
|
||||
{
|
||||
WithNoActivePlayers();
|
||||
|
||||
Subject.GetActivePlayers(_settings).Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_active_video_player()
|
||||
{
|
||||
WithVideoPlayerActive();
|
||||
|
||||
var result = Subject.GetActivePlayers(_settings);
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
result.First().Type.Should().Be("video");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
||||
{
|
||||
[TestFixture]
|
||||
public class CheckForErrorFixture : CoreTest<HttpApiProvider>
|
||||
{
|
||||
[Test]
|
||||
public void should_be_true_when_the_response_contains_an_error()
|
||||
{
|
||||
const string response = "html><li>Error:Unknown command</html>";
|
||||
|
||||
Subject.CheckForError(response).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonError_true_empty_response()
|
||||
{
|
||||
var response = String.Empty;
|
||||
|
||||
Subject.CheckForError(response).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonError_false()
|
||||
{
|
||||
const string response = "html><li>Filename:[Nothing Playing]</html>";
|
||||
|
||||
Subject.CheckForError(response).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
||||
{
|
||||
[TestFixture]
|
||||
public class GetSeriesPathFixture : CoreTest<HttpApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
private Series _series;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
|
||||
_series = new Series
|
||||
{
|
||||
TvdbId = 79488,
|
||||
Title = "30 Rock"
|
||||
};
|
||||
|
||||
const string setResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)";
|
||||
const string resetResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat()";
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(setResponseUrl, _settings.Username, _settings.Password))
|
||||
.Returns("<xml><tag>OK</xml>");
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(resetResponseUrl, _settings.Username, _settings.Password))
|
||||
.Returns(@"<html>
|
||||
<li>OK
|
||||
</html>");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_series_path()
|
||||
{
|
||||
const string queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/</field></record></xml>";
|
||||
var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(query, _settings.Username, _settings.Password))
|
||||
.Returns(queryResult);
|
||||
|
||||
Subject.GetSeriesPath(_settings, _series)
|
||||
.Should().Be("smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_null_for_series_path()
|
||||
{
|
||||
const string queryResult = @"<xml></xml>";
|
||||
var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(query, _settings.Username, _settings.Password))
|
||||
.Returns(queryResult);
|
||||
|
||||
|
||||
Subject.GetSeriesPath(_settings, _series)
|
||||
.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_series_path_with_special_characters_in_it()
|
||||
{
|
||||
const string queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/</field></record></xml>";
|
||||
var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(query, _settings.Username, _settings.Password))
|
||||
.Returns(queryResult);
|
||||
|
||||
|
||||
Subject.GetSeriesPath(_settings, _series)
|
||||
.Should().Be("smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpdateFixture : CoreTest<HttpApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
private string _seriesQueryUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)";
|
||||
private Series _fakeSeries;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
|
||||
_fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.TvdbId = 79488)
|
||||
.With(s => s.Title = "30 Rock")
|
||||
.Build();
|
||||
}
|
||||
|
||||
private void WithSeriesPath()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(_seriesQueryUrl, _settings.Username, _settings.Password))
|
||||
.Returns("<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/</field></record></xml>");
|
||||
}
|
||||
|
||||
private void WithoutSeriesPath()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(_seriesQueryUrl, _settings.Username, _settings.Password))
|
||||
.Returns("<xml></xml>");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_using_series_path()
|
||||
{
|
||||
WithSeriesPath();
|
||||
const string url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video,smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/))";
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadString(url, _settings.Username, _settings.Password));
|
||||
|
||||
Subject.Update(_settings, _fakeSeries);
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_all_paths_when_series_path_not_found()
|
||||
{
|
||||
WithoutSeriesPath();
|
||||
const string url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))";
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadString(url, _settings.Username, _settings.Password));
|
||||
|
||||
Subject.Update(_settings, _fakeSeries);
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc
|
||||
{
|
||||
[TestFixture]
|
||||
public class HttpApiProviderFixture : CoreTest<HttpApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
||||
{
|
||||
[TestFixture]
|
||||
public class ActivePlayersFixture : CoreTest<JsonApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
|
||||
private void WithNoActivePlayers()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.IsAny<string>()))
|
||||
.Returns("{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[]}");
|
||||
}
|
||||
|
||||
private void WithVideoPlayerActive()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.IsAny<string>()))
|
||||
.Returns("{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[{\"playerid\":1,\"type\":\"video\"}]}");
|
||||
}
|
||||
|
||||
private void WithAudioPlayerActive()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.IsAny<string>()))
|
||||
.Returns("{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[{\"playerid\":1,\"type\":\"audio\"}]}");
|
||||
}
|
||||
|
||||
private void WithPicturePlayerActive()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.IsAny<string>()))
|
||||
.Returns("{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[{\"playerid\":1,\"type\":\"picture\"}]}");
|
||||
}
|
||||
|
||||
private void WithAllPlayersActive()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.IsAny<string>()))
|
||||
.Returns("{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[{\"playerid\":1,\"type\":\"audio\"},{\"playerid\":2,\"type\":\"picture\"},{\"playerid\":3,\"type\":\"video\"}]}");
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void _should_be_empty_when_no_active_players()
|
||||
{
|
||||
WithNoActivePlayers();
|
||||
|
||||
Subject.GetActivePlayers(_settings).Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_active_video_player()
|
||||
{
|
||||
WithVideoPlayerActive();
|
||||
|
||||
var result = Subject.GetActivePlayers(_settings);
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
result.First().Type.Should().Be("video");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_active_audio_player()
|
||||
{
|
||||
WithAudioPlayerActive();
|
||||
|
||||
var result = Subject.GetActivePlayers(_settings);
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
result.First().Type.Should().Be("audio");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_active_picture_player()
|
||||
{
|
||||
WithPicturePlayerActive();
|
||||
|
||||
var result = Subject.GetActivePlayers(_settings);
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
result.First().Type.Should().Be("picture");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_all_players_active()
|
||||
{
|
||||
WithAllPlayersActive();
|
||||
|
||||
var result = Subject.GetActivePlayers(_settings);
|
||||
|
||||
result.Should().HaveCount(3);
|
||||
result.Select(a => a.PlayerId).Distinct().Should().HaveCount(3);
|
||||
result.Select(a => a.Type).Distinct().Should().HaveCount(3);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
||||
{
|
||||
[TestFixture]
|
||||
public class CheckForErrorFixture : CoreTest<JsonApiProvider>
|
||||
{
|
||||
[Test]
|
||||
public void should_be_true_when_the_response_contains_an_error()
|
||||
{
|
||||
const string response = "{\"error\":{\"code\":-32601,\"message\":\"Method not found.\"},\"id\":10,\"jsonrpc\":\"2.0\"}";
|
||||
|
||||
Subject.CheckForError(response).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonError_true_empty_response()
|
||||
{
|
||||
var response = String.Empty;
|
||||
|
||||
Subject.CheckForError(response).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonError_false()
|
||||
{
|
||||
const string response = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":3}}";
|
||||
|
||||
Subject.CheckForError(response).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
||||
{
|
||||
[TestFixture]
|
||||
public class GetSeriesPathFixture : CoreTest<JsonApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
private Series _series;
|
||||
private string _response;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
|
||||
_response = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"limits\":" +
|
||||
"{\"end\":5,\"start\":0,\"total\":5},\"tvshows\":[{\"file\"" +
|
||||
":\"smb://HOMESERVER/TV/7th Heaven/\",\"imdbnumber\":\"73928\"," +
|
||||
"\"label\":\"7th Heaven\",\"tvshowid\":3},{\"file\":\"smb://HOMESERVER/TV/8 Simple Rules/\"" +
|
||||
",\"imdbnumber\":\"78461\",\"label\":\"8 Simple Rules\",\"tvshowid\":4},{\"file\":" +
|
||||
"\"smb://HOMESERVER/TV/24-7 Penguins-Capitals- Road to the NHL Winter Classic/\",\"imdbnumber\"" +
|
||||
":\"213041\",\"label\":\"24/7 Penguins/Capitals: Road to the NHL Winter Classic\",\"tvshowid\":1}," +
|
||||
"{\"file\":\"smb://HOMESERVER/TV/30 Rock/\",\"imdbnumber\":\"79488\",\"label\":\"30 Rock\",\"tvshowid\":2}" +
|
||||
",{\"file\":\"smb://HOMESERVER/TV/90210/\",\"imdbnumber\":\"82716\",\"label\":\"90210\",\"tvshowid\":5}]}}";
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(
|
||||
s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.IsAny<string>()))
|
||||
.Returns(_response);
|
||||
}
|
||||
|
||||
private void WithMatchingTvdbId()
|
||||
{
|
||||
_series = new Series
|
||||
{
|
||||
TvdbId = 78461,
|
||||
Title = "TV Show"
|
||||
};
|
||||
}
|
||||
|
||||
private void WithMatchingTitle()
|
||||
{
|
||||
_series = new Series
|
||||
{
|
||||
TvdbId = 1,
|
||||
Title = "30 Rock"
|
||||
};
|
||||
}
|
||||
|
||||
private void WithoutMatchingSeries()
|
||||
{
|
||||
_series = new Series
|
||||
{
|
||||
TvdbId = 1,
|
||||
Title = "Does not exist"
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_null_when_series_is_not_found()
|
||||
{
|
||||
WithoutMatchingSeries();
|
||||
|
||||
Subject.GetSeriesPath(_settings, _series).Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_path_when_tvdbId_matches()
|
||||
{
|
||||
WithMatchingTvdbId();
|
||||
|
||||
Subject.GetSeriesPath(_settings, _series).Should().Be("smb://HOMESERVER/TV/8 Simple Rules/");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_path_when_title_matches()
|
||||
{
|
||||
WithMatchingTitle();
|
||||
|
||||
Subject.GetSeriesPath(_settings, _series).Should().Be("smb://HOMESERVER/TV/30 Rock/");
|
||||
}
|
||||
}
|
||||
}
|
104
NzbDrone.Core.Test/NotificationTests/Xbmc/Json/UpdateFixture.cs
Normal file
104
NzbDrone.Core.Test/NotificationTests/Xbmc/Json/UpdateFixture.cs
Normal file
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpdateFixture : CoreTest<JsonApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
const string _expectedJson = "{\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.GetTvShows\",\"params\":{\"properties\":[\"file\",\"imdbnumber\"]},\"id\":10}";
|
||||
|
||||
private const string _tvshowsResponse = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"limits\":" +
|
||||
"{\"end\":5,\"start\":0,\"total\":5},\"tvshows\":[{\"file\"" +
|
||||
":\"smb://HOMESERVER/TV/7th Heaven/\",\"imdbnumber\":\"73928\"," +
|
||||
"\"label\":\"7th Heaven\",\"tvshowid\":3},{\"file\":\"smb://HOMESERVER/TV/8 Simple Rules/\"" +
|
||||
",\"imdbnumber\":\"78461\",\"label\":\"8 Simple Rules\",\"tvshowid\":4},{\"file\":" +
|
||||
"\"smb://HOMESERVER/TV/24-7 Penguins-Capitals- Road to the NHL Winter Classic/\",\"imdbnumber\"" +
|
||||
":\"213041\",\"label\":\"24/7 Penguins/Capitals: Road to the NHL Winter Classic\",\"tvshowid\":1}," +
|
||||
"{\"file\":\"smb://HOMESERVER/TV/30 Rock/\",\"imdbnumber\":\"79488\",\"label\":\"30 Rock\",\"tvshowid\":2}" +
|
||||
",{\"file\":\"smb://HOMESERVER/TV/90210/\",\"imdbnumber\":\"82716\",\"label\":\"90210\",\"tvshowid\":5}]}}";
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password,
|
||||
It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == _expectedJson.Replace(" ", ""))))
|
||||
.Returns(_tvshowsResponse);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_using_series_path()
|
||||
{
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.TvdbId = 79488)
|
||||
.With(s => s.Title = "30 Rock")
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.Is<String>(
|
||||
e => e.Replace(" ", "")
|
||||
.Replace("\r\n", "")
|
||||
.Replace("\t", "")
|
||||
.Contains("\"params\":{\"directory\":\"smb://HOMESERVER/TV/30Rock/\"}"))))
|
||||
.Returns("{\"id\":55,\"jsonrpc\":\"2.0\",\"result\":\"OK\"}");
|
||||
|
||||
Subject.Update(_settings, fakeSeries);
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Verify(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.Is<String>(
|
||||
e => e.Replace(" ", "")
|
||||
.Replace("\r\n", "")
|
||||
.Replace("\t", "")
|
||||
.Contains("\"params\":{\"directory\":\"smb://HOMESERVER/TV/30Rock/\"}"))), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_all_paths_when_series_path_not_found()
|
||||
{
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.TvdbId = 1)
|
||||
.With(s => s.Title = "Not 30 Rock")
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.Is<String>(
|
||||
e => !e.Replace(" ", "")
|
||||
.Replace("\r\n", "")
|
||||
.Replace("\t", "")
|
||||
.Contains("\"params\":{\"directory\":\"smb://HOMESERVER/TV/30Rock/\"}"))))
|
||||
.Returns("{\"id\":55,\"jsonrpc\":\"2.0\",\"result\":\"OK\"}");
|
||||
|
||||
Subject.Update(_settings, fakeSeries);
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Verify(s => s.PostCommand(_settings.Address, _settings.Username, _settings.Password, It.Is<String>(
|
||||
e => e.Replace(" ", "")
|
||||
.Replace("\r\n", "")
|
||||
.Replace("\t", "")
|
||||
.Contains("\"params\":{\"directory\":\"smb://HOMESERVER/TV/30Rock/\"}"))), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc
|
||||
{
|
||||
[TestFixture]
|
||||
public class JsonApiProviderFixture : CoreTest<JsonApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model.Xbmc;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc
|
||||
{
|
||||
[TestFixture]
|
||||
public class XbmcProviderTest : CoreTest
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new XbmcSettings
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 8080,
|
||||
Username = "xbmc",
|
||||
Password = "xbmc",
|
||||
AlwaysUpdate = false,
|
||||
CleanLibrary = false,
|
||||
UpdateLibrary = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue