You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Radarr/src/NzbDrone.Common.Test/ServiceProviderTests.cs

133 lines
3.7 KiB

using System;
using System.ServiceProcess;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.Categories;
namespace NzbDrone.Common.Test
{
[TestFixture]
[Timeout(15000)]
public class ServiceProviderTests : TestBase<ServiceProvider>
{
private const string ALWAYS_INSTALLED_SERVICE = "SCardSvr"; //Smart Card
private const string TEMP_SERVICE_NAME = "NzbDrone_Nunit";
[SetUp]
public void Setup()
{
WindowsOnly();
CleanupService();
}
[TearDown]
public void TearDown()
{
if (OsInfo.IsWindows)
{
CleanupService();
}
}
private void CleanupService()
{
if (Subject.ServiceExist(TEMP_SERVICE_NAME))
{
Subject.UnInstall(TEMP_SERVICE_NAME);
}
if (Subject.IsServiceRunning(ALWAYS_INSTALLED_SERVICE))
{
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
}
}
[Test]
public void Exists_should_find_existing_service()
{
Subject.ServiceExist(ALWAYS_INSTALLED_SERVICE).Should().BeTrue();
}
[Test]
public void Exists_should_not_find_random_service()
{
Subject.ServiceExist("random_service_name").Should().BeFalse();
}
[Test]
public void Service_should_be_installed_and_then_uninstalled()
{
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();
ExceptionVerification.ExpectedWarns(1);
}
[Test]
[Explicit]
[ManualTest]
public void UnInstallService()
{
Subject.UnInstall(ServiceProvider.SERVICE_NAME);
Subject.ServiceExist(ServiceProvider.SERVICE_NAME).Should().BeFalse();
}
[Test]
[Explicit]
[ManualTest]
public void Should_be_able_to_start_and_stop_service()
{
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
.Should().NotBe(ServiceControllerStatus.Running);
Subject.Start(ALWAYS_INSTALLED_SERVICE);
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
.Should().Be(ServiceControllerStatus.Running);
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
.Should().Be(ServiceControllerStatus.Stopped);
}
[Test]
Fixed all tests and even added some new ones :) (#835) * First fixing of tests. * Updated more tests. * Fix some tests * Fix all prioritization tests. And add new for preferred words. * Updated CompletedDownloadservice tests * Fixed a lot of tests * Fixed all indexer requests. We should add more for the indexers we added. To lazy for that though ¯\_(ツ)_/¯ * Fixed organizer tests. Should probably be also updated to incorporate our newly added tags. * Fix notification tests. * Fixed update test for osx * Fixed a few more tests. * Fixed some more tests. * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update appveyor.yml * Update activity.less * Update appveyor.yml * Update appveyor.yml * Update CommonVersionInfo.cs * Update build-appveyor.cake Let's hope this works. * Update CommonVersionInfo.cs Just to kickstart appveyor * Fixed a few tests * Just ignore those tests. * Fixed more tests. * First steps in fixing Core.Test.Download.DownloadApprovedFixture * Fix most DownloadApprovedFixture tests * Fixed something. * Fixed a few more tests. * Fixed pending release tests. * All Core tests are now fixed. * Fixed the last tests :) * Fixed Download Station Tests. * Fixed Vuze and Transmission default settings which caused the tests to fail. * Fix most tests. * Fix RootFolder tests. * Fixed last tests
7 years ago
[Ignore("Shit appveyor")]
public void should_throw_if_starting_a_running_serivce()
{
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
.Should().NotBe(ServiceControllerStatus.Running);
Subject.Start(ALWAYS_INSTALLED_SERVICE);
Assert.Throws<InvalidOperationException>(() => Subject.Start(ALWAYS_INSTALLED_SERVICE));
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void Should_log_warn_if_on_stop_if_service_is_already_stopped()
{
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
.Should().NotBe(ServiceControllerStatus.Running);
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
.Should().Be(ServiceControllerStatus.Stopped);
ExceptionVerification.ExpectedWarns(1);
}
}
}