From f9a316f632f60e09c880483be5bc3d083ca62048 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 23 Oct 2011 10:32:57 -0700 Subject: [PATCH] Moved tests for NzbDrone.Common to its own test project. added some new tests. --- NzbDrone.App.Test/EnviromentProviderTest.cs | 30 ------ NzbDrone.App.Test/NzbDrone.App.Test.csproj | 1 - .../EnviromentProviderTest.cs | 44 +++++++++ .../NzbDrone.Common.Test.csproj | 91 +++++++++++++++++++ NzbDrone.Common.Test/ProcessProviderTests.cs | 77 ++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++ .../ServiceControllerTests.cs | 79 ++++++++++++++++ NzbDrone.Common.Test/packages.config | 7 ++ NzbDrone.Core.Test/Framework/Fixtures.cs | 1 - NzbDrone.Test.Dummy/Program.cs | 3 - NzbDrone.sln | 15 +++ packages/repositories.config | 1 + 12 files changed, 350 insertions(+), 35 deletions(-) delete mode 100644 NzbDrone.App.Test/EnviromentProviderTest.cs create mode 100644 NzbDrone.Common.Test/EnviromentProviderTest.cs create mode 100644 NzbDrone.Common.Test/NzbDrone.Common.Test.csproj create mode 100644 NzbDrone.Common.Test/ProcessProviderTests.cs create mode 100644 NzbDrone.Common.Test/Properties/AssemblyInfo.cs create mode 100644 NzbDrone.Common.Test/ServiceControllerTests.cs create mode 100644 NzbDrone.Common.Test/packages.config diff --git a/NzbDrone.App.Test/EnviromentProviderTest.cs b/NzbDrone.App.Test/EnviromentProviderTest.cs deleted file mode 100644 index 3340a11d7..000000000 --- a/NzbDrone.App.Test/EnviromentProviderTest.cs +++ /dev/null @@ -1,30 +0,0 @@ -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Common; -using NzbDrone.Providers; - -namespace NzbDrone.App.Test -{ - [TestFixture] - public class EnviromentProviderTest - { - - [Test] - public void Is_user_interactive_should_be_false() - { - var enviromentController = new EnviromentProvider(); - - //Act - enviromentController.IsUserInteractive.Should().BeTrue(); - } - - [Test] - public void Log_path_should_not_be_empty() - { - var enviromentController = new EnviromentProvider(); - - //Act - enviromentController.LogPath.Should().NotBeBlank(); - } - } -} diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index df95ddc4e..515023417 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -82,7 +82,6 @@ - diff --git a/NzbDrone.Common.Test/EnviromentProviderTest.cs b/NzbDrone.Common.Test/EnviromentProviderTest.cs new file mode 100644 index 000000000..adfffb48f --- /dev/null +++ b/NzbDrone.Common.Test/EnviromentProviderTest.cs @@ -0,0 +1,44 @@ +// ReSharper disable InconsistentNaming + +using System.IO; +using FluentAssertions; +using NUnit.Framework; + +namespace NzbDrone.Common.Test +{ + [TestFixture] + public class EnviromentProviderTest + { + readonly EnviromentProvider enviromentController = new EnviromentProvider(); + + [Test] + + public void Is_user_interactive_should_be_false() + { + enviromentController.IsUserInteractive.Should().BeTrue(); + } + + [Test] + public void Log_path_should_not_be_empty() + { + enviromentController.LogPath.Should().NotBeBlank(); + Path.IsPathRooted(enviromentController.LogPath).Should().BeTrue("Path is not rooted"); + + } + + [Test] + public void StartupPath_should_not_be_empty() + { + enviromentController.StartUpPath.Should().NotBeBlank(); + Path.IsPathRooted(enviromentController.StartUpPath).Should().BeTrue("Path is not rooted"); + + } + + [Test] + public void ApplicationPath_should_not_be_empty() + { + enviromentController.ApplicationPath.Should().NotBeBlank(); + Path.IsPathRooted(enviromentController.ApplicationPath).Should().BeTrue("Path is not rooted"); + } + } +} diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj new file mode 100644 index 000000000..d11d1784f --- /dev/null +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -0,0 +1,91 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997} + Library + Properties + NzbDrone.Common.Test + NzbDrone.Common.Test + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll + + + ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll + + + ..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll + + + ..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll + + + ..\packages\NUnit.2.5.10.11092\lib\nunit.mocks.dll + + + ..\packages\NUnit.2.5.10.11092\lib\pnunit.framework.dll + + + + + + + + + + + + + + + + + + + + + + {F2BE0FDF-6E47-4827-A420-DD4EF82407F8} + NzbDrone.Common + + + {FAFB5948-A222-4CF6-AD14-026BE7564802} + NzbDrone.Test.Dummy + + + + + + + + \ No newline at end of file diff --git a/NzbDrone.Common.Test/ProcessProviderTests.cs b/NzbDrone.Common.Test/ProcessProviderTests.cs new file mode 100644 index 000000000..b3cc05b14 --- /dev/null +++ b/NzbDrone.Common.Test/ProcessProviderTests.cs @@ -0,0 +1,77 @@ +using System.Diagnostics; +using System.Linq; +using FluentAssertions; +using NUnit.Framework; + +namespace NzbDrone.Common.Test +{ + [TestFixture] + public class ProcessProviderTests + { + private const string DummyProccessName = "NzbDrone.Test.Dummy"; + ProcessProvider _processProvider; + + [SetUp] + public void Setup() + { + Process.GetProcessesByName(DummyProccessName).ToList().ForEach(c => c.Kill()); + _processProvider = new ProcessProvider(); + } + + [TearDown] + public void TearDown() + { + Process.GetProcessesByName(DummyProccessName).ToList().ForEach(c => c.Kill()); + } + + [TestCase(0)] + [TestCase(123332324)] + public void Kill_should_not_fail_on_invalid_process_is(int processId) + { + _processProvider.Kill(processId); + } + + [Test] + public void GetById_should_return_null_if_process_doesnt_exist() + { + _processProvider.GetProcessById(1234567).Should().BeNull(); + } + + [TestCase(0)] + [TestCase(-1)] + [TestCase(9999)] + public void GetProcessById_should_return_null_for_invalid_process(int processId) + { + _processProvider.GetProcessById(processId).Should().BeNull(); + } + + [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() + { + var startInfo = new ProcessStartInfo(DummyProccessName + ".exe"); + + //Act/Assert + _processProvider.GetProcessByName(DummyProccessName).Should() + .BeEmpty("Dummy process is already running"); + _processProvider.Start(startInfo).Should().NotBeNull(); + + _processProvider.GetProcessByName(DummyProccessName).Should() + .HaveCount(1, "excepted one dummy process to be already running"); + } + + public Process StartDummyProcess() + { + var startInfo = new ProcessStartInfo(DummyProccessName + ".exe"); + return _processProvider.Start(startInfo); + } + + } +} diff --git a/NzbDrone.Common.Test/Properties/AssemblyInfo.cs b/NzbDrone.Common.Test/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..0870584c0 --- /dev/null +++ b/NzbDrone.Common.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("NzbDrone.Common.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("NzbDrone.Common.Test")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("dc28491a-9f47-4823-a239-0e195d2ee42b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/NzbDrone.Common.Test/ServiceControllerTests.cs b/NzbDrone.Common.Test/ServiceControllerTests.cs new file mode 100644 index 000000000..90595b837 --- /dev/null +++ b/NzbDrone.Common.Test/ServiceControllerTests.cs @@ -0,0 +1,79 @@ +// ReSharper disable InconsistentNaming + +using System.ServiceProcess; +using FluentAssertions; +using NUnit.Framework; + +namespace NzbDrone.Common.Test +{ + [TestFixture] + public class ServiceControllerTests + { + private const string ALWAYS_INSTALLED_SERVICE = "SCardSvr"; //Smart Card + private ServiceProvider serviceProvider; + + + [SetUp] + public void Setup() + { + serviceProvider = new ServiceProvider(); + } + + [Test] + public void Exists_should_find_existing_service() + { + //Act + var exists = serviceProvider.ServiceExist(ALWAYS_INSTALLED_SERVICE); + + exists.Should().BeTrue(); + } + + [Test] + public void Exists_should_not_find_random_service() + { + //Act + var exists = serviceProvider.ServiceExist("random_service_name"); + + exists.Should().BeFalse(); + } + + + [Test] + public void Service_should_be_installed_and_then_uninstalled() + { + //Act + serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse("Service already installed"); + serviceProvider.Install(); + serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeTrue(); + serviceProvider.UnInstall(); + serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse(); + } + + [Test] + [Explicit] + public void UnInstallService() + { + //Act + serviceProvider.UnInstall(); + serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName).Should().BeFalse(); + } + + [Test] + [Timeout(10000)] + public void Should_be_able_to_start_and_stop_service() + { + serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status + .Should().NotBe(ServiceControllerStatus.Running); + + serviceProvider.Start(ALWAYS_INSTALLED_SERVICE); + + serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status + .Should().Be(ServiceControllerStatus.Running); + + serviceProvider.Stop(ALWAYS_INSTALLED_SERVICE); + + serviceProvider.GetService(ALWAYS_INSTALLED_SERVICE).Status + .Should().Be(ServiceControllerStatus.Stopped); + } + } +} diff --git a/NzbDrone.Common.Test/packages.config b/NzbDrone.Common.Test/packages.config new file mode 100644 index 000000000..433116fba --- /dev/null +++ b/NzbDrone.Common.Test/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/NzbDrone.Core.Test/Framework/Fixtures.cs b/NzbDrone.Core.Test/Framework/Fixtures.cs index 8b6334262..05eb6d4a1 100644 --- a/NzbDrone.Core.Test/Framework/Fixtures.cs +++ b/NzbDrone.Core.Test/Framework/Fixtures.cs @@ -3,7 +3,6 @@ using System.IO; using NLog; using NLog.Config; using NUnit.Framework; -using NzbDrone.Core; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; diff --git a/NzbDrone.Test.Dummy/Program.cs b/NzbDrone.Test.Dummy/Program.cs index c5356034a..746e7ef5c 100644 --- a/NzbDrone.Test.Dummy/Program.cs +++ b/NzbDrone.Test.Dummy/Program.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; namespace NzbDrone.Test.Dummy { diff --git a/NzbDrone.sln b/NzbDrone.sln index 7551226fe..97196e319 100644 --- a/NzbDrone.sln +++ b/NzbDrone.sln @@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Update.Test", "Nzb EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Common", "NzbDrone.Common\NzbDrone.Common.csproj", "{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Common.Test", "NzbDrone.Common.Test\NzbDrone.Common.Test.csproj", "{BEC74619-DDBB-4FBA-B517-D3E20AFC9997}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -147,6 +149,18 @@ Global {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Release|Mixed Platforms.Build.0 = Release|Any CPU {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Release|x64.ActiveCfg = Release|Any CPU {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Release|x86.ActiveCfg = Release|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|x64.ActiveCfg = Debug|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|x86.ActiveCfg = Debug|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|Any CPU.Build.0 = Release|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|x64.ActiveCfg = Release|Any CPU + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -156,6 +170,7 @@ Global {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5} = {57A04B72-8088-4F75-A582-1158CF8291F7} {FAFB5948-A222-4CF6-AD14-026BE7564802} = {57A04B72-8088-4F75-A582-1158CF8291F7} {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97} = {57A04B72-8088-4F75-A582-1158CF8291F7} + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997} = {57A04B72-8088-4F75-A582-1158CF8291F7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.0\lib\NET35 diff --git a/packages/repositories.config b/packages/repositories.config index 5219697f0..c2c1aeb7c 100644 --- a/packages/repositories.config +++ b/packages/repositories.config @@ -8,4 +8,5 @@ + \ No newline at end of file