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