@ -93,12 +93,29 @@ namespace NzbDrone.Core.Test.ProviderTests
[TestCase(3)]
[TestCase(2)]
[TestCase(0)]
public void GetJsonVersion ( int number )
public void GetJsonVersion IntOnly ( int number )
{
//Setup
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":" + number + "}}" ;
var fakeHttp = Mocker . GetMock < HttpProvider > ( ) ;
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
. Returns ( message ) ;
var message = "{\"id\":10,\"jsonrpc\":\"2.0\",\"result\":{\"version\":" + number + "}}" ;
//Act
var result = Mocker . Resolve < XbmcProvider > ( ) . GetJsonVersion ( "localhost:8080" , "xbmc" , "xbmc" ) ;
//Assert
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 + "}}}" ;
var fakeHttp = Mocker . GetMock < HttpProvider > ( ) ;
fakeHttp . Setup ( s = > s . PostCommand ( "localhost:8080" , "xbmc" , "xbmc" , It . IsAny < string > ( ) ) )
@ -108,15 +125,12 @@ namespace NzbDrone.Core.Test.ProviderTests
var result = Mocker . Resolve < XbmcProvider > ( ) . GetJsonVersion ( "localhost:8080" , "xbmc" , "xbmc" ) ;
//Assert
Assert. AreEqual ( number , result ) ;
result. Should ( ) . Be ( new XbmcVersion ( major , minor , patch ) ) ;
}
[Test]
public void GetJsonVersion_error ( )
{
//Setup
var message = "{\"error\":{\"code\":-32601,\"message\":\"Method not found.\"},\"id\":10,\"jsonrpc\":\"2.0\"}" ;
var fakeHttp = Mocker . GetMock < HttpProvider > ( ) ;
@ -127,7 +141,7 @@ namespace NzbDrone.Core.Test.ProviderTests
var result = Mocker . Resolve < XbmcProvider > ( ) . GetJsonVersion ( "localhost:8080" , "xbmc" , "xbmc" ) ;
//Assert
Assert. AreEqual ( 0 , result ) ;
result. Should ( ) . Be ( new XbmcVersion ( 0 ) ) ;
}
[TestCase(false, false, false)]
@ -491,7 +505,7 @@ namespace NzbDrone.Core.Test.ProviderTests
}
[Test]
public void UpdateWithJson _Single( )
public void UpdateWithJson BuiltIn _Single( )
{
//Setup
@ -516,18 +530,15 @@ namespace NzbDrone.Core.Test.ProviderTests
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,smb://HOMESERVER/TV/30 Rock/))"));
//Act
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJson ( fakeSeries , host , username , password ) ;
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJsonExecBuiltIn ( fakeSeries , host , username , password ) ;
//Assert
result . Should ( ) . BeTrue ( ) ;
}
[Test]
public void UpdateWithJson _All( )
public void UpdateWithJson BuiltIn _All( )
{
//Setup
@ -556,7 +567,71 @@ namespace NzbDrone.Core.Test.ProviderTests
//fakeEventClient.Setup(s => s.SendAction("localhost", ActionType.ExecBuiltin, "ExecBuiltIn(UpdateLibrary(video))"));
//Act
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJson ( fakeSeries , host , username , password ) ;
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJsonExecBuiltIn ( fakeSeries , host , username , password ) ;
//Assert
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 ( )
. With ( s = > s . SeriesId = 79488 )
. With ( s = > s . Title = "30 Rock" )
. Build ( ) ;
var fakeHttp = Mocker . GetMock < HttpProvider > ( ) ;
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\"}" ) ;
//Act
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJsonVideoLibraryScan ( fakeSeries , host , username , password ) ;
//Assert
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 ( )
. With ( s = > s . SeriesId = 79488 )
. With ( s = > s . Title = "30 Rock" )
. Build ( ) ;
var fakeHttp = Mocker . GetMock < HttpProvider > ( ) ;
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\"}" ) ;
//Act
var result = Mocker . Resolve < XbmcProvider > ( ) . UpdateWithJsonVideoLibraryScan ( fakeSeries , host , username , password ) ;
//Assert
result . Should ( ) . BeTrue ( ) ;