mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
Moved tests for NzbDrone.Common to its own test project. added some new tests.
This commit is contained in:
parent
f52620db70
commit
f9a316f632
12 changed files with 350 additions and 35 deletions
77
NzbDrone.Common.Test/ProcessProviderTests.cs
Normal file
77
NzbDrone.Common.Test/ProcessProviderTests.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProcessProviderTests
|
||||
{
|
||||
private const string DummyProccessName = "NzbDrone.Test.Dummy";
|
||||
ProcessProvider _processProvider;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Process.GetProcessesByName(DummyProccessName).ToList().ForEach(c => c.Kill());
|
||||
_processProvider = new ProcessProvider();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Process.GetProcessesByName(DummyProccessName).ToList().ForEach(c => c.Kill());
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
|
||||
[TestCase(0)]
|
||||
[TestCase(-1)]
|
||||
[TestCase(9999)]
|
||||
public void GetProcessById_should_return_null_for_invalid_process(int processId)
|
||||
{
|
||||
_processProvider.GetProcessById(processId).Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Should_be_able_to_kill_procces()
|
||||
{
|
||||
var dummyProcess = StartDummyProcess();
|
||||
_processProvider.Kill(dummyProcess.Id);
|
||||
dummyProcess.HasExited.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Should_be_able_to_start_process()
|
||||
{
|
||||
var startInfo = new ProcessStartInfo(DummyProccessName + ".exe");
|
||||
|
||||
//Act/Assert
|
||||
_processProvider.GetProcessByName(DummyProccessName).Should()
|
||||
.BeEmpty("Dummy process is already running");
|
||||
_processProvider.Start(startInfo).Should().NotBeNull();
|
||||
|
||||
_processProvider.GetProcessByName(DummyProccessName).Should()
|
||||
.HaveCount(1, "excepted one dummy process to be already running");
|
||||
}
|
||||
|
||||
public Process StartDummyProcess()
|
||||
{
|
||||
var startInfo = new ProcessStartInfo(DummyProccessName + ".exe");
|
||||
return _processProvider.Start(startInfo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue