mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 10:47:08 -07:00
More nzbdrone.exe refactoring.
This commit is contained in:
parent
69ba365cd3
commit
8bf4f81a04
30 changed files with 1092 additions and 234 deletions
39
NzbDrone.App.Test/ApplicationTest.cs
Normal file
39
NzbDrone.App.Test/ApplicationTest.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AutoMoq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Providers;
|
||||
|
||||
namespace NzbDrone.App.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class MonitoringProviderTest
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void Ensure_priority_doesnt_fail_on_invalid_iis_proccess_id()
|
||||
{
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
var processMock = mocker.GetMock<ProcessProvider>();
|
||||
processMock.Setup(c => c.GetCurrentProcess())
|
||||
.Returns(Builder<ProcessInfo>.CreateNew().With(c => c.Priority == ProcessPriorityClass.Normal).Build());
|
||||
|
||||
processMock.Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null);
|
||||
|
||||
var subject = mocker.Resolve<MonitoringProvider>();
|
||||
|
||||
|
||||
//Act
|
||||
subject.EnsurePriority(null, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
166
NzbDrone.App.Test/AutoMoq/AutoMoqer.cs
Normal file
166
NzbDrone.App.Test/AutoMoq/AutoMoqer.cs
Normal file
|
@ -0,0 +1,166 @@
|
|||
// ReSharper disable RedundantUsingDirective
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using AutoMoq.Unity;
|
||||
using Microsoft.Practices.Unity;
|
||||
using Moq;
|
||||
using Moq.Language.Flow;
|
||||
|
||||
[assembly: InternalsVisibleTo("AutoMoq.Tests")]
|
||||
|
||||
namespace AutoMoq
|
||||
{
|
||||
public class AutoMoqer
|
||||
{
|
||||
internal readonly MockBehavior DefaultBehavior = MockBehavior.Default;
|
||||
internal Type ResolveType;
|
||||
private IUnityContainer container;
|
||||
private IDictionary<Type, object> registeredMocks;
|
||||
|
||||
public AutoMoqer()
|
||||
{
|
||||
SetupAutoMoqer(new UnityContainer());
|
||||
}
|
||||
|
||||
public AutoMoqer(MockBehavior defaultBehavior)
|
||||
{
|
||||
DefaultBehavior = defaultBehavior;
|
||||
SetupAutoMoqer(new UnityContainer());
|
||||
|
||||
}
|
||||
|
||||
internal AutoMoqer(IUnityContainer container)
|
||||
{
|
||||
SetupAutoMoqer(container);
|
||||
}
|
||||
|
||||
public virtual T Resolve<T>()
|
||||
{
|
||||
ResolveType = typeof(T);
|
||||
var result = container.Resolve<T>();
|
||||
SetConstant(result);
|
||||
ResolveType = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual Mock<T> GetMock<T>() where T : class
|
||||
{
|
||||
return GetMock<T>(DefaultBehavior);
|
||||
}
|
||||
|
||||
public virtual Mock<T> GetMock<T>(MockBehavior behavior) where T : class
|
||||
{
|
||||
ResolveType = null;
|
||||
var type = GetTheMockType<T>();
|
||||
if (GetMockHasNotBeenCalledForThisType(type))
|
||||
{
|
||||
CreateANewMockAndRegisterIt<T>(type, behavior);
|
||||
}
|
||||
|
||||
var mock = TheRegisteredMockForThisType<T>(type);
|
||||
|
||||
if (behavior != MockBehavior.Default && mock.Behavior == MockBehavior.Default)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to change be behaviour of a an existing mock.");
|
||||
}
|
||||
|
||||
return mock;
|
||||
}
|
||||
|
||||
internal virtual void SetMock(Type type, Mock mock)
|
||||
{
|
||||
if (registeredMocks.ContainsKey(type) == false)
|
||||
registeredMocks.Add(type, mock);
|
||||
}
|
||||
|
||||
public virtual void SetConstant<T>(T instance)
|
||||
{
|
||||
container.RegisterInstance(instance);
|
||||
SetMock(instance.GetType(), null);
|
||||
}
|
||||
|
||||
public ISetup<T> Setup<T>(Expression<Action<T>> expression) where T : class
|
||||
{
|
||||
return GetMock<T>().Setup(expression);
|
||||
}
|
||||
|
||||
public ISetup<T, TResult> Setup<T, TResult>(Expression<Func<T, TResult>> expression) where T : class
|
||||
{
|
||||
return GetMock<T>().Setup(expression);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression, string failMessage) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression, failMessage);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression, Times times) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression, times);
|
||||
}
|
||||
|
||||
public void Verify<T>(Expression<Action<T>> expression, Times times, string failMessage) where T : class
|
||||
{
|
||||
GetMock<T>().Verify(expression, times, failMessage);
|
||||
}
|
||||
|
||||
public void VerifyAllMocks()
|
||||
{
|
||||
foreach (var registeredMock in registeredMocks)
|
||||
{
|
||||
var mock = registeredMock.Value as Mock;
|
||||
if (mock != null)
|
||||
mock.VerifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
#region private methods
|
||||
|
||||
private void SetupAutoMoqer(IUnityContainer container)
|
||||
{
|
||||
this.container = container;
|
||||
container.RegisterInstance(this);
|
||||
|
||||
registeredMocks = new Dictionary<Type, object>();
|
||||
AddTheAutoMockingContainerExtensionToTheContainer(container);
|
||||
}
|
||||
|
||||
private static void AddTheAutoMockingContainerExtensionToTheContainer(IUnityContainer container)
|
||||
{
|
||||
container.AddNewExtension<AutoMockingContainerExtension>();
|
||||
return;
|
||||
}
|
||||
|
||||
private Mock<T> TheRegisteredMockForThisType<T>(Type type) where T : class
|
||||
{
|
||||
return (Mock<T>)registeredMocks.Where(x => x.Key == type).First().Value;
|
||||
}
|
||||
|
||||
private void CreateANewMockAndRegisterIt<T>(Type type, MockBehavior behavior) where T : class
|
||||
{
|
||||
var mock = new Mock<T>(behavior);
|
||||
container.RegisterInstance(mock.Object);
|
||||
SetMock(type, mock);
|
||||
}
|
||||
|
||||
private bool GetMockHasNotBeenCalledForThisType(Type type)
|
||||
{
|
||||
return registeredMocks.ContainsKey(type) == false;
|
||||
}
|
||||
|
||||
private static Type GetTheMockType<T>() where T : class
|
||||
{
|
||||
return typeof(T);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
187
NzbDrone.App.Test/AutoMoq/AutoMoqerTest.cs
Normal file
187
NzbDrone.App.Test/AutoMoq/AutoMoqerTest.cs
Normal file
|
@ -0,0 +1,187 @@
|
|||
// ReSharper disable RedundantUsingDirective
|
||||
using System;
|
||||
using AutoMoq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class AutoMoqerTest
|
||||
{
|
||||
[Test]
|
||||
public void GetMock_on_interface_returns_mock()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var mock = mocker.GetMock<IDependency>();
|
||||
|
||||
//Assert
|
||||
Assert.IsNotNull(mock);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMock_on_concrete_returns_mock()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var mock = mocker.GetMock<ConcreteClass>();
|
||||
|
||||
//Assert
|
||||
Assert.IsNotNull(mock);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Resolve_doesnt_return_mock()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ConcreteClass>().Do();
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("hello", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Resolve_with_dependency_doesnt_return_mock()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<VirtualDependency>().VirtualMethod();
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("hello", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Resolve_with_mocked_dependency_uses_mock()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<VirtualDependency>()
|
||||
.Setup(m => m.VirtualMethod())
|
||||
.Returns("mocked");
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ClassWithVirtualDependencies>().CallVirtualChild();
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("mocked", result);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Resolve_with_unbound_concerete_dependency_uses_mock()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ClassWithVirtualDependencies>().CallVirtualChild();
|
||||
|
||||
var mockedResult = new Mock<VirtualDependency>().Object.VirtualMethod();
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(mockedResult, result);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Resolve_with_constant_concerete_dependency_uses_constant()
|
||||
{
|
||||
//Arrange
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
var constant = new VirtualDependency { PropValue = Guid.NewGuid().ToString() };
|
||||
|
||||
mocker.SetConstant(constant);
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ClassWithVirtualDependencies>().GetVirtualProperty();
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(constant.PropValue, result);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConcreteClass
|
||||
{
|
||||
public string Do()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
public class Dependency : IDependency
|
||||
{
|
||||
}
|
||||
|
||||
public interface IDependency
|
||||
{
|
||||
}
|
||||
|
||||
public class ClassWithDependencies
|
||||
{
|
||||
public ClassWithDependencies(IDependency dependency)
|
||||
{
|
||||
Dependency = dependency;
|
||||
}
|
||||
|
||||
public IDependency Dependency { get; set; }
|
||||
}
|
||||
|
||||
public class ClassWithVirtualDependencies
|
||||
{
|
||||
private readonly VirtualDependency _virtualDependency;
|
||||
|
||||
public ClassWithVirtualDependencies(IDependency dependency, VirtualDependency virtualDependency)
|
||||
{
|
||||
_virtualDependency = virtualDependency;
|
||||
Dependency = dependency;
|
||||
}
|
||||
|
||||
public IDependency Dependency { get; set; }
|
||||
|
||||
public string CallVirtualChild()
|
||||
{
|
||||
return _virtualDependency.VirtualMethod();
|
||||
}
|
||||
|
||||
public string GetVirtualProperty()
|
||||
{
|
||||
return _virtualDependency.PropValue;
|
||||
}
|
||||
}
|
||||
|
||||
public class VirtualDependency
|
||||
{
|
||||
private readonly IDependency _dependency;
|
||||
|
||||
public VirtualDependency()
|
||||
{
|
||||
}
|
||||
|
||||
public VirtualDependency(IDependency dependency)
|
||||
{
|
||||
_dependency = dependency;
|
||||
}
|
||||
|
||||
public string PropValue { get; set; }
|
||||
|
||||
public virtual string VirtualMethod()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
}
|
22
NzbDrone.App.Test/AutoMoq/License.txt
Normal file
22
NzbDrone.App.Test/AutoMoq/License.txt
Normal file
|
@ -0,0 +1,22 @@
|
|||
Copyright (c) 2010 Darren Cauthon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,84 @@
|
|||
// ReSharper disable RedundantUsingDirective
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.Practices.ObjectBuilder2;
|
||||
using Microsoft.Practices.Unity;
|
||||
using Moq;
|
||||
|
||||
namespace AutoMoq.Unity
|
||||
{
|
||||
internal class AutoMockingBuilderStrategy : BuilderStrategy
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly MockRepository _mockFactory;
|
||||
private readonly IEnumerable<Type> _registeredTypes;
|
||||
|
||||
public AutoMockingBuilderStrategy(IEnumerable<Type> registeredTypes, IUnityContainer container)
|
||||
{
|
||||
var autoMoqer = container.Resolve<AutoMoqer>();
|
||||
_mockFactory = new MockRepository(autoMoqer.DefaultBehavior);
|
||||
_registeredTypes = registeredTypes;
|
||||
_container = container;
|
||||
}
|
||||
|
||||
public override void PreBuildUp(IBuilderContext context)
|
||||
{
|
||||
var autoMoqer = _container.Resolve<AutoMoqer>();
|
||||
|
||||
var type = GetTheTypeFromTheBuilderContext(context);
|
||||
if (AMockObjectShouldBeCreatedForThisType(type))
|
||||
{
|
||||
var mock = CreateAMockObject(type);
|
||||
context.Existing = mock.Object;
|
||||
autoMoqer.SetMock(type, mock);
|
||||
}
|
||||
}
|
||||
|
||||
#region private methods
|
||||
|
||||
private bool AMockObjectShouldBeCreatedForThisType(Type type)
|
||||
{
|
||||
var mocker = _container.Resolve<AutoMoqer>();
|
||||
return TypeIsNotRegistered(type) && (mocker.ResolveType == null || mocker.ResolveType != type);
|
||||
//return TypeIsNotRegistered(type) && type.IsInterface;
|
||||
}
|
||||
|
||||
private static Type GetTheTypeFromTheBuilderContext(IBuilderContext context)
|
||||
{
|
||||
return (context.OriginalBuildKey).Type;
|
||||
}
|
||||
|
||||
private bool TypeIsNotRegistered(Type type)
|
||||
{
|
||||
return _registeredTypes.Any(x => x.Equals(type)) == false;
|
||||
}
|
||||
|
||||
private Mock CreateAMockObject(Type type)
|
||||
{
|
||||
var createMethod = GenerateAnInterfaceMockCreationMethod(type);
|
||||
|
||||
return InvokeTheMockCreationMethod(createMethod);
|
||||
}
|
||||
|
||||
private Mock InvokeTheMockCreationMethod(MethodInfo createMethod)
|
||||
{
|
||||
return (Mock)createMethod.Invoke(_mockFactory, new object[] { new List<object>().ToArray() });
|
||||
}
|
||||
|
||||
private MethodInfo GenerateAnInterfaceMockCreationMethod(Type type)
|
||||
{
|
||||
var createMethodWithNoParameters = _mockFactory.GetType().GetMethod("Create", EmptyArgumentList());
|
||||
|
||||
return createMethodWithNoParameters.MakeGenericMethod(new[] { type });
|
||||
}
|
||||
|
||||
private static Type[] EmptyArgumentList()
|
||||
{
|
||||
return new[] { typeof(object[]) };
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
// ReSharper disable RedundantUsingDirective
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Practices.Unity;
|
||||
using Microsoft.Practices.Unity.ObjectBuilder;
|
||||
|
||||
namespace AutoMoq.Unity
|
||||
{
|
||||
internal class AutoMockingContainerExtension : UnityContainerExtension
|
||||
{
|
||||
private readonly IList<Type> registeredTypes = new List<Type>();
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
SetEventsOnContainerToTrackAllRegisteredTypes();
|
||||
SetBuildingStrategyForBuildingUnregisteredTypes();
|
||||
}
|
||||
|
||||
#region private methods
|
||||
|
||||
private void SetEventsOnContainerToTrackAllRegisteredTypes()
|
||||
{
|
||||
Context.Registering += ((sender, e) => RegisterType(e.TypeFrom));
|
||||
Context.RegisteringInstance += ((sender, e) => RegisterType(e.RegisteredType));
|
||||
}
|
||||
|
||||
private void RegisterType(Type typeToRegister)
|
||||
{
|
||||
registeredTypes.Add(typeToRegister);
|
||||
}
|
||||
|
||||
private void SetBuildingStrategyForBuildingUnregisteredTypes()
|
||||
{
|
||||
var strategy = new AutoMockingBuilderStrategy(registeredTypes, Container);
|
||||
Context.Strategies.Add(strategy, UnityBuildStage.PreCreation);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
38
NzbDrone.App.Test/IISProviderTest.cs
Normal file
38
NzbDrone.App.Test/IISProviderTest.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AutoMoq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Providers;
|
||||
|
||||
namespace NzbDrone.App.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class IISProviderTest
|
||||
{
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void start_should_set_IISProccessId_property()
|
||||
{
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
var configMock = mocker.GetMock<ConfigProvider>();
|
||||
configMock.SetupGet(c => c.IISExePath).Returns("NzbDrone.Test.Dummy.exe");
|
||||
|
||||
mocker.Resolve<ProcessProvider>();
|
||||
|
||||
var iisProvider = mocker.Resolve<IISProvider>();
|
||||
|
||||
iisProvider.StartServer();
|
||||
|
||||
iisProvider.IISProcessId.Should().NotBe(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -31,9 +31,21 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FizzWare.NBuilder">
|
||||
<HintPath>..\packages\NBuilder.3.0.1\lib\FizzWare.NBuilder.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FluentAssertions">
|
||||
<HintPath>..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.ServiceLocation">
|
||||
<HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Unity">
|
||||
<HintPath>..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Unity.Configuration">
|
||||
<HintPath>..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.Configuration.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq">
|
||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
|
@ -56,6 +68,13 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AutoMoq\AutoMoqer.cs" />
|
||||
<Compile Include="AutoMoq\AutoMoqerTest.cs" />
|
||||
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
|
||||
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
|
||||
<Compile Include="ApplicationTest.cs" />
|
||||
<Compile Include="IISProviderTest.cs" />
|
||||
<Compile Include="ProcessProviderTests.cs" />
|
||||
<Compile Include="EnviromentControllerTest.cs" />
|
||||
<Compile Include="ServiceControllerTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -64,11 +83,18 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NzbDrone.Test.Dummy\NzbDrone.Test.Dummy.csproj">
|
||||
<Project>{FAFB5948-A222-4CF6-AD14-026BE7564802}</Project>
|
||||
<Name>NzbDrone.Test.Dummy</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\NzbDrone\NzbDrone.csproj">
|
||||
<Project>{D12F7F2F-8A3C-415F-88FA-6DD061A84869}</Project>
|
||||
<Name>NzbDrone</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="AutoMoq\License.txt" />
|
||||
</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.
|
||||
|
|
53
NzbDrone.App.Test/ProcessProviderTests.cs
Normal file
53
NzbDrone.App.Test/ProcessProviderTests.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Providers;
|
||||
|
||||
namespace NzbDrone.App.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProcessProviderTests
|
||||
{
|
||||
ProcessProvider _processProvider;
|
||||
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_processProvider = new ProcessProvider();
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Should_be_able_to_kill_procces()
|
||||
{
|
||||
var dummyProcess = StartDummyProcess();
|
||||
_processProvider.Kill(dummyProcess.Id);
|
||||
dummyProcess.HasExited.Should().BeTrue();
|
||||
}
|
||||
|
||||
|
||||
public Process StartDummyProcess()
|
||||
{
|
||||
return Process.Start("NzbDrone.Test.Dummy.exe");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CommonServiceLocator" version="1.0" />
|
||||
<package id="FluentAssertions" version="1.5.0.0" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NBuilder" version="3.0.1" />
|
||||
<package id="NUnit" version="2.5.10.11092" />
|
||||
<package id="Unity" version="2.1.505.0" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue