1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-30 19:56:54 +00:00
Sonarr/NzbDrone.Common.Test/ProcessProviderTests.cs

114 lines
3.2 KiB
C#
Raw Normal View History

2013-05-03 04:37:08 +00:00
using System;
using System.ComponentModel;
2011-10-23 18:31:17 +00:00
using System.Diagnostics;
2013-08-06 02:42:22 +00:00
using System.IO;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Model;
2011-11-13 18:16:31 +00:00
using NzbDrone.Test.Common;
using NzbDrone.Test.Dummy;
namespace NzbDrone.Common.Test
{
[TestFixture]
2013-05-07 05:38:40 +00:00
public class ProcessProviderTests : TestBase<ProcessProvider>
{
[SetUp]
public void Setup()
{
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c =>
{
c.Kill();
c.WaitForExit();
});
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).Should().BeEmpty();
}
[TearDown]
public void TearDown()
{
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill());
}
[Test]
public void GetById_should_return_null_if_process_doesnt_exist()
{
2013-05-07 05:38:40 +00:00
Subject.GetProcessById(1234567).Should().BeNull();
ExceptionVerification.ExpectedWarns(1);
}
[TestCase(0)]
[TestCase(-1)]
[TestCase(9999)]
public void GetProcessById_should_return_null_for_invalid_process(int processId)
{
2013-05-07 05:38:40 +00:00
Subject.GetProcessById(processId).Should().BeNull();
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void Should_be_able_to_start_process()
{
2013-08-06 02:42:22 +00:00
var startInfo = new ProcessStartInfo(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe"));
var process = Subject.Start(startInfo);
2013-05-07 05:38:40 +00:00
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
.BeTrue("excepted one dummy process to be already running");
process.Kill();
process.WaitForExit();
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should().BeFalse();
}
[Test]
public void Should_be_able_to_execute_process()
{
var process = Subject.ShellExecute(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe"));
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
.BeTrue("excepted one dummy process to be already running");
process.Kill();
process.WaitForExit();
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should().BeFalse();
}
2013-05-07 05:38:40 +00: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();
}
public Process StartDummyProcess()
{
var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
2013-05-07 05:38:40 +00:00
return Subject.Start(startInfo);
}
[Test]
public void ToString_on_new_processInfo()
{
Console.WriteLine(new ProcessInfo().ToString());
ExceptionVerification.MarkInconclusive(typeof(Win32Exception));
}
}
}