1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 07:52:37 +01:00
Sonarr/NzbDrone.Common.Test/ProcessProviderTests.cs

97 lines
2.8 KiB
C#
Raw Normal View History

2013-03-28 23:07:09 +01:00

using System;
using System.ComponentModel;
2011-10-23 20:31:17 +02:00
using System.Diagnostics;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Model;
2011-11-13 19:16:31 +01:00
using NzbDrone.Test.Common;
using NzbDrone.Test.Dummy;
namespace NzbDrone.Common.Test
{
[TestFixture]
2011-11-13 19:16:31 +01:00
public class ProcessProviderTests : TestBase
{
ProcessProvider _processProvider;
[SetUp]
public void Setup()
{
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill());
_processProvider = new ProcessProvider();
}
[TearDown]
public void TearDown()
{
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill());
}
[TestCase(0)]
[TestCase(123332324)]
public void Kill_should_not_fail_on_invalid_process_is(int processId)
{
_processProvider.Kill(processId);
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void GetById_should_return_null_if_process_doesnt_exist()
{
_processProvider.GetProcessById(1234567).Should().BeNull();
ExceptionVerification.ExpectedWarns(1);
}
[TestCase(0)]
[TestCase(-1)]
[TestCase(9999)]
public void GetProcessById_should_return_null_for_invalid_process(int processId)
{
_processProvider.GetProcessById(processId).Should().BeNull();
ExceptionVerification.ExpectedWarns(1);
}
[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(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
2013-03-28 23:07:09 +01:00
_processProvider.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should()
.BeEmpty("Dummy process is already running");
_processProvider.Start(startInfo).Should().NotBeNull();
_processProvider.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should()
.HaveCount(1, "excepted one dummy process to be already running");
}
public Process StartDummyProcess()
{
var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
return _processProvider.Start(startInfo);
}
[Test]
public void ToString_on_new_processInfo()
{
Console.WriteLine(new ProcessInfo().ToString());
ExceptionVerification.MarkInconclusive(typeof(Win32Exception));
}
}
}