Moved tests for NzbDrone.Common to its own test project. added some new tests.

This commit is contained in:
kay.one 2011-10-23 10:32:57 -07:00
parent f52620db70
commit f9a316f632
12 changed files with 350 additions and 35 deletions

View File

@ -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();
}
}
}

View File

@ -82,7 +82,6 @@
<Compile Include="ConfigProviderTest.cs" />
<Compile Include="IISProviderTest.cs" />
<Compile Include="ProcessProviderTests.cs" />
<Compile Include="EnviromentProviderTest.cs" />
<Compile Include="ServiceControllerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@ -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");
}
}
}

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BEC74619-DDBB-4FBA-B517-D3E20AFC9997}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NzbDrone.Common.Test</RootNamespace>
<AssemblyName>NzbDrone.Common.Test</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentAssertions">
<HintPath>..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.mocks">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.mocks.dll</HintPath>
</Reference>
<Reference Include="pnunit.framework">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\pnunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="EnviromentProviderTest.cs" />
<Compile Include="ProcessProviderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceControllerTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj">
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
<Name>NzbDrone.Common</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone.Test.Dummy\NzbDrone.Test.Dummy.csproj">
<Project>{FAFB5948-A222-4CF6-AD14-026BE7564802}</Project>
<Name>NzbDrone.Test.Dummy</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -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);
}
}
}

View File

@ -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")]

View File

@ -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);
}
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentAssertions" version="1.5.0.0" />
<package id="Moq" version="4.0.10827" />
<package id="NLog" version="2.0.0.2000" />
<package id="NUnit" version="2.5.10.11092" />
</packages>

View File

@ -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;

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace NzbDrone.Test.Dummy
{

View File

@ -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

View File

@ -8,4 +8,5 @@
<repository path="..\NzbDrone.Update.Test\packages.config" />
<repository path="..\NzbDrone.Update\packages.config" />
<repository path="..\NzbDrone.Common\packages.config" />
<repository path="..\NzbDrone.Common.Test\packages.config" />
</repositories>