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