Lidarr/src/NzbDrone.Host.Test/RouterTest.cs

77 lines
3.0 KiB
C#
Raw Permalink Normal View History

using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes;
using NzbDrone.Host;
2011-11-13 18:16:31 +00:00
using NzbDrone.Test.Common;
namespace NzbDrone.App.Test
{
[TestFixture]
public class RouterTest : TestBase<UtilityModeRouter>
{
2013-07-27 01:25:45 +00:00
[SetUp]
public void Setup()
{
WindowsOnly();
}
[Test]
public void Route_should_call_install_service_when_application_mode_is_install()
{
2013-05-10 23:53:50 +00:00
var serviceProviderMock = Mocker.GetMock<IServiceProvider>(MockBehavior.Strict);
2017-09-27 02:06:05 +00:00
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.SERVICE_NAME)).Returns(false);
serviceProviderMock.Setup(c => c.Install(ServiceProvider.SERVICE_NAME));
serviceProviderMock.Setup(c => c.SetPermissions(ServiceProvider.SERVICE_NAME));
Mocker.GetMock<IProcessProvider>()
.Setup(c => c.SpawnNewProcess("sc.exe", It.IsAny<string>(), null, true));
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
2013-04-16 04:52:41 +00:00
Subject.Route(ApplicationModes.InstallService);
2017-09-27 02:06:05 +00:00
serviceProviderMock.Verify(c => c.Install(ServiceProvider.SERVICE_NAME), Times.Once());
}
[Test]
public void Route_should_call_uninstall_service_when_application_mode_is_uninstall()
{
2013-05-10 23:53:50 +00:00
var serviceProviderMock = Mocker.GetMock<IServiceProvider>();
serviceProviderMock.Setup(c => c.Uninstall(ServiceProvider.SERVICE_NAME));
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
2017-09-27 02:06:05 +00:00
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.SERVICE_NAME)).Returns(true);
2013-04-16 04:52:41 +00:00
Subject.Route(ApplicationModes.UninstallService);
serviceProviderMock.Verify(c => c.Uninstall(ServiceProvider.SERVICE_NAME), Times.Once());
}
[Test]
public void show_error_on_install_if_service_already_exist()
{
2013-04-16 04:52:41 +00:00
var consoleMock = Mocker.GetMock<IConsoleService>();
2013-05-10 23:53:50 +00:00
var serviceMock = Mocker.GetMock<IServiceProvider>();
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceAlreadyExist());
2017-09-27 02:06:05 +00:00
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.SERVICE_NAME)).Returns(true);
2013-04-16 04:52:41 +00:00
Subject.Route(ApplicationModes.InstallService);
}
[Test]
public void show_error_on_uninstall_if_service_doesnt_exist()
{
2013-04-16 04:52:41 +00:00
var consoleMock = Mocker.GetMock<IConsoleService>();
2013-05-10 23:53:50 +00:00
var serviceMock = Mocker.GetMock<IServiceProvider>();
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceDoesNotExist());
2017-09-27 02:06:05 +00:00
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.SERVICE_NAME)).Returns(false);
2013-04-16 04:52:41 +00:00
Subject.Route(ApplicationModes.UninstallService);
}
}
}