2013-03-01 01:50:50 +01:00
|
|
|
|
using System.ServiceProcess;
|
2011-10-14 03:22:51 +02:00
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2011-10-23 07:26:43 +02:00
|
|
|
|
using NzbDrone.Common;
|
2013-06-28 02:04:52 +02:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2011-11-13 19:16:31 +01:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.App.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-04-16 06:52:41 +02:00
|
|
|
|
public class RouterTest : TestBase<Router>
|
2011-10-14 03:22:51 +02:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void Route_should_call_install_service_when_application_mode_is_install()
|
|
|
|
|
{
|
2013-05-11 01:53:50 +02:00
|
|
|
|
var serviceProviderMock = Mocker.GetMock<IServiceProvider>(MockBehavior.Strict);
|
2011-10-26 19:15:47 +02:00
|
|
|
|
serviceProviderMock.Setup(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
|
|
|
|
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
|
2012-01-17 08:12:22 +01:00
|
|
|
|
serviceProviderMock.Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
2013-06-28 02:04:52 +02:00
|
|
|
|
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2013-04-16 06:52:41 +02:00
|
|
|
|
Subject.Route(ApplicationModes.InstallService);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2011-10-26 19:15:47 +02:00
|
|
|
|
serviceProviderMock.Verify(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
2011-10-14 03:22:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 06:52:41 +02:00
|
|
|
|
|
2011-10-14 03:22:51 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void Route_should_call_uninstall_service_when_application_mode_is_uninstall()
|
|
|
|
|
{
|
2013-05-11 01:53:50 +02:00
|
|
|
|
var serviceProviderMock = Mocker.GetMock<IServiceProvider>();
|
2011-10-26 19:15:47 +02:00
|
|
|
|
serviceProviderMock.Setup(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME));
|
2013-06-28 02:04:52 +02:00
|
|
|
|
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2011-10-26 19:15:47 +02:00
|
|
|
|
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2013-04-16 06:52:41 +02:00
|
|
|
|
Subject.Route(ApplicationModes.UninstallService);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2011-10-26 19:15:47 +02:00
|
|
|
|
serviceProviderMock.Verify(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
2011-10-14 03:22:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Route_should_call_console_service_when_application_mode_is_console()
|
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2013-04-16 06:52:41 +02:00
|
|
|
|
Mocker.GetMock<IConsoleService>().SetupGet(c => c.IsConsoleApplication).Returns(true);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2013-04-16 06:52:41 +02:00
|
|
|
|
Subject.Route(ApplicationModes.Console);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2013-04-16 06:52:41 +02:00
|
|
|
|
Mocker.GetMock<IConsoleService>().Verify(c => c.WaitForClose(), Times.Once());
|
|
|
|
|
Mocker.GetMock<INzbDroneServiceFactory>().Verify(c => c.Start(), Times.Once());
|
2011-10-14 03:22:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-01 01:50:50 +01: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 03:22:51 +02:00
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
var envMock = Mocker.GetMock<IRuntimeInfo>();
|
2013-05-11 01:53:50 +02:00
|
|
|
|
var serviceProvider = Mocker.GetMock<IServiceProvider>();
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2011-10-15 02:41:09 +02:00
|
|
|
|
envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
|
|
|
|
|
|
|
|
|
|
serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>()));
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2013-04-16 06:52:41 +02:00
|
|
|
|
Subject.Route(applicationModes);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2011-10-15 02:41:09 +02:00
|
|
|
|
serviceProvider.Verify(c => c.Run(It.IsAny<ServiceBase>()), Times.Once());
|
2011-10-14 03:22:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void show_error_on_install_if_service_already_exist()
|
|
|
|
|
{
|
2013-04-16 06:52:41 +02:00
|
|
|
|
var consoleMock = Mocker.GetMock<IConsoleService>();
|
2013-05-11 01:53:50 +02:00
|
|
|
|
var serviceMock = Mocker.GetMock<IServiceProvider>();
|
2013-06-28 02:04:52 +02:00
|
|
|
|
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
|
|
|
|
consoleMock.Setup(c => c.PrintServiceAlreadyExist());
|
2011-10-26 19:15:47 +02:00
|
|
|
|
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2013-04-16 06:52:41 +02:00
|
|
|
|
Subject.Route(ApplicationModes.InstallService);
|
2011-10-14 03:22:51 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-14 03:22:51 +02:00
|
|
|
|
}
|
2011-10-15 02:41:09 +02:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void show_error_on_uninstall_if_service_doesnt_exist()
|
|
|
|
|
{
|
2013-04-16 06:52:41 +02:00
|
|
|
|
var consoleMock = Mocker.GetMock<IConsoleService>();
|
2013-05-11 01:53:50 +02:00
|
|
|
|
var serviceMock = Mocker.GetMock<IServiceProvider>();
|
2013-06-28 02:04:52 +02:00
|
|
|
|
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
2011-10-15 02:41:09 +02:00
|
|
|
|
|
2013-07-09 02:47:09 +02:00
|
|
|
|
consoleMock.Setup(c => c.PrintServiceDoesNotExist());
|
2011-10-26 19:15:47 +02:00
|
|
|
|
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
|
2011-10-15 02:41:09 +02:00
|
|
|
|
|
2013-04-16 06:52:41 +02:00
|
|
|
|
Subject.Route(ApplicationModes.UninstallService);
|
2011-10-15 02:41:09 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-10-15 02:41:09 +02:00
|
|
|
|
}
|
2011-10-14 03:22:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|