2013-04-30 05:09:50 +02:00
|
|
|
|
using System.ServiceProcess;
|
2011-10-23 19:32:57 +02:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2011-11-13 19:16:31 +01:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-10-23 19:32:57 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Common.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-04-30 05:09:50 +02:00
|
|
|
|
public class ServiceProviderTests : TestBase<ServiceProvider>
|
2011-10-23 19:32:57 +02:00
|
|
|
|
{
|
|
|
|
|
private const string ALWAYS_INSTALLED_SERVICE = "SCardSvr"; //Smart Card
|
2011-11-15 03:38:15 +01:00
|
|
|
|
private const string TEMP_SERVICE_NAME = "NzbDrone_Nunit";
|
2011-10-23 19:32:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2013-04-30 05:09:50 +02:00
|
|
|
|
WindowsOnly();
|
2013-02-18 05:13:23 +01:00
|
|
|
|
|
2011-10-26 19:15:47 +02:00
|
|
|
|
|
2013-04-30 05:09:50 +02:00
|
|
|
|
if (Subject.ServiceExist(TEMP_SERVICE_NAME))
|
2011-10-26 19:15:47 +02:00
|
|
|
|
{
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.UnInstall(TEMP_SERVICE_NAME);
|
2011-10-26 19:15:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown()
|
|
|
|
|
{
|
2013-04-30 06:14:53 +02:00
|
|
|
|
WindowsOnly();
|
|
|
|
|
|
2013-04-30 05:09:50 +02:00
|
|
|
|
if (Subject.ServiceExist(TEMP_SERVICE_NAME))
|
2011-10-26 19:15:47 +02:00
|
|
|
|
{
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.UnInstall(TEMP_SERVICE_NAME);
|
2011-10-26 19:15:47 +02:00
|
|
|
|
}
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Exists_should_find_existing_service()
|
|
|
|
|
{
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.ServiceExist(ALWAYS_INSTALLED_SERVICE).Should().BeTrue();
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Exists_should_not_find_random_service()
|
|
|
|
|
{
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.ServiceExist("random_service_name").Should().BeFalse();
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Service_should_be_installed_and_then_uninstalled()
|
|
|
|
|
{
|
2013-04-30 05:09:50 +02:00
|
|
|
|
|
|
|
|
|
Subject.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse("Service already installed");
|
|
|
|
|
Subject.Install(TEMP_SERVICE_NAME);
|
|
|
|
|
Subject.ServiceExist(TEMP_SERVICE_NAME).Should().BeTrue();
|
|
|
|
|
Subject.UnInstall(TEMP_SERVICE_NAME);
|
|
|
|
|
Subject.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse();
|
2012-01-17 08:12:22 +01:00
|
|
|
|
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Explicit]
|
|
|
|
|
public void UnInstallService()
|
|
|
|
|
{
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
|
|
|
|
Subject.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME).Should().BeFalse();
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Should_be_able_to_start_and_stop_service()
|
|
|
|
|
{
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
2011-10-23 19:32:57 +02:00
|
|
|
|
.Should().NotBe(ServiceControllerStatus.Running);
|
|
|
|
|
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.Start(ALWAYS_INSTALLED_SERVICE);
|
2011-10-23 19:32:57 +02:00
|
|
|
|
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
2011-10-23 19:32:57 +02:00
|
|
|
|
.Should().Be(ServiceControllerStatus.Running);
|
|
|
|
|
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
|
2011-10-23 19:32:57 +02:00
|
|
|
|
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
2011-10-23 19:32:57 +02:00
|
|
|
|
.Should().Be(ServiceControllerStatus.Stopped);
|
|
|
|
|
}
|
2011-11-15 03:38:15 +01:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Should_log_warn_if_on_stop_if_service_is_already_stopped()
|
|
|
|
|
{
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
2011-11-15 03:38:15 +01:00
|
|
|
|
.Should().NotBe(ServiceControllerStatus.Running);
|
|
|
|
|
|
|
|
|
|
|
2013-04-30 05:09:50 +02:00
|
|
|
|
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
2011-11-15 03:38:15 +01:00
|
|
|
|
.Should().Be(ServiceControllerStatus.Stopped);
|
|
|
|
|
|
2011-12-20 01:58:26 +01:00
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-11-15 03:38:15 +01:00
|
|
|
|
}
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
}
|