@ -1,12 +1,9 @@
using System.IO ;
using System.ServiceProcess ;
using System.ServiceProcess ;
using FluentAssertions ;
using FluentAssertions ;
using Moq ;
using Moq ;
using NUnit.Framework ;
using NUnit.Framework ;
using NzbDrone.Common ;
using NzbDrone.Common ;
using NzbDrone.Model ;
using NzbDrone.Test.Common ;
using NzbDrone.Test.Common ;
using NzbDrone.Test.Common.AutoMoq ;
namespace NzbDrone.App.Test
namespace NzbDrone.App.Test
{
{
@ -14,34 +11,34 @@ namespace NzbDrone.App.Test
public class RouterTest : TestBase
public class RouterTest : TestBase
{
{
[TestCase(null, ApplicationMode .Console)]
[TestCase(null, ApplicationMode s .Console)]
[TestCase("", ApplicationMode .Console)]
[TestCase("", ApplicationMode s .Console)]
[TestCase("1", ApplicationMode .Help)]
[TestCase("1", ApplicationMode s .Help)]
[TestCase("ii", ApplicationMode .Help)]
[TestCase("ii", ApplicationMode s .Help)]
[TestCase("uu", ApplicationMode .Help)]
[TestCase("uu", ApplicationMode s .Help)]
[TestCase("i", ApplicationMode .InstallService)]
[TestCase("i", ApplicationMode s .InstallService)]
[TestCase("I", ApplicationMode .InstallService)]
[TestCase("I", ApplicationMode s .InstallService)]
[TestCase("/I", ApplicationMode .InstallService)]
[TestCase("/I", ApplicationMode s .InstallService)]
[TestCase("/i", ApplicationMode .InstallService)]
[TestCase("/i", ApplicationMode s .InstallService)]
[TestCase("-I", ApplicationMode .InstallService)]
[TestCase("-I", ApplicationMode s .InstallService)]
[TestCase("-i", ApplicationMode .InstallService)]
[TestCase("-i", ApplicationMode s .InstallService)]
[TestCase("u", ApplicationMode .UninstallService)]
[TestCase("u", ApplicationMode s .UninstallService)]
[TestCase("U", ApplicationMode .UninstallService)]
[TestCase("U", ApplicationMode s .UninstallService)]
[TestCase("/U", ApplicationMode .UninstallService)]
[TestCase("/U", ApplicationMode s .UninstallService)]
[TestCase("/u", ApplicationMode .UninstallService)]
[TestCase("/u", ApplicationMode s .UninstallService)]
[TestCase("-U", ApplicationMode .UninstallService)]
[TestCase("-U", ApplicationMode s .UninstallService)]
[TestCase("-u", ApplicationMode .UninstallService)]
[TestCase("-u", ApplicationMode s .UninstallService)]
public void GetApplicationMode_single_arg ( string arg , ApplicationMode mode )
public void GetApplicationMode_single_arg ( string arg , ApplicationMode s mode s )
{
{
Router . GetApplicationMode ( new [ ] { arg } ) . Should ( ) . Be ( mode ) ;
Router . GetApplicationMode ( new [ ] { arg } ) . Should ( ) . Be ( mode s ) ;
}
}
[TestCase("", "", ApplicationMode .Console)]
[TestCase("", "", ApplicationMode s .Console)]
[TestCase("", null, ApplicationMode .Console)]
[TestCase("", null, ApplicationMode s .Console)]
[TestCase("i", "n", ApplicationMode .Help)]
[TestCase("i", "n", ApplicationMode s .Help)]
public void GetApplicationMode_two_args ( string a , string b , ApplicationMode mode )
public void GetApplicationMode_two_args ( string a , string b , ApplicationMode s mode s )
{
{
Router . GetApplicationMode ( new [ ] { a , b } ) . Should ( ) . Be ( mode ) ;
Router . GetApplicationMode ( new [ ] { a , b } ) . Should ( ) . Be ( mode s ) ;
}
}
[Test]
[Test]
@ -53,7 +50,7 @@ namespace NzbDrone.App.Test
serviceProviderMock . Setup ( c = > c . Start ( ServiceProvider . NZBDRONE_SERVICE_NAME ) ) ;
serviceProviderMock . Setup ( c = > c . Start ( ServiceProvider . NZBDRONE_SERVICE_NAME ) ) ;
Mocker . GetMock < EnvironmentProvider > ( ) . SetupGet ( c = > c . IsUserInteractive ) . Returns ( true ) ;
Mocker . GetMock < EnvironmentProvider > ( ) . SetupGet ( c = > c . IsUserInteractive ) . Returns ( true ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode . InstallService ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode s . InstallService ) ;
serviceProviderMock . Verify ( c = > c . Install ( ServiceProvider . NZBDRONE_SERVICE_NAME ) , Times . Once ( ) ) ;
serviceProviderMock . Verify ( c = > c . Install ( ServiceProvider . NZBDRONE_SERVICE_NAME ) , Times . Once ( ) ) ;
}
}
@ -67,7 +64,7 @@ namespace NzbDrone.App.Test
Mocker . GetMock < EnvironmentProvider > ( ) . SetupGet ( c = > c . IsUserInteractive ) . Returns ( true ) ;
Mocker . GetMock < EnvironmentProvider > ( ) . SetupGet ( c = > c . IsUserInteractive ) . Returns ( true ) ;
serviceProviderMock . Setup ( c = > c . ServiceExist ( ServiceProvider . NZBDRONE_SERVICE_NAME ) ) . Returns ( true ) ;
serviceProviderMock . Setup ( c = > c . ServiceExist ( ServiceProvider . NZBDRONE_SERVICE_NAME ) ) . Returns ( true ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode . UninstallService ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode s . UninstallService ) ;
serviceProviderMock . Verify ( c = > c . UnInstall ( ServiceProvider . NZBDRONE_SERVICE_NAME ) , Times . Once ( ) ) ;
serviceProviderMock . Verify ( c = > c . UnInstall ( ServiceProvider . NZBDRONE_SERVICE_NAME ) , Times . Once ( ) ) ;
}
}
@ -81,17 +78,17 @@ namespace NzbDrone.App.Test
appServerProvider . Setup ( c = > c . Start ( ) ) ;
appServerProvider . Setup ( c = > c . Start ( ) ) ;
Mocker . GetMock < EnvironmentProvider > ( ) . SetupGet ( c = > c . IsUserInteractive ) . Returns ( true ) ;
Mocker . GetMock < EnvironmentProvider > ( ) . SetupGet ( c = > c . IsUserInteractive ) . Returns ( true ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode . Console ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode s . Console ) ;
consoleProvider . Verify ( c = > c . WaitForClose ( ) , Times . Once ( ) ) ;
consoleProvider . Verify ( c = > c . WaitForClose ( ) , Times . Once ( ) ) ;
appServerProvider . Verify ( c = > c . Start ( ) , Times . Once ( ) ) ;
appServerProvider . Verify ( c = > c . Start ( ) , Times . Once ( ) ) ;
}
}
[TestCase(ApplicationMode .Console)]
[TestCase(ApplicationMode s .Console)]
[TestCase(ApplicationMode .InstallService)]
[TestCase(ApplicationMode s .InstallService)]
[TestCase(ApplicationMode .UninstallService)]
[TestCase(ApplicationMode s .UninstallService)]
[TestCase(ApplicationMode .Help)]
[TestCase(ApplicationMode s .Help)]
public void Route_should_call_service_start_when_run_in_service_more ( ApplicationMode applicationMode )
public void Route_should_call_service_start_when_run_in_service_more ( ApplicationMode s applicationMode s )
{
{
var envMock = Mocker . GetMock < EnvironmentProvider > ( ) ;
var envMock = Mocker . GetMock < EnvironmentProvider > ( ) ;
var serviceProvider = Mocker . GetMock < ServiceProvider > ( ) ;
var serviceProvider = Mocker . GetMock < ServiceProvider > ( ) ;
@ -100,7 +97,7 @@ namespace NzbDrone.App.Test
serviceProvider . Setup ( c = > c . Run ( It . IsAny < ServiceBase > ( ) ) ) ;
serviceProvider . Setup ( c = > c . Run ( It . IsAny < ServiceBase > ( ) ) ) ;
Mocker . Resolve < Router > ( ) . Route ( applicationMode ) ;
Mocker . Resolve < Router > ( ) . Route ( applicationMode s ) ;
serviceProvider . Verify ( c = > c . Run ( It . IsAny < ServiceBase > ( ) ) , Times . Once ( ) ) ;
serviceProvider . Verify ( c = > c . Run ( It . IsAny < ServiceBase > ( ) ) , Times . Once ( ) ) ;
}
}
@ -116,7 +113,7 @@ namespace NzbDrone.App.Test
consoleMock . Setup ( c = > c . PrintServiceAlreadyExist ( ) ) ;
consoleMock . Setup ( c = > c . PrintServiceAlreadyExist ( ) ) ;
serviceMock . Setup ( c = > c . ServiceExist ( ServiceProvider . NZBDRONE_SERVICE_NAME ) ) . Returns ( true ) ;
serviceMock . Setup ( c = > c . ServiceExist ( ServiceProvider . NZBDRONE_SERVICE_NAME ) ) . Returns ( true ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode . InstallService ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode s . InstallService ) ;
Mocker . VerifyAllMocks ( ) ;
Mocker . VerifyAllMocks ( ) ;
}
}
@ -131,7 +128,7 @@ namespace NzbDrone.App.Test
consoleMock . Setup ( c = > c . PrintServiceDoestExist ( ) ) ;
consoleMock . Setup ( c = > c . PrintServiceDoestExist ( ) ) ;
serviceMock . Setup ( c = > c . ServiceExist ( ServiceProvider . NZBDRONE_SERVICE_NAME ) ) . Returns ( false ) ;
serviceMock . Setup ( c = > c . ServiceExist ( ServiceProvider . NZBDRONE_SERVICE_NAME ) ) . Returns ( false ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode . UninstallService ) ;
Mocker . Resolve < Router > ( ) . Route ( ApplicationMode s . UninstallService ) ;
Mocker . VerifyAllMocks ( ) ;
Mocker . VerifyAllMocks ( ) ;
}
}