Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus

pull/7/merge
Mark McDowall 13 years ago
commit f5b5aea62d

@ -69,8 +69,6 @@
<Compile Include="MonitoringProviderTest.cs" />
<Compile Include="ConfigProviderTest.cs" />
<Compile Include="IISProviderTest.cs" />
<Compile Include="ProcessProviderTests.cs" />
<Compile Include="ServiceControllerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

@ -1,57 +0,0 @@
using System.Diagnostics;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common;
namespace NzbDrone.App.Test
{
[TestFixture]
public class ProcessProviderTests
{
ProcessProvider _processProvider;
[SetUp]
public void Setup()
{
_processProvider = new ProcessProvider();
}
[TestCase(0)]
[TestCase(123332324)]
public void Kill_should_not_fail_on_invalid_process_is(int processId)
{
_processProvider.Kill(processId);
}
[Test]
public void GetById_should_return_null_if_process_doesnt_exist()
{
_processProvider.GetProcessById(1234567).Should().BeNull();
}
[Test]
public void Should_be_able_to_kill_procces()
{
var dummyProcess = StartDummyProcess();
_processProvider.Kill(dummyProcess.Id);
dummyProcess.HasExited.Should().BeTrue();
}
[TestCase(0)]
[TestCase(-1)]
[TestCase(9999)]
public void GetProcessById_should_return_null_for_invalid_process(int processId)
{
_processProvider.GetProcessById(processId).Should().BeNull();
}
public Process StartDummyProcess()
{
return Process.Start("NzbDrone.Test.Dummy.exe");
}
}
}

@ -47,13 +47,13 @@ namespace NzbDrone.App.Test
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var serviceProviderMock = mocker.GetMock<ServiceProvider>();
serviceProviderMock.Setup(c => c.Install());
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NzbDroneServiceName)).Returns(false);
serviceProviderMock.Setup(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME));
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.InstallService);
serviceProviderMock.Verify(c => c.Install(), Times.Once());
serviceProviderMock.Verify(c => c.Install(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
}
@ -62,13 +62,13 @@ namespace NzbDrone.App.Test
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var serviceProviderMock = mocker.GetMock<ServiceProvider>();
serviceProviderMock.Setup(c => c.UnInstall());
serviceProviderMock.Setup(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME));
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NzbDroneServiceName)).Returns(true);
serviceProviderMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.UninstallService);
serviceProviderMock.Verify(c => c.UnInstall(), Times.Once());
serviceProviderMock.Verify(c => c.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
}
[Test]
@ -116,7 +116,7 @@ namespace NzbDrone.App.Test
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceAlreadyExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NzbDroneServiceName)).Returns(true);
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(true);
mocker.Resolve<Router>().Route(ApplicationMode.InstallService);
@ -132,7 +132,7 @@ namespace NzbDrone.App.Test
mocker.GetMock<EnviromentProvider>().SetupGet(c => c.IsUserInteractive).Returns(true);
consoleMock.Setup(c => c.PrintServiceDoestExist());
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NzbDroneServiceName)).Returns(false);
serviceMock.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)).Returns(false);
mocker.Resolve<Router>().Route(ApplicationMode.UninstallService);

@ -1,62 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Providers;
namespace NzbDrone.App.Test
{
[TestFixture]
public class ServiceControllerTests
{
[Test]
public void Exists_should_find_spooler_service()
{
var serviceController = new ServiceProvider();
//Act
var exists = serviceController.ServiceExist("spooler");
exists.Should().BeTrue();
}
[Test]
public void Exists_should_not_find_random_service()
{
var serviceController = new ServiceProvider();
//Act
var exists = serviceController.ServiceExist("random_service_name");
exists.Should().BeFalse();
}
[Test]
public void Service_should_be_installed_and_then_uninstalled()
{
var serviceController = new ServiceProvider();
//Act
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse("Service already installed");
serviceController.Install();
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeTrue();
serviceController.UnInstall();
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse();
}
[Test]
[Explicit]
public void UnInstallService()
{
var serviceController = new ServiceProvider();
//Act
serviceController.UnInstall();
serviceController.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse();
}
}
}

@ -10,6 +10,7 @@ namespace NzbDrone.Common.Test
public class ServiceControllerTests
{
private const string ALWAYS_INSTALLED_SERVICE = "SCardSvr"; //Smart Card
private const string TEMP_SERVICE_NAME = "NzbDrone_Nunit"; //Smart Card
private ServiceProvider serviceProvider;
@ -17,6 +18,20 @@ namespace NzbDrone.Common.Test
public void Setup()
{
serviceProvider = new ServiceProvider();
if (serviceProvider.ServiceExist(TEMP_SERVICE_NAME))
{
serviceProvider.UnInstall(TEMP_SERVICE_NAME);
}
}
[TearDown]
public void TearDown()
{
if (serviceProvider.ServiceExist(TEMP_SERVICE_NAME))
{
serviceProvider.UnInstall(TEMP_SERVICE_NAME);
}
}
[Test]
@ -42,11 +57,11 @@ namespace NzbDrone.Common.Test
public void Service_should_be_installed_and_then_uninstalled()
{
//Act
serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse("Service already installed");
serviceProvider.Install();
serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeTrue();
serviceProvider.UnInstall();
serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse();
serviceProvider.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse("Service already installed");
serviceProvider.Install(TEMP_SERVICE_NAME);
serviceProvider.ServiceExist(TEMP_SERVICE_NAME).Should().BeTrue();
serviceProvider.UnInstall(TEMP_SERVICE_NAME);
serviceProvider.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse();
}
[Test]
@ -54,8 +69,8 @@ namespace NzbDrone.Common.Test
public void UnInstallService()
{
//Act
serviceProvider.UnInstall();
serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse();
serviceProvider.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME).Should().BeFalse();
}
[Test]

@ -18,19 +18,19 @@ namespace NzbDrone.Common
Console.WriteLine();
Console.WriteLine(" Usage: {0} <command> ", Process.GetCurrentProcess().MainModule.ModuleName);
Console.WriteLine(" Commands:");
Console.WriteLine(" /i Install the application as a Windows Service ({0}).", ServiceProvider.NzbDroneServiceName);
Console.WriteLine(" /u Uninstall already installed Windows Service ({0}).", ServiceProvider.NzbDroneServiceName);
Console.WriteLine(" /i Install the application as a Windows Service ({0}).", ServiceProvider.NZBDRONE_SERVICE_NAME);
Console.WriteLine(" /u Uninstall already installed Windows Service ({0}).", ServiceProvider.NZBDRONE_SERVICE_NAME);
Console.WriteLine(" <No Arguments> Run application in console mode.");
}
public virtual void PrintServiceAlreadyExist()
{
Console.WriteLine("A service with the same name ({0}) already exists. Aborting installation", ServiceProvider.NzbDroneServiceName);
Console.WriteLine("A service with the same name ({0}) already exists. Aborting installation", ServiceProvider.NZBDRONE_SERVICE_NAME);
}
public virtual void PrintServiceDoestExist()
{
Console.WriteLine("Can't find service ({0})", ServiceProvider.NzbDroneServiceName);
Console.WriteLine("Can't find service ({0})", ServiceProvider.NZBDRONE_SERVICE_NAME);
}
}
}

@ -10,7 +10,7 @@ namespace NzbDrone.Common
{
public class ServiceProvider
{
public const string NzbDroneServiceName = "NzbDrone";
public const string NZBDRONE_SERVICE_NAME = "NzbDrone";
private static readonly Logger Logger = LogManager.GetLogger("Host.ServiceManager");
@ -23,9 +23,9 @@ namespace NzbDrone.Common
}
public virtual void Install()
public virtual void Install(string serviceName)
{
Logger.Info("Installing service '{0}'", NzbDroneServiceName);
Logger.Info("Installing service '{0}'", serviceName);
var installer = new ServiceProcessInstaller
@ -40,8 +40,8 @@ namespace NzbDrone.Common
var context = new InstallContext("service_install.log", cmdline);
serviceInstaller.Context = context;
serviceInstaller.DisplayName = NzbDroneServiceName;
serviceInstaller.ServiceName = NzbDroneServiceName;
serviceInstaller.DisplayName = serviceName;
serviceInstaller.ServiceName = serviceName;
serviceInstaller.Description = "NzbDrone Application Server";
serviceInstaller.StartType = ServiceStartMode.Automatic;
@ -52,17 +52,17 @@ namespace NzbDrone.Common
Logger.Info("Service Has installed successfully.");
}
public virtual void UnInstall()
public virtual void UnInstall(string serviceName)
{
Logger.Info("Uninstalling NzbDrone service");
Logger.Info("Uninstalling {0} service", serviceName);
var serviceInstaller = new ServiceInstaller();
var context = new InstallContext("service_uninstall.log", null);
serviceInstaller.Context = context;
serviceInstaller.ServiceName = NzbDroneServiceName;
serviceInstaller.ServiceName = serviceName;
serviceInstaller.Uninstall(null);
Logger.Info("NzbDrone successfully uninstalled");
Logger.Info("{0} successfully uninstalled", serviceName);
}

@ -23,14 +23,14 @@ namespace NzbDrone.Update.Test
public void should_stop_nzbdrone_service_if_installed()
{
mocker.GetMock<ServiceProvider>()
.Setup(c => c.ServiceExist(ServiceProvider.NzbDroneServiceName))
.Setup(c => c.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
.Returns(true);
//Act
mocker.Resolve<UpdateProvider>().Start(null);
//Assert
mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(ServiceProvider.NzbDroneServiceName), Times.Once());
mocker.GetMock<ServiceProvider>().Verify(c => c.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
mocker.VerifyAllMocks();
}

@ -44,9 +44,9 @@ namespace NzbDrone.Update.Providers
public void Start(string installationFolder)
{
Logger.Info("Stopping all running services");
if (_serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName))
if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
{
_serviceProvider.Stop(ServiceProvider.NzbDroneServiceName);
_serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
}
Logger.Info("Killing all running processes");

@ -15,7 +15,7 @@
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<compilation debug="false" xdt:Transform="Replace" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.

@ -50,25 +50,25 @@ namespace NzbDrone
}
case ApplicationMode.InstallService:
{
if (_serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName))
if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
{
_consoleProvider.PrintServiceAlreadyExist();
}
else
{
_serviceProvider.Install();
_serviceProvider.Install(ServiceProvider.NZBDRONE_SERVICE_NAME);
}
break;
}
case ApplicationMode.UninstallService:
{
if (!_serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName))
if (!_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
{
_consoleProvider.PrintServiceDoestExist();
}
else
{
_serviceProvider.UnInstall();
_serviceProvider.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
}
break;

@ -1,11 +1,14 @@
SET PACKAGEROOT=_rawPackage
SET TARGET=%PACKAGEROOT%\NzbDrone
rd %TARGET% /S /Q
del nzbdrone*.zip /Q /F
xcopy IISExpress %TARGET%\IISExpress /E /V /I /Y
xcopy NzbDrone\bin\Release\*.* %TARGET%\ /E /V /I /Y
del %TARGET%\nlog.xml
del %TARGET%\*.vshost.exe.*
del %TARGET%\nlog.xml /Q /F
del %TARGET%\*.vshost.exe.* /Q /F
xcopy NzbDrone.Web\bin\*.* %TARGET%\NzbDrone.Web\bin\ /E /V /I /Y
xcopy NzbDrone.Web\App_GlobalResources\*.* %TARGET%\NzbDrone.Web\App_GlobalResources\ /E /V /I /Y

Loading…
Cancel
Save