@ -55,7 +55,7 @@ namespace PlexRequests.Services.Tests
var plexMock = new Mock < IPlexApi > ( ) ;
var plexMock = new Mock < IPlexApi > ( ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Assert . Throws < ApplicationSettingsException > ( ( ) = > Checker . IsAvailable ( "title" , "2013" ), "We should be throwing an exception since we cannot talk to the services." ) ;
Assert . Throws < ApplicationSettingsException > ( ( ) = > Checker . IsAvailable ( "title" , "2013" , null , PlexType . TvShow ), "We should be throwing an exception since we cannot talk to the services." ) ;
}
}
[Test]
[Test]
@ -74,20 +74,20 @@ namespace PlexRequests.Services.Tests
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
var result = Checker . IsAvailable ( "title" , "2011" );
var result = Checker . IsAvailable ( "title" , "2011" , null , PlexType . Movie );
Assert . That ( result , Is . True ) ;
Assert . That ( result , Is . True ) ;
}
}
[Test]
[Test]
public void IsAvailable DirectoryTitleTest( )
public void IsAvailable Music DirectoryTitleTest( )
{
{
var settingsMock = new Mock < ISettingsService < PlexSettings > > ( ) ;
var settingsMock = new Mock < ISettingsService < PlexSettings > > ( ) ;
var authMock = new Mock < ISettingsService < AuthenticationSettings > > ( ) ;
var authMock = new Mock < ISettingsService < AuthenticationSettings > > ( ) ;
var requestMock = new Mock < IRequestService > ( ) ;
var requestMock = new Mock < IRequestService > ( ) ;
var plexMock = new Mock < IPlexApi > ( ) ;
var plexMock = new Mock < IPlexApi > ( ) ;
var searchResult = new PlexSearch { Directory = new Directory1 { Title = "title" , Year = "2013" } } ;
var searchResult = new PlexSearch { Directory = new List< Directory1 > { new Directory1 { Title = "title" , Year = "2013" , ParentTitle = "dIzZy" } } } ;
settingsMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new PlexSettings { Ip = "abc" } ) ;
settingsMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new PlexSettings { Ip = "abc" } ) ;
authMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new AuthenticationSettings { PlexAuthToken = "abc" } ) ;
authMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new AuthenticationSettings { PlexAuthToken = "abc" } ) ;
@ -95,11 +95,32 @@ namespace PlexRequests.Services.Tests
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
var result = Checker . IsAvailable ( "title" , "2013" );
var result = Checker . IsAvailable ( "title" , "2013" , "dIzZy" , PlexType . Music );
Assert . That ( result , Is . True ) ;
Assert . That ( result , Is . True ) ;
}
}
[Test]
public void IsNotAvailableMusicDirectoryTitleTest ( )
{
var settingsMock = new Mock < ISettingsService < PlexSettings > > ( ) ;
var authMock = new Mock < ISettingsService < AuthenticationSettings > > ( ) ;
var requestMock = new Mock < IRequestService > ( ) ;
var plexMock = new Mock < IPlexApi > ( ) ;
var searchResult = new PlexSearch { Directory = new List < Directory1 > { new Directory1 { Title = "title2" , Year = "1992" , ParentTitle = "dIzZy" } } } ;
settingsMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new PlexSettings { Ip = "abc" } ) ;
authMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new AuthenticationSettings { PlexAuthToken = "abc" } ) ;
plexMock . Setup ( x = > x . SearchContent ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < Uri > ( ) ) ) . Returns ( searchResult ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
var result = Checker . IsAvailable ( "title" , "2013" , "dIzZy" , PlexType . Music ) ;
Assert . That ( result , Is . False ) ;
}
[Test]
[Test]
public void IsAvailableDirectoryTitleWithoutYearTest ( )
public void IsAvailableDirectoryTitleWithoutYearTest ( )
{
{
@ -108,7 +129,7 @@ namespace PlexRequests.Services.Tests
var requestMock = new Mock < IRequestService > ( ) ;
var requestMock = new Mock < IRequestService > ( ) ;
var plexMock = new Mock < IPlexApi > ( ) ;
var plexMock = new Mock < IPlexApi > ( ) ;
var searchResult = new PlexSearch { Directory = new Directory1 { Title = "title" , } } ;
var searchResult = new PlexSearch { Directory = new List< Directory1 > { new Directory1 { Title = "title" , } } } ;
settingsMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new PlexSettings { Ip = "abc" } ) ;
settingsMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new PlexSettings { Ip = "abc" } ) ;
authMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new AuthenticationSettings { PlexAuthToken = "abc" } ) ;
authMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new AuthenticationSettings { PlexAuthToken = "abc" } ) ;
@ -116,7 +137,7 @@ namespace PlexRequests.Services.Tests
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
var result = Checker . IsAvailable ( "title" , null );
var result = Checker . IsAvailable ( "title" , null , null , PlexType . Movie );
Assert . That ( result , Is . True ) ;
Assert . That ( result , Is . True ) ;
}
}
@ -137,7 +158,7 @@ namespace PlexRequests.Services.Tests
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
var result = Checker . IsAvailable ( "title" , "2011" );
var result = Checker . IsAvailable ( "title" , "2011" , null , PlexType . Movie );
Assert . That ( result , Is . False ) ;
Assert . That ( result , Is . False ) ;
}
}
@ -158,7 +179,7 @@ namespace PlexRequests.Services.Tests
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
var result = Checker . IsAvailable ( "title" , null );
var result = Checker . IsAvailable ( "title" , null , null , PlexType . Movie );
Assert . That ( result , Is . False ) ;
Assert . That ( result , Is . False ) ;
}
}
@ -179,7 +200,7 @@ namespace PlexRequests.Services.Tests
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
var result = Checker . IsAvailable ( "title" , "2011" );
var result = Checker . IsAvailable ( "title" , "2011" , null , PlexType . Movie );
Assert . That ( result , Is . False ) ;
Assert . That ( result , Is . False ) ;
}
}
@ -200,7 +221,7 @@ namespace PlexRequests.Services.Tests
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
var result = Checker . IsAvailable ( "title" , "2019" );
var result = Checker . IsAvailable ( "title" , "2019" , null , PlexType . Movie );
Assert . That ( result , Is . False ) ;
Assert . That ( result , Is . False ) ;
}
}
@ -221,7 +242,7 @@ namespace PlexRequests.Services.Tests
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
var result = Checker . IsAvailable ( "title" , null );
var result = Checker . IsAvailable ( "title" , null , null , PlexType . Movie );
Assert . That ( result , Is . False ) ;
Assert . That ( result , Is . False ) ;
}
}
@ -328,11 +349,11 @@ namespace PlexRequests.Services.Tests
Title = "Title2" ,
Title = "Title2" ,
}
}
} ,
} ,
Directory = new Directory1
Directory = new List< Directory1 > { new Directory1
{
{
Title = "Title9" ,
Title = "Title9" ,
Year = "1978"
Year = "1978"
}
} }
} ;
} ;
var settingsMock = new Mock < ISettingsService < PlexSettings > > ( ) ;
var settingsMock = new Mock < ISettingsService < PlexSettings > > ( ) ;
@ -402,10 +423,107 @@ namespace PlexRequests.Services.Tests
Title = "Hi" ,
Title = "Hi" ,
}
}
} ,
} ,
Directory = new Directory1
Directory = new List< Directory1 > { new Directory1
{
{
Title = "missingTitle" ,
Title = "missingTitle" ,
Year = "1978"
Year = "1978"
} }
} ;
var settingsMock = new Mock < ISettingsService < PlexSettings > > ( ) ;
var authMock = new Mock < ISettingsService < AuthenticationSettings > > ( ) ;
var requestMock = new Mock < IRequestService > ( ) ;
var plexMock = new Mock < IPlexApi > ( ) ;
settingsMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new PlexSettings { Ip = "192.168.1.1" } ) ;
authMock . Setup ( x = > x . GetSettings ( ) ) . Returns ( new AuthenticationSettings { PlexAuthToken = "abc" } ) ;
requestMock . Setup ( x = > x . GetAll ( ) ) . Returns ( requests ) ;
plexMock . Setup ( x = > x . SearchContent ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < Uri > ( ) ) ) . Returns ( search ) ;
Checker = new PlexAvailabilityChecker ( settingsMock . Object , authMock . Object , requestMock . Object , plexMock . Object ) ;
Checker . CheckAndUpdateAll ( 1 ) ;
requestMock . Verify ( x = > x . BatchUpdate ( It . IsAny < List < RequestedModel > > ( ) ) , Times . Once ) ;
requestMock . Verify ( x = > x . Get ( It . IsAny < int > ( ) ) , Times . Never ) ;
plexMock . Verify ( x = > x . SearchContent ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < Uri > ( ) ) , Times . Exactly ( 4 ) ) ;
}
[Test]
public void CheckAndUpdateAllMusicRequestsTest ( )
{
var requests = new List < RequestedModel > {
new RequestedModel
{
Id = 123 ,
Title = "title1" ,
Available = false ,
ArtistName = "dizzy" ,
Type = RequestType . Album ,
ReleaseDate = new DateTime ( 2010 , 1 , 1 )
} ,
new RequestedModel
{
Id = 222 ,
Title = "title3" ,
Available = false ,
ArtistName = "a" ,
Type = RequestType . Album ,
ReleaseDate = new DateTime ( 2006 , 1 , 1 )
} ,
new RequestedModel
{
Id = 333 ,
Title = "missingTitle" ,
Available = false ,
ArtistName = "b" ,
Type = RequestType . Album ,
ReleaseDate = new DateTime ( 1992 , 1 , 1 )
} ,
new RequestedModel
{
Id = 444 ,
Title = "Hi" ,
Available = false ,
ArtistName = "c" ,
Type = RequestType . Album ,
ReleaseDate = new DateTime ( 2017 , 1 , 1 )
}
} ;
var search = new PlexSearch
{
Directory = new List < Directory1 > {
new Directory1
{
Title = "missingTitle" ,
Year = "1978" ,
ParentTitle = "c"
} ,
new Directory1
{
Title = "Hi" ,
Year = "1978" ,
ParentTitle = "c"
} ,
new Directory1
{
Title = "Hi" ,
Year = "2017" ,
ParentTitle = "c"
} ,
new Directory1
{
Title = "missingTitle" ,
Year = "1992" ,
ParentTitle = "b"
} ,
new Directory1
{
Title = "title1" ,
Year = "2010" ,
ParentTitle = "DiZzY"
} ,
}
}
} ;
} ;