From 4d3217432c18c23ad3b46563eb8c3ebe7e1b3f90 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 10 Feb 2014 11:40:13 -0800 Subject: [PATCH] Fixed some unit tests --- .../NzbDroneProcessServiceFixture.cs | 36 +++++-------------- .../EnvironmentInfo/RuntimeInfo.cs | 7 +++- .../Processes/INzbDroneProcessProvider.cs | 2 +- src/NzbDrone.Host/SingleInstancePolicy.cs | 2 +- .../NzbDrone.Mono.Test.csproj | 13 +++++++ .../ServiceFactoryFixture.cs | 31 ++++++++++++++++ src/NzbDrone.Mono.Test/packages.config | 1 + src/NzbDrone.Mono/NzbDroneProcessProvider.cs | 2 +- .../NzbDrone.Windows.Test.csproj | 13 +++++++ .../ServiceFactoryFixture.cs | 31 ++++++++++++++++ src/NzbDrone.Windows.Test/packages.config | 1 + .../NzbDroneProcessProvider.cs | 2 +- src/NzbDrone.sln | 3 ++ 13 files changed, 111 insertions(+), 33 deletions(-) create mode 100644 src/NzbDrone.Mono.Test/ServiceFactoryFixture.cs create mode 100644 src/NzbDrone.Windows.Test/ServiceFactoryFixture.cs diff --git a/src/NzbDrone.App.Test/NzbDroneProcessServiceFixture.cs b/src/NzbDrone.App.Test/NzbDroneProcessServiceFixture.cs index 0c792f0c3..faef69f54 100644 --- a/src/NzbDrone.App.Test/NzbDroneProcessServiceFixture.cs +++ b/src/NzbDrone.App.Test/NzbDroneProcessServiceFixture.cs @@ -23,11 +23,7 @@ namespace NzbDrone.App.Test [Test] public void should_continue_if_only_instance() { - Mocker.GetMock() - .Setup(c => c.FindProcessByName(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME)) - .Returns(new List()); - - Mocker.GetMock().Setup(c => c.FindProcessByName(ProcessProvider.NZB_DRONE_PROCESS_NAME)) + Mocker.GetMock().Setup(c => c.FindNzbDroneProcesses()) .Returns(new List { new ProcessInfo{Id = CURRENT_PROCESS_ID} @@ -36,29 +32,20 @@ namespace NzbDrone.App.Test Subject.PreventStartIfAlreadyRunning(); - Mocker.GetMock().Verify(c => c.LaunchWebUI(), Times.Never()); - } [Test] public void should_enforce_if_another_console_is_running() { - Mocker.GetMock() - .Setup(c => c.FindProcessByName(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME)) + Mocker.GetMock() + .Setup(c => c.FindNzbDroneProcesses()) .Returns(new List { - new ProcessInfo{Id = 10} - }); - - Mocker.GetMock().Setup(c => c.FindProcessByName(ProcessProvider.NZB_DRONE_PROCESS_NAME)) - .Returns(new List - { + new ProcessInfo{Id = 10}, new ProcessInfo{Id = CURRENT_PROCESS_ID} }); - - Assert.Throws(() => Subject.PreventStartIfAlreadyRunning()); Mocker.GetMock().Verify(c => c.LaunchWebUI(), Times.Once()); ExceptionVerification.ExpectedWarns(1); @@ -67,22 +54,15 @@ namespace NzbDrone.App.Test [Test] public void should_return_false_if_another_gui_is_running() { - Mocker.GetMock() - .Setup(c => c.FindProcessByName(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME)) + Mocker.GetMock() + .Setup(c => c.FindNzbDroneProcesses()) .Returns(new List { - new ProcessInfo{Id = CURRENT_PROCESS_ID} + new ProcessInfo{Id = CURRENT_PROCESS_ID}, + new ProcessInfo{Id = 10} }); - Mocker.GetMock().Setup(c => c.FindProcessByName(ProcessProvider.NZB_DRONE_PROCESS_NAME)) - .Returns(new List - { - new ProcessInfo{Id = 10} - }); - - - Assert.Throws(() => Subject.PreventStartIfAlreadyRunning()); Mocker.GetMock().Verify(c => c.LaunchWebUI(), Times.Once()); ExceptionVerification.ExpectedWarns(1); diff --git a/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs b/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs index 314b7cb6a..7f8ebedf3 100644 --- a/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs +++ b/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs @@ -33,7 +33,12 @@ namespace NzbDrone.Common.EnvironmentInfo serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) && serviceProvider.GetStatus(ServiceProvider.NZBDRONE_SERVICE_NAME) == ServiceControllerStatus.StartPending; - ExecutingApplication = Assembly.GetEntryAssembly().Location; + var entry = Assembly.GetEntryAssembly(); + + if (entry != null) + { + ExecutingApplication = entry.Location; + } } static RuntimeInfo() diff --git a/src/NzbDrone.Common/Processes/INzbDroneProcessProvider.cs b/src/NzbDrone.Common/Processes/INzbDroneProcessProvider.cs index 29f16b7fa..71abd6d0e 100644 --- a/src/NzbDrone.Common/Processes/INzbDroneProcessProvider.cs +++ b/src/NzbDrone.Common/Processes/INzbDroneProcessProvider.cs @@ -5,6 +5,6 @@ namespace NzbDrone.Common.Processes { public interface INzbDroneProcessProvider { - List GetNzbDroneProcesses(); + List FindNzbDroneProcesses(); } } diff --git a/src/NzbDrone.Host/SingleInstancePolicy.cs b/src/NzbDrone.Host/SingleInstancePolicy.cs index d88b11117..2952997cb 100644 --- a/src/NzbDrone.Host/SingleInstancePolicy.cs +++ b/src/NzbDrone.Host/SingleInstancePolicy.cs @@ -56,7 +56,7 @@ namespace NzbDrone.Host private List GetOtherNzbDroneProcessIds() { var currentId = _processProvider.GetCurrentProcess().Id; - var otherProcesses = _nzbDroneProcessProvider.GetNzbDroneProcesses() + var otherProcesses = _nzbDroneProcessProvider.FindNzbDroneProcesses() .Select(c => c.Id) .Except(new[] {currentId}) .ToList(); diff --git a/src/NzbDrone.Mono.Test/NzbDrone.Mono.Test.csproj b/src/NzbDrone.Mono.Test/NzbDrone.Mono.Test.csproj index 4d31659ea..6b5b32c5b 100644 --- a/src/NzbDrone.Mono.Test/NzbDrone.Mono.Test.csproj +++ b/src/NzbDrone.Mono.Test/NzbDrone.Mono.Test.csproj @@ -50,6 +50,10 @@ MinimumRecommendedRules.ruleset + + False + ..\packages\FluentAssertions.2.1.0.0\lib\net40\FluentAssertions.dll + ..\packages\NUnit.2.6.2\lib\nunit.framework.dll @@ -66,6 +70,7 @@ + @@ -79,6 +84,14 @@ {f2be0fdf-6e47-4827-a420-dd4ef82407f8} NzbDrone.Common + + {ff5ee3b6-913b-47ce-9ceb-11c51b4e1205} + NzbDrone.Core + + + {95c11a9e-56ed-456a-8447-2c89c1139266} + NzbDrone.Host + {15ad7579-a314-4626-b556-663f51d97cd1} NzbDrone.Mono diff --git a/src/NzbDrone.Mono.Test/ServiceFactoryFixture.cs b/src/NzbDrone.Mono.Test/ServiceFactoryFixture.cs new file mode 100644 index 000000000..1d5e77f87 --- /dev/null +++ b/src/NzbDrone.Mono.Test/ServiceFactoryFixture.cs @@ -0,0 +1,31 @@ +using System.Linq; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common; +using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging.Events; +using NzbDrone.Host; +using NzbDrone.Test.Common; + +namespace NzbDrone.Mono.Test +{ + [TestFixture] + public class ServiceFactoryFixture : TestBase + { + [SetUp] + public void setup() + { + Mocker.SetConstant(MainAppContainerBuilder.BuildContainer(new StartupContext())); + } + + [Test] + public void event_handlers_should_be_unique() + { + var handlers = Subject.BuildAll>() + .Select(c => c.GetType().FullName); + + handlers.Should().OnlyHaveUniqueItems(); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Mono.Test/packages.config b/src/NzbDrone.Mono.Test/packages.config index 5c3ca54dd..e6606e669 100644 --- a/src/NzbDrone.Mono.Test/packages.config +++ b/src/NzbDrone.Mono.Test/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/src/NzbDrone.Mono/NzbDroneProcessProvider.cs b/src/NzbDrone.Mono/NzbDroneProcessProvider.cs index 3b2ff34d7..147efb5b8 100644 --- a/src/NzbDrone.Mono/NzbDroneProcessProvider.cs +++ b/src/NzbDrone.Mono/NzbDroneProcessProvider.cs @@ -15,7 +15,7 @@ namespace NzbDrone.Mono _processProvider = processProvider; } - public List GetNzbDroneProcesses() + public List FindNzbDroneProcesses() { var monoProcesses = _processProvider.FindProcessByName("mono"); diff --git a/src/NzbDrone.Windows.Test/NzbDrone.Windows.Test.csproj b/src/NzbDrone.Windows.Test/NzbDrone.Windows.Test.csproj index 098c95b80..309005f99 100644 --- a/src/NzbDrone.Windows.Test/NzbDrone.Windows.Test.csproj +++ b/src/NzbDrone.Windows.Test/NzbDrone.Windows.Test.csproj @@ -50,6 +50,10 @@ MinimumRecommendedRules.ruleset + + False + ..\packages\FluentAssertions.2.1.0.0\lib\net40\FluentAssertions.dll + False ..\packages\NUnit.2.6.2\lib\nunit.framework.dll @@ -67,6 +71,7 @@ + @@ -77,6 +82,14 @@ {f2be0fdf-6e47-4827-a420-dd4ef82407f8} NzbDrone.Common + + {ff5ee3b6-913b-47ce-9ceb-11c51b4e1205} + NzbDrone.Core + + + {95c11a9e-56ed-456a-8447-2c89c1139266} + NzbDrone.Host + {caddfce0-7509-4430-8364-2074e1eefca2} NzbDrone.Test.Common diff --git a/src/NzbDrone.Windows.Test/ServiceFactoryFixture.cs b/src/NzbDrone.Windows.Test/ServiceFactoryFixture.cs new file mode 100644 index 000000000..bde389da2 --- /dev/null +++ b/src/NzbDrone.Windows.Test/ServiceFactoryFixture.cs @@ -0,0 +1,31 @@ +using System.Linq; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common; +using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging.Events; +using NzbDrone.Host; +using NzbDrone.Test.Common; + +namespace NzbDrone.Windows.Test +{ + [TestFixture] + public class ServiceFactoryFixture : TestBase + { + [SetUp] + public void setup() + { + Mocker.SetConstant(MainAppContainerBuilder.BuildContainer(new StartupContext())); + } + + [Test] + public void event_handlers_should_be_unique() + { + var handlers = Subject.BuildAll>() + .Select(c => c.GetType().FullName); + + handlers.Should().OnlyHaveUniqueItems(); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Windows.Test/packages.config b/src/NzbDrone.Windows.Test/packages.config index 5c3ca54dd..e6606e669 100644 --- a/src/NzbDrone.Windows.Test/packages.config +++ b/src/NzbDrone.Windows.Test/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/src/NzbDrone.Windows/NzbDroneProcessProvider.cs b/src/NzbDrone.Windows/NzbDroneProcessProvider.cs index c75f4cf30..1e18b6c50 100644 --- a/src/NzbDrone.Windows/NzbDroneProcessProvider.cs +++ b/src/NzbDrone.Windows/NzbDroneProcessProvider.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Windows _processProvider = processProvider; } - public List GetNzbDroneProcesses() + public List FindNzbDroneProcesses() { var consoleProcesses = _processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME); var winformProcesses = _processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_PROCESS_NAME); diff --git a/src/NzbDrone.sln b/src/NzbDrone.sln index 6607c1c36..fa28f72be 100644 --- a/src/NzbDrone.sln +++ b/src/NzbDrone.sln @@ -73,6 +73,9 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Platform", "Platform", "{0F0D4998-8F5D-4467-A909-BB192C4B3B4B}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Platform", "Platform", "{4EACDBBC-BCD7-4765-A57B-3E08331E4749}" + ProjectSection(SolutionItems) = preProject + NzbDrone.Common.Test\ServiceFactoryFixture.cs = NzbDrone.Common.Test\ServiceFactoryFixture.cs + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Windows.Test", "NzbDrone.Windows.Test\NzbDrone.Windows.Test.csproj", "{80B51429-7A0E-46D6-BEE3-C80DCB1C4EAA}" EndProject