fixed more linux tests
This commit is contained in:
parent
422b82f220
commit
2fab944fd4
|
@ -1,6 +1,4 @@
|
||||||
|
using System.ServiceProcess;
|
||||||
|
|
||||||
using System.ServiceProcess;
|
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
@ -8,66 +6,55 @@ using NzbDrone.Test.Common;
|
||||||
namespace NzbDrone.Common.Test
|
namespace NzbDrone.Common.Test
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ServiceProviderTests : TestBase
|
public class ServiceProviderTests : TestBase<ServiceProvider>
|
||||||
{
|
{
|
||||||
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";
|
private const string TEMP_SERVICE_NAME = "NzbDrone_Nunit";
|
||||||
private ServiceProvider serviceProvider;
|
|
||||||
|
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
if(EnvironmentProvider.IsLinux)
|
WindowsOnly();
|
||||||
{
|
|
||||||
throw new IgnoreException("Windows services aren't available in none-windows environments.");
|
|
||||||
}
|
|
||||||
|
|
||||||
serviceProvider = new ServiceProvider();
|
|
||||||
|
|
||||||
if (serviceProvider.ServiceExist(TEMP_SERVICE_NAME))
|
if (Subject.ServiceExist(TEMP_SERVICE_NAME))
|
||||||
{
|
{
|
||||||
serviceProvider.UnInstall(TEMP_SERVICE_NAME);
|
Subject.UnInstall(TEMP_SERVICE_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
public void TearDown()
|
public void TearDown()
|
||||||
{
|
{
|
||||||
if (serviceProvider.ServiceExist(TEMP_SERVICE_NAME))
|
if (Subject.ServiceExist(TEMP_SERVICE_NAME))
|
||||||
{
|
{
|
||||||
serviceProvider.UnInstall(TEMP_SERVICE_NAME);
|
Subject.UnInstall(TEMP_SERVICE_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Exists_should_find_existing_service()
|
public void Exists_should_find_existing_service()
|
||||||
{
|
{
|
||||||
|
Subject.ServiceExist(ALWAYS_INSTALLED_SERVICE).Should().BeTrue();
|
||||||
var exists = serviceProvider.ServiceExist(ALWAYS_INSTALLED_SERVICE);
|
|
||||||
|
|
||||||
exists.Should().BeTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Exists_should_not_find_random_service()
|
public void Exists_should_not_find_random_service()
|
||||||
{
|
{
|
||||||
|
Subject.ServiceExist("random_service_name").Should().BeFalse();
|
||||||
var exists = serviceProvider.ServiceExist("random_service_name");
|
|
||||||
|
|
||||||
exists.Should().BeFalse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Service_should_be_installed_and_then_uninstalled()
|
public void Service_should_be_installed_and_then_uninstalled()
|
||||||
{
|
{
|
||||||
|
|
||||||
serviceProvider.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse("Service already installed");
|
Subject.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse("Service already installed");
|
||||||
serviceProvider.Install(TEMP_SERVICE_NAME);
|
Subject.Install(TEMP_SERVICE_NAME);
|
||||||
serviceProvider.ServiceExist(TEMP_SERVICE_NAME).Should().BeTrue();
|
Subject.ServiceExist(TEMP_SERVICE_NAME).Should().BeTrue();
|
||||||
serviceProvider.UnInstall(TEMP_SERVICE_NAME);
|
Subject.UnInstall(TEMP_SERVICE_NAME);
|
||||||
serviceProvider.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse();
|
Subject.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse();
|
||||||
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
ExceptionVerification.ExpectedWarns(1);
|
||||||
}
|
}
|
||||||
|
@ -76,40 +63,38 @@ namespace NzbDrone.Common.Test
|
||||||
[Explicit]
|
[Explicit]
|
||||||
public void UnInstallService()
|
public void UnInstallService()
|
||||||
{
|
{
|
||||||
|
Subject.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
||||||
serviceProvider.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
Subject.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME).Should().BeFalse();
|
||||||
serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME).Should().BeFalse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
//[Timeout(10000)]
|
|
||||||
public void Should_be_able_to_start_and_stop_service()
|
public void Should_be_able_to_start_and_stop_service()
|
||||||
{
|
{
|
||||||
serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||||
.Should().NotBe(ServiceControllerStatus.Running);
|
.Should().NotBe(ServiceControllerStatus.Running);
|
||||||
|
|
||||||
serviceProvider.Start(ALWAYS_INSTALLED_SERVICE);
|
Subject.Start(ALWAYS_INSTALLED_SERVICE);
|
||||||
|
|
||||||
serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||||
.Should().Be(ServiceControllerStatus.Running);
|
.Should().Be(ServiceControllerStatus.Running);
|
||||||
|
|
||||||
serviceProvider.Stop(ALWAYS_INSTALLED_SERVICE);
|
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
|
||||||
|
|
||||||
serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||||
.Should().Be(ServiceControllerStatus.Stopped);
|
.Should().Be(ServiceControllerStatus.Stopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Should_log_warn_if_on_stop_if_service_is_already_stopped()
|
public void Should_log_warn_if_on_stop_if_service_is_already_stopped()
|
||||||
{
|
{
|
||||||
serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||||
.Should().NotBe(ServiceControllerStatus.Running);
|
.Should().NotBe(ServiceControllerStatus.Running);
|
||||||
|
|
||||||
|
|
||||||
serviceProvider.Stop(ALWAYS_INSTALLED_SERVICE);
|
|
||||||
|
|
||||||
|
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
|
||||||
serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
|
||||||
|
|
||||||
|
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||||
.Should().Be(ServiceControllerStatus.Stopped);
|
.Should().Be(ServiceControllerStatus.Stopped);
|
||||||
|
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
ExceptionVerification.ExpectedWarns(1);
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace NzbDrone.Common
|
||||||
return info.FullName.TrimEnd('/', '\\', ' ');
|
return info.FullName.TrimEnd('/', '\\', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
return info.FullName.Trim('/', '\\', ' ');
|
return info.FullName.TrimEnd('/').Trim('\\', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GetProperDirectoryCapitalization(DirectoryInfo dirInfo)
|
static string GetProperDirectoryCapitalization(DirectoryInfo dirInfo)
|
||||||
|
|
Loading…
Reference in New Issue