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

This commit is contained in:
Mark McDowall 2011-10-26 22:47:09 -07:00
commit f5b5aea62d
12 changed files with 57 additions and 160 deletions

View File

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

View File

@ -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");
}
}
}

View File

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

View File

@ -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();
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -44,9 +44,9 @@ namespace NzbDrone.Update.Providers
public void Start(string installationFolder) public void Start(string installationFolder)
{ {
Logger.Info("Stopping all running services"); 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"); Logger.Info("Killing all running processes");

View File

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

View File

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

View File

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