2013-03-01 00:50:50 +00:00
|
|
|
|
using System.ServiceProcess;
|
2011-10-14 01:22:51 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2011-10-23 05:26:43 +00:00
|
|
|
|
using NzbDrone.Common;
|
2011-11-13 18:16:31 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.App.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-11-13 18:16:31 +00:00
|
|
|
|
public class RouterTest : TestBase
|
2011-10-14 01:22:51 +00:00
|
|
|
|
{
|
|
|
|
|
|
2013-03-01 00:50:50 +00:00
|
|
|
|
[TestCase(null, ApplicationModes.Console)]
|
|
|
|
|
[TestCase("", ApplicationModes.Console)]
|
|
|
|
|
[TestCase("1", ApplicationModes.Help)]
|
|
|
|
|
[TestCase("ii", ApplicationModes.Help)]
|
|
|
|
|
[TestCase("uu", ApplicationModes.Help)]
|
|
|
|
|
[TestCase("i", ApplicationModes.InstallService)]
|
|
|
|
|
[TestCase("I", ApplicationModes.InstallService)]
|
|
|
|
|
[TestCase("/I", ApplicationModes.InstallService)]
|
|
|
|
|
[TestCase("/i", ApplicationModes.InstallService)]
|
|
|
|
|
[TestCase("-I", ApplicationModes.InstallService)]
|
|
|
|
|
[TestCase("-i", ApplicationModes.InstallService)]
|
|
|
|
|
[TestCase("u", ApplicationModes.UninstallService)]
|
|
|
|
|
[TestCase("U", ApplicationModes.UninstallService)]
|
|
|
|
|
[TestCase("/U", ApplicationModes.UninstallService)]
|
|
|
|
|
[TestCase("/u", ApplicationModes.UninstallService)]
|
|
|
|
|
[TestCase("-U", ApplicationModes.UninstallService)]
|
|
|
|
|
[TestCase("-u", ApplicationModes.UninstallService)]
|
|
|
|
|
public void GetApplicationMode_single_arg(string arg, ApplicationModes modes)
|
2011-10-14 01:22:51 +00:00
|
|
|
|
{
|
2013-03-01 00:50:50 +00:00
|
|
|
|
Router.GetApplicationMode(new[] { arg }).Should().Be(modes);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-01 00:50:50 +00:00
|
|
|
|
[TestCase("", "", ApplicationModes.Console)]
|
|
|
|
|
[TestCase("", null, ApplicationModes.Console)]
|
|
|
|
|
[TestCase("i", "n", ApplicationModes.Help)]
|
|
|
|
|
public void GetApplicationMode_two_args(string a, string b, ApplicationModes modes)
|
2011-10-14 01:22:51 +00:00
|
|
|
|
{
|
2013-03-01 00:50:50 +00:00
|
|
|
|
Router.GetApplicationMode(new[] { a, b }).Should().Be(modes);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Route_should_call_install_service_when_application_mode_is_install()
|
|
|
|
|
{
|
2012-01-17 07:12:22 +00:00
|
|
|
|
var serviceProviderMock = Mocker.GetMock<ServiceProvider>(MockBehavior.Strict);
|
2011-10-26 17:15:47 +00:00
|
|
|
|
serviceProviderMock.Setup(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
|
|
|
|
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
|
2012-01-17 07:12:22 +00:00
|
|
|
|
serviceProviderMock.Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
2012-03-07 02:59:43 +00:00
|
|
|
|
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2013-03-01 00:50:50 +00:00
|
|
|
|
Mocker.Resolve<Router>().Route(ApplicationModes.InstallService);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2011-10-26 17:15:47 +00:00
|
|
|
|
serviceProviderMock.Verify(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
2011-10-14 01:22:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-15 00:41:09 +00:00
|
|
|
|
|
2011-10-14 01:22:51 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Route_should_call_uninstall_service_when_application_mode_is_uninstall()
|
|
|
|
|
{
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var serviceProviderMock = Mocker.GetMock<ServiceProvider>();
|
2011-10-26 17:15:47 +00:00
|
|
|
|
serviceProviderMock.Setup(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
2012-03-07 02:59:43 +00:00
|
|
|
|
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2011-10-26 17:15:47 +00:00
|
|
|
|
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2013-03-01 00:50:50 +00:00
|
|
|
|
Mocker.Resolve<Router>().Route(ApplicationModes.UninstallService);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2011-10-26 17:15:47 +00:00
|
|
|
|
serviceProviderMock.Verify(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
2011-10-14 01:22:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Route_should_call_console_service_when_application_mode_is_console()
|
|
|
|
|
{
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var consoleProvider = Mocker.GetMock<ConsoleProvider>();
|
|
|
|
|
var appServerProvider = Mocker.GetMock<ApplicationServer>();
|
2011-10-14 01:22:51 +00:00
|
|
|
|
consoleProvider.Setup(c => c.WaitForClose());
|
|
|
|
|
appServerProvider.Setup(c => c.Start());
|
2012-03-07 02:59:43 +00:00
|
|
|
|
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2013-03-01 00:50:50 +00:00
|
|
|
|
Mocker.Resolve<Router>().Route(ApplicationModes.Console);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
|
|
|
|
consoleProvider.Verify(c => c.WaitForClose(), Times.Once());
|
|
|
|
|
appServerProvider.Verify(c => c.Start(), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-01 00:50:50 +00:00
|
|
|
|
[TestCase(ApplicationModes.Console)]
|
|
|
|
|
[TestCase(ApplicationModes.InstallService)]
|
|
|
|
|
[TestCase(ApplicationModes.UninstallService)]
|
|
|
|
|
[TestCase(ApplicationModes.Help)]
|
|
|
|
|
public void Route_should_call_service_start_when_run_in_service_more(ApplicationModes applicationModes)
|
2011-10-14 01:22:51 +00:00
|
|
|
|
{
|
2012-03-07 02:59:43 +00:00
|
|
|
|
var envMock = Mocker.GetMock<EnvironmentProvider>();
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var serviceProvider = Mocker.GetMock<ServiceProvider>();
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2011-10-15 00:41:09 +00:00
|
|
|
|
envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
|
|
|
|
|
|
|
|
|
|
serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>()));
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2013-03-01 00:50:50 +00:00
|
|
|
|
Mocker.Resolve<Router>().Route(applicationModes);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2011-10-15 00:41:09 +00:00
|
|
|
|
serviceProvider.Verify(c => c.Run(It.IsAny<ServiceBase>()), Times.Once());
|
2011-10-14 01:22:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void show_error_on_install_if_service_already_exist()
|
|
|
|
|
{
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var consoleMock = Mocker.GetMock<ConsoleProvider>();
|
|
|
|
|
var serviceMock = Mocker.GetMock<ServiceProvider>();
|
2012-03-07 02:59:43 +00:00
|
|
|
|
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
|
|
|
|
consoleMock.Setup(c => c.PrintServiceAlreadyExist());
|
2011-10-26 17:15:47 +00:00
|
|
|
|
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2013-03-01 00:50:50 +00:00
|
|
|
|
Mocker.Resolve<Router>().Route(ApplicationModes.InstallService);
|
2011-10-14 01:22:51 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-14 01:22:51 +00:00
|
|
|
|
}
|
2011-10-15 00:41:09 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void show_error_on_uninstall_if_service_doesnt_exist()
|
|
|
|
|
{
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var consoleMock = Mocker.GetMock<ConsoleProvider>();
|
|
|
|
|
var serviceMock = Mocker.GetMock<ServiceProvider>();
|
2012-03-07 02:59:43 +00:00
|
|
|
|
Mocker.GetMock<EnvironmentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2011-10-15 00:41:09 +00:00
|
|
|
|
|
|
|
|
|
consoleMock.Setup(c => c.PrintServiceDoestExist());
|
2011-10-26 17:15:47 +00:00
|
|
|
|
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
|
2011-10-15 00:41:09 +00:00
|
|
|
|
|
2013-03-01 00:50:50 +00:00
|
|
|
|
Mocker.Resolve<Router>().Route(ApplicationModes.UninstallService);
|
2011-10-15 00:41:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-15 00:41:09 +00:00
|
|
|
|
}
|
2011-10-14 01:22:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|