2013-03-28 23:07:09 +01:00
2011-07-09 20:19:33 +02:00
using System ;
2011-12-31 21:57:02 +01:00
using System.Linq ;
2011-07-09 20:19:33 +02:00
using FizzWare.NBuilder ;
using FluentAssertions ;
using Moq ;
using NUnit.Framework ;
2012-02-11 01:48:20 +01:00
using NzbDrone.Common ;
2013-02-24 07:48:52 +01:00
using NzbDrone.Core.Configuration ;
2013-02-19 07:01:03 +01:00
using NzbDrone.Core.Tv ;
2011-07-09 20:19:33 +02:00
using NzbDrone.Core.Model.Xbmc ;
using NzbDrone.Core.Providers ;
using NzbDrone.Core.Providers.Xbmc ;
2013-03-07 02:51:47 +01:00
2011-07-09 20:19:33 +02:00
using NzbDrone.Core.Test.Framework ;
2011-11-14 01:22:18 +01:00
using NzbDrone.Test.Common.AutoMoq ;
2011-07-09 20:19:33 +02:00
2011-10-21 01:42:17 +02:00
namespace NzbDrone.Core.Test.ProviderTests
2011-07-09 20:19:33 +02:00
{
[TestFixture]
2013-03-28 23:07:09 +01:00
2013-02-17 06:44:06 +01:00
public class XbmcProviderTest : CoreTest
2011-07-09 20:19:33 +02:00
{
2011-12-31 21:57:02 +01:00
private string EdenActivePlayers ;
private void WithNoActivePlayers ( )
{
EdenActivePlayers = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[]}" ;
}
private void WithVideoPlayerActive ( )
{
EdenActivePlayers = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[{\"playerid\":1,\"type\":\"video\"}]}" ;
}
private void WithAudioPlayerActive ( )
{
EdenActivePlayers = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[{\"playerid\":1,\"type\":\"audio\"}]}" ;
}
private void WithPicturePlayerActive ( )
{
EdenActivePlayers = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[{\"playerid\":1,\"type\":\"picture\"}]}" ;
}
private void WithAllPlayersActive ( )
{
EdenActivePlayers = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":[{\"playerid\":1,\"type\":\"audio\"},{\"playerid\":2,\"type\":\"picture\"},{\"playerid\":3,\"type\":\"video\"}]}" ;
}
2011-07-09 20:19:33 +02:00
[Test]
2011-09-27 19:41:36 +02:00
public void JsonError_true ( )
2011-07-09 20:19:33 +02:00
{
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
2011-07-09 20:19:33 +02:00
var response = "{\"error\":{\"code\":-32601,\"message\":\"Method not found.\"},\"id\":10,\"jsonrpc\":\"2.0\"}" ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . CheckForJsonError ( response ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-07-09 20:19:33 +02:00
Assert . AreEqual ( true , result ) ;
}
[Test]
2011-09-27 19:41:36 +02:00
public void JsonError_true_empty_response ( )
{
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
2011-09-27 19:41:36 +02:00
var response = String . Empty ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . CheckForJsonError ( response ) ;
2011-09-27 19:41:36 +02:00
2013-03-28 23:07:09 +01:00
2011-09-27 19:41:36 +02:00
Assert . AreEqual ( true , result ) ;
}
[Test]
public void JsonError_false ( )
2011-07-09 20:19:33 +02:00
{
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
2011-07-09 20:19:33 +02:00
var reposnse = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":3}}" ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . CheckForJsonError ( reposnse ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-07-09 20:19:33 +02:00
Assert . AreEqual ( false , result ) ;
}
[TestCase(3)]
[TestCase(2)]
[TestCase(0)]
2012-12-13 22:52:54 +01:00
public void GetJsonVersionIntOnly ( int number )
2011-07-09 20:19:33 +02:00
{
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":" + number + "}}" ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( message ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetJsonVersion ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2012-12-13 22:52:54 +01:00
result . 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 GetJsonVersionFrodo ( int major , int minor , int patch )
{
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":{\"major\":" + major + ",\"minor\":" + minor + ",\"patch\":" + patch + "}}}" ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2012-12-13 22:52:54 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( message ) ;
2013-03-28 23:07:09 +01:00
2012-12-13 22:52:54 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetJsonVersion ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2013-03-28 23:07:09 +01:00
2012-12-13 22:52:54 +01:00
result . Should ( ) . Be ( new XbmcVersion ( major , minor , patch ) ) ;
2011-07-09 20:19:33 +02:00
}
[Test]
public void GetJsonVersion_error ( )
{
var message = "{\"error\":{\"code\":-32601,\"message\":\"Method not found.\"},\"id\":10,\"jsonrpc\":\"2.0\"}" ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( message ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetJsonVersion ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2012-12-13 22:52:54 +01:00
result . Should ( ) . Be ( new XbmcVersion ( 0 ) ) ;
2011-07-09 20:19:33 +02:00
}
[TestCase(false, false, false)]
[TestCase(true, true, true)]
[TestCase(true, false, false)]
[TestCase(true, true, false)]
[TestCase(false, true, false)]
[TestCase(false, true, true)]
[TestCase(false, false, true)]
[TestCase(true, false, true)]
2011-12-31 21:57:02 +01:00
public void GetActivePlayersDharma ( bool audio , bool picture , bool video )
2011-07-09 20:19:33 +02:00
{
2013-03-28 23:07:09 +01:00
2011-07-09 20:19:33 +02:00
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"audio\":"
+ audio . ToString ( ) . ToLower ( )
+ ",\"picture\":"
+ picture . ToString ( ) . ToLower ( )
+ ",\"video\":"
+ video . ToString ( ) . ToLower ( )
+ "}}" ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( message ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetActivePlayersDharma ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-07-09 20:19:33 +02:00
Assert . AreEqual ( audio , result [ "audio" ] ) ;
Assert . AreEqual ( picture , result [ "picture" ] ) ;
Assert . AreEqual ( video , result [ "video" ] ) ;
}
2011-12-31 21:57:02 +01:00
[Test]
public void GetActivePlayersEden_should_be_empty_when_no_active_players ( )
{
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
WithNoActivePlayers ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-12-31 21:57:02 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( EdenActivePlayers ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetActivePlayersEden ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
result . Should ( ) . BeEmpty ( ) ;
}
[Test]
public void GetActivePlayersEden_should_have_active_video_player ( )
{
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
WithVideoPlayerActive ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-12-31 21:57:02 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( EdenActivePlayers ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetActivePlayersEden ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
result . Should ( ) . HaveCount ( 1 ) ;
result . First ( ) . Type . Should ( ) . Be ( "video" ) ;
}
[Test]
public void GetActivePlayersEden_should_have_active_audio_player ( )
{
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
WithAudioPlayerActive ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-12-31 21:57:02 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( EdenActivePlayers ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetActivePlayersEden ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
result . Should ( ) . HaveCount ( 1 ) ;
result . First ( ) . Type . Should ( ) . Be ( "audio" ) ;
}
[Test]
public void GetActivePlayersEden_should_have_active_picture_player ( )
{
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
WithPicturePlayerActive ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-12-31 21:57:02 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( EdenActivePlayers ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetActivePlayersEden ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
result . Should ( ) . HaveCount ( 1 ) ;
result . First ( ) . Type . Should ( ) . Be ( "picture" ) ;
}
[Test]
public void GetActivePlayersEden_should_have_all_players_active ( )
{
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
WithAllPlayersActive ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-12-31 21:57:02 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( EdenActivePlayers ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetActivePlayersEden ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2013-03-28 23:07:09 +01:00
2011-12-31 21:57:02 +01:00
result . Should ( ) . HaveCount ( 3 ) ;
result . Select ( a = > a . PlayerId ) . Distinct ( ) . Should ( ) . HaveCount ( 3 ) ;
result . Select ( a = > a . Type ) . Distinct ( ) . Should ( ) . HaveCount ( 3 ) ;
}
2011-07-09 20:19:33 +02:00
[Test]
public void GetTvShowsJson ( )
{
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
2011-07-09 20:19:33 +02:00
var message = "{\"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}]}}" ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( message ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetTvShowsJson ( "localhost:8080" , "xbmc" , "xbmc" ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-07-09 20:19:33 +02:00
Assert . AreEqual ( 5 , result . Count ) ;
result . Should ( ) . Contain ( s = > s . ImdbNumber = = 79488 ) ;
}
[Test]
public void Notify_true ( )
{
2013-03-28 23:07:09 +01:00
2013-04-15 07:27:51 +02:00
2011-07-09 20:19:33 +02:00
var header = "NzbDrone Test" ;
var message = "Test Message!" ;
2013-02-24 20:39:31 +01:00
var fakeConfig = Mocker . GetMock < IConfigService > ( ) ;
2011-07-09 20:19:33 +02:00
fakeConfig . SetupGet ( s = > s . XbmcHosts ) . Returns ( "localhost:8080" ) ;
2011-12-15 05:15:53 +01:00
//var fakeUdpProvider = Mocker.GetMock<EventClient>();
var fakeEventClient = Mocker . GetMock < EventClientProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeEventClient . Setup ( s = > s . SendNotification ( header , message , IconType . Jpeg , "NzbDrone.jpg" , "localhost" ) ) . Returns ( true ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . Resolve < XbmcProvider > ( ) . Notify ( header , message ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . VerifyAllMocks ( ) ;
2011-07-09 20:19:33 +02:00
}
[Test]
public void SendCommand ( )
{
2013-03-28 23:07:09 +01:00
2013-04-15 07:27:51 +02:00
2011-07-09 20:19:33 +02:00
var host = "localhost:8080" ;
var command = "ExecBuiltIn(CleanLibrary(video))" ;
var username = "xbmc" ;
var password = "xbmc" ;
var url = String . Format ( "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(CleanLibrary(video))" ) ;
2011-12-15 05:15:53 +01:00
//var fakeUdpProvider = Mocker.GetMock<EventClient>();
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeHttp . Setup ( s = > s . DownloadString ( url , username , password ) ) . Returns ( "Ok\n" ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . SendCommand ( host , command , username , username ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . VerifyAllMocks ( ) ;
2011-07-09 20:19:33 +02:00
Assert . AreEqual ( "Ok\n" , result ) ;
}
[Test]
public void GetXbmcSeriesPath_true ( )
{
2013-03-28 23:07:09 +01:00
2013-04-15 07:27:51 +02:00
2011-07-09 20:19:33 +02:00
var queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/</field></record></xml>" ;
var host = "localhost:8080" ;
var username = "xbmc" ;
var password = "xbmc" ;
var setResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)" ;
var resetResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat()" ;
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)" ) ;
2011-12-15 05:15:53 +01:00
//var fakeUdpProvider = Mocker.GetMock<EventClient>();
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeHttp . Setup ( s = > s . DownloadString ( setResponseUrl , username , password ) ) . Returns ( "<xml><tag>OK</xml>" ) ;
fakeHttp . Setup ( s = > s . DownloadString ( resetResponseUrl , username , password ) ) . Returns ( @ "<html>
< li > OK
< / html > ");
fakeHttp . Setup ( s = > s . DownloadString ( query , username , password ) ) . Returns ( queryResult ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetXbmcSeriesPath ( host , 79488 , username , username ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . VerifyAllMocks ( ) ;
2011-07-09 20:19:33 +02:00
Assert . AreEqual ( "smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/" , result ) ;
}
[Test]
public void GetXbmcSeriesPath_false ( )
{
2013-03-28 23:07:09 +01:00
2013-04-15 07:27:51 +02:00
2011-07-09 20:19:33 +02:00
var queryResult = @"<xml></xml>" ;
var host = "localhost:8080" ;
var username = "xbmc" ;
var password = "xbmc" ;
var setResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)" ;
var resetResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat()" ;
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)" ) ;
2011-12-15 05:15:53 +01:00
//var fakeUdpProvider = Mocker.GetMock<EventClient>();
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeHttp . Setup ( s = > s . DownloadString ( setResponseUrl , username , password ) ) . Returns ( "<xml><tag>OK</xml>" ) ;
fakeHttp . Setup ( s = > s . DownloadString ( resetResponseUrl , username , password ) ) . Returns ( @ "<html>
< li > OK
< / html > ");
fakeHttp . Setup ( s = > s . DownloadString ( query , username , password ) ) . Returns ( queryResult ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetXbmcSeriesPath ( host , 79488 , username , username ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . VerifyAllMocks ( ) ;
2011-07-09 20:19:33 +02:00
Assert . AreEqual ( "" , result ) ;
}
2011-09-29 06:39:05 +02:00
[Test]
public void GetXbmcSeriesPath_special_characters ( )
{
2013-03-28 23:07:09 +01:00
2013-04-15 07:27:51 +02:00
2011-09-29 06:39:05 +02:00
var queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/</field></record></xml>" ;
var host = "localhost:8080" ;
var username = "xbmc" ;
var password = "xbmc" ;
var setResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)" ;
var resetResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat()" ;
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)" ) ;
2011-12-15 05:15:53 +01:00
//var fakeUdpProvider = Mocker.GetMock<EventClient>();
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-09-29 06:39:05 +02:00
fakeHttp . Setup ( s = > s . DownloadString ( setResponseUrl , username , password ) ) . Returns ( "<xml><tag>OK</xml>" ) ;
fakeHttp . Setup ( s = > s . DownloadString ( resetResponseUrl , username , password ) ) . Returns ( @ "<html>
< li > OK
< / html > ");
fakeHttp . Setup ( s = > s . DownloadString ( query , username , password ) ) . Returns ( queryResult ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . GetXbmcSeriesPath ( host , 79488 , username , username ) ;
2011-09-29 06:39:05 +02:00
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . VerifyAllMocks ( ) ;
2011-09-29 06:39:05 +02:00
result . Should ( ) . Be ( "smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/" ) ;
}
2011-07-09 20:19:33 +02:00
[Test]
public void Clean ( )
{
2013-03-28 23:07:09 +01:00
2013-04-15 07:27:51 +02:00
2011-07-09 20:19:33 +02:00
2013-02-24 20:39:31 +01:00
var fakeConfig = Mocker . GetMock < IConfigService > ( ) ;
2011-07-09 20:19:33 +02:00
fakeConfig . SetupGet ( s = > s . XbmcHosts ) . Returns ( "localhost:8080" ) ;
2011-12-15 05:15:53 +01:00
var fakeEventClient = Mocker . GetMock < EventClientProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeEventClient . Setup ( s = > s . SendAction ( "localhost" , ActionType . ExecBuiltin , "ExecBuiltIn(CleanLibrary(video))" ) ) . Returns ( true ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . Resolve < XbmcProvider > ( ) . Clean ( ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . VerifyAllMocks ( ) ;
2011-07-09 20:19:33 +02:00
}
[Test]
public void UpdateWithHttp_Single ( )
{
var host = "localhost:8080" ;
var username = "xbmc" ;
var password = "xbmc" ;
var queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/</field></record></xml>" ;
var queryUrl = "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)" ;
var url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video,smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/))" ;
var fakeSeries = Builder < Series > . CreateNew ( )
2013-02-26 04:58:57 +01:00
. With ( s = > s . Id = 79488 )
2011-07-09 20:19:33 +02:00
. With ( s = > s . Title = "30 Rock" )
. Build ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeHttp . Setup ( s = > s . DownloadString ( queryUrl , username , password ) ) . Returns ( queryResult ) ;
fakeHttp . Setup ( s = > s . DownloadString ( url , username , password ) ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . Resolve < XbmcProvider > ( ) . UpdateWithHttp ( fakeSeries , host , username , password ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . VerifyAllMocks ( ) ;
2011-07-09 20:19:33 +02:00
}
[Test]
public void UpdateWithHttp_All ( )
{
var host = "localhost:8080" ;
var username = "xbmc" ;
var password = "xbmc" ;
var queryResult = @"<xml></xml>" ;
var queryUrl = "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)" ;
var url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))" ;
var fakeSeries = Builder < Series > . CreateNew ( )
2013-02-26 04:58:57 +01:00
. With ( s = > s . Id = 79488 )
2011-07-09 20:19:33 +02:00
. With ( s = > s . Title = "30 Rock" )
. Build ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2011-07-09 20:19:33 +02:00
fakeHttp . Setup ( s = > s . DownloadString ( queryUrl , username , password ) ) . Returns ( queryResult ) ;
fakeHttp . Setup ( s = > s . DownloadString ( url , username , password ) ) ;
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . Resolve < XbmcProvider > ( ) . UpdateWithHttp ( fakeSeries , host , username , password ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker . VerifyAllMocks ( ) ;
2011-07-09 20:19:33 +02:00
}
[Test]
2012-12-14 06:18:15 +01:00
public void UpdateWithJsonBuiltIn_Single ( )
2011-07-09 20:19:33 +02:00
{
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
2011-07-09 20:19:33 +02:00
var host = "localhost:8080" ;
var username = "xbmc" ;
var password = "xbmc" ;
2012-01-05 01:41:42 +01:00
var expectedJson = "{\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.GetTvShows\",\"params\":{\"properties\":[\"file\",\"imdbnumber\"]},\"id\":10}" ;
2011-07-09 20:19:33 +02:00
var tvshows = "{\"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}]}}" ;
var fakeSeries = Builder < Series > . CreateNew ( )
2013-02-26 04:58:57 +01:00
. With ( s = > s . Id = 79488 )
2011-07-09 20:19:33 +02:00
. With ( s = > s . Title = "30 Rock" )
. Build ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2012-01-05 01:41:42 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( host , username , password , It . Is < string > ( e = > e . Replace ( " " , "" ) . Replace ( "\r\n" , "" ) . Replace ( "\t" , "" ) = = expectedJson . Replace ( " " , "" ) ) ) )
2011-07-09 20:19:33 +02:00
. Returns ( tvshows ) ;
2012-01-10 08:10:53 +01:00
var command = "ExecBuiltIn(UpdateLibrary(video,smb://HOMESERVER/TV/30 Rock/))" ;
var url = String . Format ( "http://{0}/xbmcCmds/xbmcHttp?command={1}" , host , command ) ;
fakeHttp . Setup ( s = > s . DownloadString ( url , username , password ) ) . Returns ( "<html><li>OK</html>" ) ;
2013-03-28 23:07:09 +01:00
2012-12-14 06:18:15 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJsonExecBuiltIn ( fakeSeries , host , username , password ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2012-01-05 01:41:42 +01:00
result . Should ( ) . BeTrue ( ) ;
2011-07-09 20:19:33 +02:00
}
[Test]
2012-12-14 06:18:15 +01:00
public void UpdateWithJsonBuiltIn_All ( )
2011-07-09 20:19:33 +02:00
{
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
2011-07-09 20:19:33 +02:00
var host = "localhost:8080" ;
var username = "xbmc" ;
var password = "xbmc" ;
2012-01-05 01:41:42 +01:00
var expectedJson = "{\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.GetTvShows\",\"params\":{\"properties\":[\"file\",\"imdbnumber\"]},\"id\":10}" ;
2011-07-09 20:19:33 +02:00
var tvshows = "{\"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/90210/\",\"imdbnumber\":\"82716\",\"label\":\"90210\",\"tvshowid\":5}]}}" ;
var fakeSeries = Builder < Series > . CreateNew ( )
2013-02-26 04:58:57 +01:00
. With ( s = > s . Id = 79488 )
2011-07-09 20:19:33 +02:00
. With ( s = > s . Title = "30 Rock" )
. Build ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2012-01-05 01:41:42 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( host , username , password , It . Is < string > ( e = > e . Replace ( " " , "" ) . Replace ( "\r\n" , "" ) . Replace ( "\t" , "" ) = = expectedJson . Replace ( " " , "" ) ) ) )
2011-07-09 20:19:33 +02:00
. Returns ( tvshows ) ;
2012-01-10 08:10:53 +01:00
var command = "ExecBuiltIn(UpdateLibrary(video))" ;
var url = String . Format ( "http://{0}/xbmcCmds/xbmcHttp?command={1}" , host , command ) ;
fakeHttp . Setup ( s = > s . DownloadString ( url , username , password ) ) . Returns ( "<html><li>OK</html>" ) ;
//var fakeEventClient = Mocker.GetMock<EventClientProvider>();
//fakeEventClient.Setup(s => s.SendAction("localhost", ActionType.ExecBuiltin, "ExecBuiltIn(UpdateLibrary(video))"));
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2012-12-14 06:18:15 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJsonExecBuiltIn ( fakeSeries , host , username , password ) ;
2013-03-28 23:07:09 +01:00
2012-12-14 06:18:15 +01:00
result . Should ( ) . BeTrue ( ) ;
}
[Test]
public void UpdateWithJsonVideoLibraryScan_Single ( )
{
var host = "localhost:8080" ;
var username = "xbmc" ;
var password = "xbmc" ;
var expectedJson = "{\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.GetTvShows\",\"params\":{\"properties\":[\"file\",\"imdbnumber\"]},\"id\":10}" ;
var tvshows = "{\"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}]}}" ;
var fakeSeries = Builder < Series > . CreateNew ( )
2013-02-26 04:58:57 +01:00
. With ( s = > s . Id = 79488 )
2012-12-14 06:18:15 +01:00
. With ( s = > s . Title = "30 Rock" )
. Build ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2012-12-14 06:18:15 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( host , username , password , It . Is < string > ( e = > e . Replace ( " " , "" ) . Replace ( "\r\n" , "" ) . Replace ( "\t" , "" ) = = expectedJson . Replace ( " " , "" ) ) ) )
. Returns ( tvshows ) ;
fakeHttp . Setup ( s = > s . PostCommand ( host , username , 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\"}" ) ;
2013-03-28 23:07:09 +01:00
2012-12-14 06:18:15 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJsonVideoLibraryScan ( fakeSeries , host , username , password ) ;
2013-03-28 23:07:09 +01:00
2012-12-14 06:18:15 +01:00
result . Should ( ) . BeTrue ( ) ;
}
[Test]
public void UpdateWithJsonVideoLibraryScan_All ( )
{
var host = "localhost:8080" ;
var username = "xbmc" ;
var password = "xbmc" ;
var expectedJson = "{\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.GetTvShows\",\"params\":{\"properties\":[\"file\",\"imdbnumber\"]},\"id\":10}" ;
var tvshows = "{\"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/90210/\",\"imdbnumber\":\"82716\",\"label\":\"90210\",\"tvshowid\":5}]}}" ;
var fakeSeries = Builder < Series > . CreateNew ( )
2013-02-26 04:58:57 +01:00
. With ( s = > s . Id = 79488 )
2012-12-14 06:18:15 +01:00
. With ( s = > s . Title = "30 Rock" )
. Build ( ) ;
2013-04-11 01:41:45 +02:00
var fakeHttp = Mocker . GetMock < IHttpProvider > ( ) ;
2012-12-14 06:18:15 +01:00
fakeHttp . Setup ( s = > s . PostCommand ( host , username , password , It . Is < string > ( e = > e . Replace ( " " , "" ) . Replace ( "\r\n" , "" ) . Replace ( "\t" , "" ) = = expectedJson . Replace ( " " , "" ) ) ) )
. Returns ( tvshows ) ;
fakeHttp . Setup ( s = > s . PostCommand ( host , username , 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\"}" ) ;
2013-03-28 23:07:09 +01:00
2012-12-14 06:18:15 +01:00
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJsonVideoLibraryScan ( fakeSeries , host , username , password ) ;
2011-07-09 20:19:33 +02:00
2013-03-28 23:07:09 +01:00
2012-01-05 01:41:42 +01:00
result . Should ( ) . BeTrue ( ) ;
2011-07-09 20:19:33 +02:00
}
}
}