2013-05-03 06:37:08 +02:00
|
|
|
|
using System;
|
2012-12-21 02:49:57 +01:00
|
|
|
|
using System.ComponentModel;
|
2011-10-23 20:31:17 +02:00
|
|
|
|
using System.Diagnostics;
|
2013-08-06 04:42:22 +02:00
|
|
|
|
using System.IO;
|
2011-10-23 19:32:57 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2011-12-12 07:52:58 +01:00
|
|
|
|
using NzbDrone.Common.Model;
|
2011-11-13 19:16:31 +01:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-11-14 04:37:36 +01:00
|
|
|
|
using NzbDrone.Test.Dummy;
|
2011-10-23 19:32:57 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Common.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-05-07 07:38:40 +02:00
|
|
|
|
public class ProcessProviderTests : TestBase<ProcessProvider>
|
2011-10-23 19:32:57 +02:00
|
|
|
|
{
|
2011-11-14 04:37:36 +01:00
|
|
|
|
|
2011-10-23 19:32:57 +02:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2013-08-13 16:39:00 +02:00
|
|
|
|
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c =>
|
|
|
|
|
{
|
|
|
|
|
c.Kill();
|
|
|
|
|
c.WaitForExit();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).Should().BeEmpty();
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown()
|
|
|
|
|
{
|
2011-11-14 04:37:36 +01:00
|
|
|
|
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill());
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetById_should_return_null_if_process_doesnt_exist()
|
|
|
|
|
{
|
2013-05-07 07:38:40 +02:00
|
|
|
|
Subject.GetProcessById(1234567).Should().BeNull();
|
2011-12-12 07:52:58 +01:00
|
|
|
|
|
2011-12-20 01:58:26 +01:00
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(0)]
|
|
|
|
|
[TestCase(-1)]
|
|
|
|
|
[TestCase(9999)]
|
|
|
|
|
public void GetProcessById_should_return_null_for_invalid_process(int processId)
|
|
|
|
|
{
|
2013-05-07 07:38:40 +02:00
|
|
|
|
Subject.GetProcessById(processId).Should().BeNull();
|
2011-12-12 07:52:58 +01:00
|
|
|
|
|
2011-12-20 01:58:26 +01:00
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Should_be_able_to_start_process()
|
|
|
|
|
{
|
2013-08-14 07:20:24 +02:00
|
|
|
|
var process = Subject.Start(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe"));
|
2013-05-07 07:38:40 +02:00
|
|
|
|
|
2013-07-30 22:19:09 +02:00
|
|
|
|
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
2013-08-13 16:39:00 +02:00
|
|
|
|
.BeTrue("excepted one dummy process to be already running");
|
|
|
|
|
|
|
|
|
|
process.Kill();
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
|
|
|
|
|
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-23 19:32:57 +02:00
|
|
|
|
|
2013-05-07 07:38:40 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void kill_all_should_kill_all_process_with_name()
|
|
|
|
|
{
|
|
|
|
|
var dummy1 = StartDummyProcess();
|
|
|
|
|
var dummy2 = StartDummyProcess();
|
|
|
|
|
|
|
|
|
|
Subject.KillAll(dummy1.ProcessName);
|
|
|
|
|
|
|
|
|
|
dummy1.HasExited.Should().BeTrue();
|
|
|
|
|
dummy2.HasExited.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-14 07:20:24 +02:00
|
|
|
|
private Process StartDummyProcess()
|
2011-10-23 19:32:57 +02:00
|
|
|
|
{
|
2013-08-14 07:20:24 +02:00
|
|
|
|
return Subject.Start(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-12 07:52:58 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void ToString_on_new_processInfo()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(new ProcessInfo().ToString());
|
2012-12-21 02:49:57 +01:00
|
|
|
|
ExceptionVerification.MarkInconclusive(typeof(Win32Exception));
|
2011-12-12 07:52:58 +01:00
|
|
|
|
}
|
2011-10-23 19:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
}
|