2016-12-23 21:45:24 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-11-26 02:46:12 +00:00
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common.Model;
|
|
|
|
|
using NzbDrone.Common.Processes;
|
|
|
|
|
using NzbDrone.Host;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.App.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class NzbDroneProcessServiceFixture : TestBase<SingleInstancePolicy>
|
|
|
|
|
{
|
|
|
|
|
private const int CURRENT_PROCESS_ID = 5;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<IProcessProvider>().Setup(c => c.GetCurrentProcess())
|
|
|
|
|
.Returns(new ProcessInfo() { Id = CURRENT_PROCESS_ID });
|
2014-04-28 06:34:29 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IProcessProvider>()
|
2017-09-18 03:25:28 +00:00
|
|
|
|
.Setup(s => s.FindProcessByName(ProcessProvider.SONARR_CONSOLE_PROCESS_NAME))
|
2014-04-28 06:34:29 +00:00
|
|
|
|
.Returns(new List<ProcessInfo>());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IProcessProvider>()
|
2017-09-18 03:25:28 +00:00
|
|
|
|
.Setup(s => s.FindProcessByName(ProcessProvider.SONARR_PROCESS_NAME))
|
2014-04-28 06:34:29 +00:00
|
|
|
|
.Returns(new List<ProcessInfo>());
|
2013-11-26 02:46:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_continue_if_only_instance()
|
|
|
|
|
{
|
2014-04-28 06:34:29 +00:00
|
|
|
|
Mocker.GetMock<IProcessProvider>()
|
2015-10-03 17:45:26 +00:00
|
|
|
|
.Setup(c => c.FindProcessByName(It.Is<string>(f => f.Contains("NzbDrone"))))
|
2014-04-28 06:34:29 +00:00
|
|
|
|
.Returns(new List<ProcessInfo>
|
|
|
|
|
{
|
2021-08-03 04:43:28 +00:00
|
|
|
|
new ProcessInfo { Id = CURRENT_PROCESS_ID }
|
2014-04-28 06:34:29 +00:00
|
|
|
|
});
|
2013-11-26 02:46:12 +00:00
|
|
|
|
|
2013-11-26 07:08:12 +00:00
|
|
|
|
Subject.PreventStartIfAlreadyRunning();
|
2013-11-26 02:46:12 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IBrowserService>().Verify(c => c.LaunchWebUI(), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_enforce_if_another_console_is_running()
|
|
|
|
|
{
|
2014-04-28 06:34:29 +00:00
|
|
|
|
Mocker.GetMock<IProcessProvider>()
|
2017-09-18 03:25:28 +00:00
|
|
|
|
.Setup(c => c.FindProcessByName(ProcessProvider.SONARR_CONSOLE_PROCESS_NAME))
|
2014-04-28 06:34:29 +00:00
|
|
|
|
.Returns(new List<ProcessInfo>
|
|
|
|
|
{
|
2021-07-30 04:47:53 +00:00
|
|
|
|
new ProcessInfo { Id = 10 },
|
|
|
|
|
new ProcessInfo { Id = CURRENT_PROCESS_ID }
|
2014-04-28 06:34:29 +00:00
|
|
|
|
});
|
2013-11-26 02:46:12 +00:00
|
|
|
|
|
2013-11-26 07:08:12 +00:00
|
|
|
|
Assert.Throws<TerminateApplicationException>(() => Subject.PreventStartIfAlreadyRunning());
|
2013-11-26 02:46:12 +00:00
|
|
|
|
Mocker.GetMock<IBrowserService>().Verify(c => c.LaunchWebUI(), Times.Once());
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_false_if_another_gui_is_running()
|
|
|
|
|
{
|
2014-04-28 06:34:29 +00:00
|
|
|
|
Mocker.GetMock<IProcessProvider>()
|
2017-09-18 03:25:28 +00:00
|
|
|
|
.Setup(c => c.FindProcessByName(ProcessProvider.SONARR_PROCESS_NAME))
|
2014-04-28 06:34:29 +00:00
|
|
|
|
.Returns(new List<ProcessInfo>
|
|
|
|
|
{
|
2021-07-30 04:47:53 +00:00
|
|
|
|
new ProcessInfo { Id = CURRENT_PROCESS_ID },
|
|
|
|
|
new ProcessInfo { Id = 10 }
|
2014-04-28 06:34:29 +00:00
|
|
|
|
});
|
2013-11-26 02:46:12 +00:00
|
|
|
|
|
2013-11-26 07:08:12 +00:00
|
|
|
|
Assert.Throws<TerminateApplicationException>(() => Subject.PreventStartIfAlreadyRunning());
|
2013-11-26 02:46:12 +00:00
|
|
|
|
Mocker.GetMock<IBrowserService>().Verify(c => c.LaunchWebUI(), Times.Once());
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|