1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00
Radarr/NzbDrone.App.Test/RouterTest.cs

106 lines
4.0 KiB
C#
Raw Normal View History

2013-03-01 01:50:50 +01:00
using System.ServiceProcess;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Host;
2011-11-13 19:16:31 +01:00
using NzbDrone.Test.Common;
namespace NzbDrone.App.Test
{
[TestFixture]
2013-04-16 06:52:41 +02:00
public class RouterTest : TestBase<Router>
{
2013-07-27 03:25:45 +02:00
[SetUp]
public void Setup()
{
WindowsOnly();
}
[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);
serviceProviderMock.Setup(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME));
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
serviceProviderMock.Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME));
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
2013-04-16 06:52:41 +02:00
Subject.Route(ApplicationModes.InstallService);
serviceProviderMock.Verify(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
}
2013-04-16 06:52:41 +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>();
serviceProviderMock.Setup(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME));
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
2013-04-16 06:52:41 +02:00
Subject.Route(ApplicationModes.UninstallService);
serviceProviderMock.Verify(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
}
[Test]
public void Route_should_call_console_service_when_application_mode_is_console()
{
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
Subject.Route(ApplicationModes.Interactive);
2013-04-16 06:52:41 +02:00
Mocker.GetMock<INzbDroneServiceFactory>().Verify(c => c.Start(), Times.Once());
}
2013-08-14 06:02:56 +02:00
[Test]
public void Route_should_call_service_start_when_run_in_service_mode()
{
var envMock = Mocker.GetMock<IRuntimeInfo>();
2013-05-11 01:53:50 +02:00
var serviceProvider = Mocker.GetMock<IServiceProvider>();
envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>()));
serviceProvider.Setup(c => c.ServiceExist(It.IsAny<string>())).Returns(true);
2013-08-14 06:02:56 +02:00
serviceProvider.Setup(c => c.GetStatus(It.IsAny<string>())).Returns(ServiceControllerStatus.StartPending);
2013-08-14 06:02:56 +02:00
Subject.Route();
serviceProvider.Verify(c => c.Run(It.IsAny<ServiceBase>()), Times.Once());
}
[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>();
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceAlreadyExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
2013-04-16 06:52:41 +02:00
Subject.Route(ApplicationModes.InstallService);
}
[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>();
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceDoesNotExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
2013-04-16 06:52:41 +02:00
Subject.Route(ApplicationModes.UninstallService);
}
}
}