mirror of https://github.com/lidarr/Lidarr
Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus
This commit is contained in:
commit
f68fa84cad
|
@ -17,7 +17,7 @@ Thumbs.db
|
||||||
*.cache
|
*.cache
|
||||||
*.ilk
|
*.ilk
|
||||||
*.log
|
*.log
|
||||||
[Bb]in
|
[Bb]in*/
|
||||||
[Dd]ebug*/
|
[Dd]ebug*/
|
||||||
*.lib
|
*.lib
|
||||||
*.sbr
|
*.sbr
|
||||||
|
|
|
@ -1,187 +0,0 @@
|
||||||
// ReSharper disable RedundantUsingDirective
|
|
||||||
using System;
|
|
||||||
using AutoMoq;
|
|
||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace NzbDrone.App.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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// ReSharper disable CheckNamespace
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
[SetUpFixture]
|
||||||
|
public class Fixtures : LoggingFixtures
|
||||||
|
{
|
||||||
|
}
|
|
@ -38,15 +38,6 @@
|
||||||
<Reference Include="FluentAssertions, Version=1.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
<Reference Include="FluentAssertions, Version=1.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll</HintPath>
|
<HintPath>..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll</HintPath>
|
||||||
</Reference>
|
</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">
|
<Reference Include="Moq">
|
||||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -72,11 +63,8 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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="CentralDispatchTests.cs" />
|
<Compile Include="CentralDispatchTests.cs" />
|
||||||
|
<Compile Include="Fixtures.cs" />
|
||||||
<Compile Include="RouterTest.cs" />
|
<Compile Include="RouterTest.cs" />
|
||||||
<Compile Include="MonitoringProviderTest.cs" />
|
<Compile Include="MonitoringProviderTest.cs" />
|
||||||
<Compile Include="ConfigProviderTest.cs" />
|
<Compile Include="ConfigProviderTest.cs" />
|
||||||
|
@ -93,6 +81,10 @@
|
||||||
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
||||||
<Name>NzbDrone.Common</Name>
|
<Name>NzbDrone.Common</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\NzbDrone.Test.Common\NzbDrone.Test.Common.csproj">
|
||||||
|
<Project>{CADDFCE0-7509-4430-8364-2074E1EEFCA2}</Project>
|
||||||
|
<Name>NzbDrone.Test.Common</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\NzbDrone.Test.Dummy\NzbDrone.Test.Dummy.csproj">
|
<ProjectReference Include="..\NzbDrone.Test.Dummy\NzbDrone.Test.Dummy.csproj">
|
||||||
<Project>{FAFB5948-A222-4CF6-AD14-026BE7564802}</Project>
|
<Project>{FAFB5948-A222-4CF6-AD14-026BE7564802}</Project>
|
||||||
<Name>NzbDrone.Test.Dummy</Name>
|
<Name>NzbDrone.Test.Dummy</Name>
|
||||||
|
@ -102,9 +94,6 @@
|
||||||
<Name>NzbDrone</Name>
|
<Name>NzbDrone</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="AutoMoq\License.txt" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="CommonServiceLocator" version="1.0" />
|
<package id="FluentAssertions" version="1.5.0.0" />
|
||||||
<package id="Moq" version="4.0.10827" />
|
<package id="Moq" version="4.0.10827" />
|
||||||
<package id="NBuilder" version="3.0.1" />
|
<package id="NBuilder" version="3.0.1" />
|
||||||
<package id="Ninject" version="2.2.1.4" />
|
<package id="Ninject" version="2.2.1.4" />
|
||||||
<package id="NUnit" version="2.5.10.11092" />
|
<package id="NUnit" version="2.5.10.11092" />
|
||||||
<package id="Unity" version="2.1.505.0" />
|
|
||||||
<package id="FluentAssertions" version="1.5.0.0" />
|
|
||||||
</packages>
|
</packages>
|
|
@ -0,0 +1,65 @@
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.Test
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class DiskProviderTests
|
||||||
|
{
|
||||||
|
DirectoryInfo BinFolder;
|
||||||
|
DirectoryInfo BinFolderCopy;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
var binRoot = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.Parent;
|
||||||
|
BinFolder = new DirectoryInfo(Path.Combine(binRoot.FullName, "bin"));
|
||||||
|
BinFolderCopy = new DirectoryInfo(Path.Combine(binRoot.FullName, "bin_copy"));
|
||||||
|
|
||||||
|
if (BinFolderCopy.Exists)
|
||||||
|
{
|
||||||
|
BinFolderCopy.Delete(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CopyFolder_should_copy_folder()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
var diskProvider = new DiskProvider();
|
||||||
|
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
BinFolder.Refresh();
|
||||||
|
BinFolderCopy.Refresh();
|
||||||
|
|
||||||
|
BinFolder.GetFiles("*.*", SearchOption.AllDirectories)
|
||||||
|
.Should().HaveSameCount(BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CopyFolder_should_overright_existing_folder()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
var diskProvider = new DiskProvider();
|
||||||
|
|
||||||
|
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
|
||||||
|
|
||||||
|
//Delete Random File
|
||||||
|
BinFolderCopy.GetFiles().First().Delete();
|
||||||
|
|
||||||
|
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
BinFolder.Refresh();
|
||||||
|
BinFolderCopy.Refresh();
|
||||||
|
|
||||||
|
BinFolder.GetFiles("*.*", SearchOption.AllDirectories)
|
||||||
|
.Should().HaveSameCount(BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,5 +40,11 @@ namespace NzbDrone.Common.Test
|
||||||
enviromentController.ApplicationPath.Should().NotBeBlank();
|
enviromentController.ApplicationPath.Should().NotBeBlank();
|
||||||
Path.IsPathRooted(enviromentController.ApplicationPath).Should().BeTrue("Path is not rooted");
|
Path.IsPathRooted(enviromentController.ApplicationPath).Should().BeTrue("Path is not rooted");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IsProduction_should_return_false_when_run_within_nunit()
|
||||||
|
{
|
||||||
|
EnviromentProvider.IsProduction.Should().BeFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// ReSharper disable CheckNamespace
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
[SetUpFixture]
|
||||||
|
public class Fixtures : LoggingFixtures
|
||||||
|
{
|
||||||
|
}
|
|
@ -21,6 +21,7 @@
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
|
@ -59,7 +60,9 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="DiskProviderTests.cs" />
|
||||||
<Compile Include="EnviromentProviderTest.cs" />
|
<Compile Include="EnviromentProviderTest.cs" />
|
||||||
|
<Compile Include="Fixtures.cs" />
|
||||||
<Compile Include="ProcessProviderTests.cs" />
|
<Compile Include="ProcessProviderTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ServiceControllerTests.cs" />
|
<Compile Include="ServiceControllerTests.cs" />
|
||||||
|
@ -73,14 +76,15 @@
|
||||||
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
||||||
<Name>NzbDrone.Common</Name>
|
<Name>NzbDrone.Common</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\NzbDrone.Test.Common\NzbDrone.Test.Common.csproj">
|
||||||
|
<Project>{CADDFCE0-7509-4430-8364-2074E1EEFCA2}</Project>
|
||||||
|
<Name>NzbDrone.Test.Common</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\NzbDrone.Test.Dummy\NzbDrone.Test.Dummy.csproj">
|
<ProjectReference Include="..\NzbDrone.Test.Dummy\NzbDrone.Test.Dummy.csproj">
|
||||||
<Project>{FAFB5948-A222-4CF6-AD14-026BE7564802}</Project>
|
<Project>{FAFB5948-A222-4CF6-AD14-026BE7564802}</Project>
|
||||||
<Name>NzbDrone.Test.Dummy</Name>
|
<Name>NzbDrone.Test.Dummy</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<WCFMetadata Include="Service References\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|
|
@ -77,6 +77,25 @@ namespace NzbDrone.Common
|
||||||
Directory.Move(source, destination);
|
Directory.Move(source, destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void CopyDirectory(string source, string target)
|
||||||
|
{
|
||||||
|
Logger.Trace("Copying {0} -> {1}", source, target);
|
||||||
|
|
||||||
|
var sourceFolder = new DirectoryInfo(source);
|
||||||
|
var targetFolder = new DirectoryInfo(target);
|
||||||
|
|
||||||
|
if (!targetFolder.Exists)
|
||||||
|
{
|
||||||
|
targetFolder.Create();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var file in sourceFolder.GetFiles("*.*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
var destFile = Path.Combine(target, file.Name);
|
||||||
|
file.CopyTo(destFile, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void InheritFolderPermissions(string filename)
|
public virtual void InheritFolderPermissions(string filename)
|
||||||
{
|
{
|
||||||
var fs = File.GetAccessControl(filename);
|
var fs = File.GetAccessControl(filename);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
|
@ -16,6 +17,23 @@ namespace NzbDrone.Common
|
||||||
get { return Environment.UserInteractive; }
|
get { return Environment.UserInteractive; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsProduction
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Debugger.IsAttached) return false;
|
||||||
|
|
||||||
|
var processName = Process.GetCurrentProcess().ProcessName.ToLower();
|
||||||
|
|
||||||
|
Console.WriteLine(processName);
|
||||||
|
if (processName.Contains("nunit")) return false;
|
||||||
|
if (processName.Contains("jetbrain")) return false;
|
||||||
|
if (processName.Contains("resharper")) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual string ApplicationPath
|
public virtual string ApplicationPath
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -3,7 +3,7 @@ using Exceptioneer.WindowsFormsClient;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Instrumentation
|
namespace NzbDrone.Common
|
||||||
{
|
{
|
||||||
public class ExceptioneerTarget : Target
|
public class ExceptioneerTarget : Target
|
||||||
{
|
{
|
|
@ -0,0 +1,93 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using NLog;
|
||||||
|
using NLog.Config;
|
||||||
|
using NLog.Targets;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common
|
||||||
|
{
|
||||||
|
public static class LogConfiguration
|
||||||
|
{
|
||||||
|
static LogConfiguration()
|
||||||
|
{
|
||||||
|
if (EnviromentProvider.IsProduction)
|
||||||
|
{
|
||||||
|
LogManager.ThrowExceptions = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogManager.ThrowExceptions = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LogManager.Configuration == null)
|
||||||
|
{
|
||||||
|
LogManager.Configuration = new LoggingConfiguration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterConsoleLogger(LogLevel minLevel, string loggerNamePattern = "*")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var consoleTarget = new ConsoleTarget();
|
||||||
|
consoleTarget.Layout = "${message} ${exception}";
|
||||||
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
||||||
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule(loggerNamePattern, minLevel, consoleTarget));
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
|
||||||
|
if (LogManager.ThrowExceptions)
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterUdpLogger()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var udpTarget = new ChainsawTarget();
|
||||||
|
udpTarget.Address = "udp://127.0.0.1:20480";
|
||||||
|
udpTarget.IncludeCallSite = true;
|
||||||
|
udpTarget.IncludeSourceInfo = true;
|
||||||
|
udpTarget.IncludeNLogData = true;
|
||||||
|
udpTarget.IncludeNdc = true;
|
||||||
|
LogManager.Configuration.AddTarget(udpTarget.GetType().Name, udpTarget);
|
||||||
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, udpTarget));
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
|
||||||
|
if (LogManager.ThrowExceptions)
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterExceptioneer()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var exTarget = new ExceptioneerTarget();
|
||||||
|
LogManager.Configuration.AddTarget("Exceptioneer", exTarget);
|
||||||
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Error, exTarget));
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Reload()
|
||||||
|
{
|
||||||
|
LogManager.Configuration.Reload();
|
||||||
|
LogManager.ReconfigExistingLoggers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
|
@ -31,6 +32,9 @@
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Exceptioneer.WindowsFormsClient">
|
||||||
|
<HintPath>..\Libraries\Exceptioneer.WindowsFormsClient.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="NLog">
|
<Reference Include="NLog">
|
||||||
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
|
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -48,6 +52,8 @@
|
||||||
<Compile Include="ConsoleProvider.cs" />
|
<Compile Include="ConsoleProvider.cs" />
|
||||||
<Compile Include="DiskProvider.cs" />
|
<Compile Include="DiskProvider.cs" />
|
||||||
<Compile Include="EnviromentProvider.cs" />
|
<Compile Include="EnviromentProvider.cs" />
|
||||||
|
<Compile Include="ExceptioneerTarget.cs" />
|
||||||
|
<Compile Include="LogConfiguration.cs" />
|
||||||
<Compile Include="Model\ProcessInfo.cs" />
|
<Compile Include="Model\ProcessInfo.cs" />
|
||||||
<Compile Include="ProcessProvider.cs" />
|
<Compile Include="ProcessProvider.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|
|
@ -3,7 +3,9 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
using NLog;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Instrumentation;
|
||||||
using NzbDrone.Core.Providers;
|
using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.Indexer;
|
using NzbDrone.Core.Providers.Indexer;
|
||||||
using NzbDrone.Core.Providers.Jobs;
|
using NzbDrone.Core.Providers.Jobs;
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
// ReSharper disable RedundantUsingDirective
|
using System;
|
||||||
// ReSharper disable RedundantUsingDirective
|
|
||||||
using System;
|
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
|
@ -1,166 +0,0 @@
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
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.
|
|
|
@ -1,84 +0,0 @@
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +1,17 @@
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using NLog;
|
// ReSharper disable CheckNamespace
|
||||||
using NLog.Config;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Providers;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
[SetUpFixture]
|
[SetUpFixture]
|
||||||
public class Fixtures
|
public class Fixtures : LoggingFixtures
|
||||||
{
|
{
|
||||||
[TearDown]
|
|
||||||
public void TearDown()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
try
|
var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
||||||
{
|
foreach (var file in oldDbFiles)
|
||||||
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().AppPath, "log.config"), false);
|
|
||||||
LogManager.ThrowExceptions = true;
|
|
||||||
|
|
||||||
var exceptionVerification = new ExceptionVerification();
|
|
||||||
LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification);
|
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, exceptionVerification));
|
|
||||||
LogManager.Configuration.Reload();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Unable to configure logging. " + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
|
||||||
foreach (var file in filesToDelete)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,9 +12,6 @@ using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Framework
|
namespace NzbDrone.Core.Test.Framework
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Provides the standard Mocks needed for a typical test
|
|
||||||
/// </summary>
|
|
||||||
internal static class MockLib
|
internal static class MockLib
|
||||||
{
|
{
|
||||||
private const string DbTemplateName = "_dbtemplate.sdf";
|
private const string DbTemplateName = "_dbtemplate.sdf";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Providers.Jobs;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Framework
|
namespace NzbDrone.Core.Test.Framework
|
||||||
{
|
{
|
||||||
|
@ -9,17 +9,19 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
{
|
{
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public virtual void Setup()
|
public virtual void SetupBase()
|
||||||
{
|
{
|
||||||
ExceptionVerification.Reset();
|
ExceptionVerification.Reset();
|
||||||
if (Directory.Exists(TempFolder))
|
if (Directory.Exists(TempFolder))
|
||||||
{
|
{
|
||||||
Directory.Delete(TempFolder, true);
|
Directory.Delete(TempFolder, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Directory.CreateDirectory(TempFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
public void TearDown()
|
public void TearDownBase()
|
||||||
{
|
{
|
||||||
ExceptionVerification.AssertNoUnexcpectedLogs();
|
ExceptionVerification.AssertNoUnexcpectedLogs();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +29,7 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
|
|
||||||
protected string TempFolder
|
protected string TempFolder
|
||||||
{
|
{
|
||||||
get { return Path.Combine(Directory.GetCurrentDirectory(), "_temp"); }
|
get { return Path.Combine(Directory.GetCurrentDirectory(), "temp"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string GetTestFilePath(string fileName)
|
protected string GetTestFilePath(string fileName)
|
||||||
|
|
|
@ -16,6 +16,7 @@ using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Repository.Quality;
|
using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Core.Test.ProviderTests;
|
using NzbDrone.Core.Test.ProviderTests;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test
|
namespace NzbDrone.Core.Test
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@ using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.Jobs;
|
using NzbDrone.Core.Providers.Jobs;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.JobTests
|
namespace NzbDrone.Core.Test.JobTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@ using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.Jobs;
|
using NzbDrone.Core.Providers.Jobs;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.JobTests
|
namespace NzbDrone.Core.Test.JobTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,17 +43,6 @@
|
||||||
<Reference Include="FluentAssertions, Version=1.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
<Reference Include="FluentAssertions, Version=1.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll</HintPath>
|
<HintPath>..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.Practices.Unity.Configuration, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.Configuration.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -126,14 +115,6 @@
|
||||||
<Compile Include="JobTests\DiskScanJobTest.cs" />
|
<Compile Include="JobTests\DiskScanJobTest.cs" />
|
||||||
<Compile Include="IndexerTests.cs" />
|
<Compile Include="IndexerTests.cs" />
|
||||||
<Compile Include="ProviderTests\InventoryProvider_QualityNeededTest.cs" />
|
<Compile Include="ProviderTests\InventoryProvider_QualityNeededTest.cs" />
|
||||||
<Compile Include="Framework\AutoMoq\AutoMoqer.cs" />
|
|
||||||
<Compile Include="Framework\AutoMoq\Unity\AutoMockingBuilderStrategy.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Framework\AutoMoq\Unity\AutoMockingContainerExtension.cs">
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Framework\ExceptionVerification.cs" />
|
|
||||||
<Compile Include="ProviderTests\JobProviderTest.cs" />
|
<Compile Include="ProviderTests\JobProviderTest.cs" />
|
||||||
<Compile Include="QualityTest.cs" />
|
<Compile Include="QualityTest.cs" />
|
||||||
<Compile Include="ProviderTests\RootDirProviderTest.cs" />
|
<Compile Include="ProviderTests\RootDirProviderTest.cs" />
|
||||||
|
@ -153,10 +134,18 @@
|
||||||
<Compile Include="ProviderTests\TvDbProviderTest.cs" />
|
<Compile Include="ProviderTests\TvDbProviderTest.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj">
|
||||||
|
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
||||||
|
<Name>NzbDrone.Common</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
|
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
|
||||||
<Project>{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}</Project>
|
<Project>{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}</Project>
|
||||||
<Name>NzbDrone.Core</Name>
|
<Name>NzbDrone.Core</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\NzbDrone.Test.Common\NzbDrone.Test.Common.csproj">
|
||||||
|
<Project>{CADDFCE0-7509-4430-8364-2074E1EEFCA2}</Project>
|
||||||
|
<Name>NzbDrone.Test.Common</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="App_Data\Config.xml">
|
<Content Include="App_Data\Config.xml">
|
||||||
|
@ -181,7 +170,6 @@
|
||||||
<Content Include="Files\RSS\SizeParsing\nzbsrus.xml">
|
<Content Include="Files\RSS\SizeParsing\nzbsrus.xml">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="Framework\AutoMoq\License.txt" />
|
|
||||||
<Content Include="Files\Feed.nzbmatrix.com.xml">
|
<Content Include="Files\Feed.nzbmatrix.com.xml">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
|
|
@ -8,6 +8,7 @@ using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@ using NzbDrone.Core.Providers.Core;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Repository.Quality;
|
using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
private QualityType qualityType;
|
private QualityType qualityType;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public new void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
parseResultMulti = new EpisodeParseResult
|
parseResultMulti = new EpisodeParseResult
|
||||||
{
|
{
|
||||||
|
@ -66,7 +66,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
.With(q => q.QualityTypeId = 1)
|
.With(q => q.QualityTypeId = 1)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
base.Setup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -68,8 +68,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
.With(c => c.Monitored = true)
|
.With(c => c.Monitored = true)
|
||||||
.With(d => d.CleanTitle = parseResultMulti.CleanTitle)
|
.With(d => d.CleanTitle = parseResultMulti.CleanTitle)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
base.Setup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -102,9 +102,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
/* parseResultSingle.Episodes.Add(episode);
|
/* parseResultSingle.Episodes.Add(episode);
|
||||||
parseResultMulti.Episodes.Add(episode);
|
parseResultMulti.Episodes.Add(episode);
|
||||||
parseResultMulti.Episodes.Add(episode2);*/
|
parseResultMulti.Episodes.Add(episode2);*/
|
||||||
|
|
||||||
|
|
||||||
base.Setup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -10,6 +10,7 @@ using NzbDrone.Core.Model;
|
||||||
using NzbDrone.Core.Model.Notification;
|
using NzbDrone.Core.Model.Notification;
|
||||||
using NzbDrone.Core.Providers.Jobs;
|
using NzbDrone.Core.Providers.Jobs;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,8 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Core.Instrumentation;
|
using NzbDrone.Core.Instrumentation;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
|
@ -20,8 +22,18 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
public class LogProviderTest : TestBase
|
public class LogProviderTest : TestBase
|
||||||
{
|
{
|
||||||
|
|
||||||
private const string loggerName ="Core.Test.ProviderTests.LogProviderTest";
|
private const string loggerName = "Core.Test.ProviderTests.LogProviderTest";
|
||||||
|
|
||||||
|
private static IDatabase db;
|
||||||
|
Logger Logger;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
db = MockLib.GetEmptyDatabase(true);
|
||||||
|
LogConfiguration.RegisterDatabaseLogger(new DatabaseTarget(db));
|
||||||
|
Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void write_log()
|
public void write_log()
|
||||||
|
@ -29,17 +41,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
//setup
|
//setup
|
||||||
var message = Guid.NewGuid().ToString();
|
var message = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
var db = MockLib.GetEmptyDatabase(true);
|
|
||||||
|
|
||||||
var sonicTarget = new DatabaseTarget(db);
|
|
||||||
|
|
||||||
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
|
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget));
|
|
||||||
LogManager.Configuration.Reload();
|
|
||||||
|
|
||||||
Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
//Act
|
|
||||||
|
|
||||||
Logger.Info(message);
|
Logger.Info(message);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
|
@ -66,17 +67,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
message += Guid.NewGuid();
|
message += Guid.NewGuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
var db = MockLib.GetEmptyDatabase(true);
|
|
||||||
|
|
||||||
var sonicTarget = new DatabaseTarget(db);
|
|
||||||
|
|
||||||
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
|
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget));
|
|
||||||
LogManager.Configuration.Reload();
|
|
||||||
|
|
||||||
Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
//Act
|
//Act
|
||||||
|
|
||||||
Logger.Info(message);
|
Logger.Info(message);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
|
@ -92,25 +84,12 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void clearLog()
|
public void clearLog()
|
||||||
{
|
{
|
||||||
//setup
|
|
||||||
var db = MockLib.GetEmptyDatabase(true);
|
|
||||||
|
|
||||||
var sonicTarget = new DatabaseTarget(db);
|
|
||||||
|
|
||||||
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
|
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget));
|
|
||||||
LogManager.Configuration.Reload();
|
|
||||||
|
|
||||||
Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
//Act
|
//Act
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
Logger.Info("Test");
|
Logger.Info("Test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
var provider = new LogProvider(db);
|
var provider = new LogProvider(db);
|
||||||
provider.GetAllLogs().Should().HaveCount(10);
|
provider.GetAllLogs().Should().HaveCount(10);
|
||||||
|
@ -124,16 +103,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
//setup
|
//setup
|
||||||
var message = Guid.NewGuid().ToString();
|
var message = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
var db = MockLib.GetEmptyDatabase(true);
|
|
||||||
|
|
||||||
var sonicTarget = new DatabaseTarget(db);
|
|
||||||
|
|
||||||
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
|
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget));
|
|
||||||
LogManager.Configuration.Reload();
|
|
||||||
|
|
||||||
Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
|
|
||||||
var ex = new InvalidOperationException("Fake Exception");
|
var ex = new InvalidOperationException("Fake Exception");
|
||||||
//Act
|
//Act
|
||||||
|
|
||||||
|
@ -158,16 +127,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
//setup
|
//setup
|
||||||
var message = String.Empty;
|
var message = String.Empty;
|
||||||
|
|
||||||
var db = MockLib.GetEmptyDatabase(true);
|
|
||||||
|
|
||||||
var sonicTarget = new DatabaseTarget(db);
|
|
||||||
|
|
||||||
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
|
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, sonicTarget));
|
|
||||||
LogManager.Configuration.Reload();
|
|
||||||
|
|
||||||
Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
|
|
||||||
var ex = new InvalidOperationException("Fake Exception");
|
var ex = new InvalidOperationException("Fake Exception");
|
||||||
//Act
|
//Act
|
||||||
|
|
||||||
|
@ -189,9 +148,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void null_string_as_arg_should_not_fail()
|
public void null_string_as_arg_should_not_fail()
|
||||||
{
|
{
|
||||||
//setup
|
|
||||||
|
|
||||||
Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
var epFile = new EpisodeFile();
|
var epFile = new EpisodeFile();
|
||||||
Logger.Trace("File {0} no longer exists on disk. removing from database.", epFile.Path);
|
Logger.Trace("File {0} no longer exists on disk. removing from database.", epFile.Path);
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,7 @@ using NzbDrone.Core.Providers.Core;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Repository.Quality;
|
using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,7 @@ using NzbDrone.Core.Providers.Indexer;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Repository.Quality;
|
using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,7 @@ using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.Indexer;
|
using NzbDrone.Core.Providers.Indexer;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
private Series series;
|
private Series series;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public new void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
episodes = Builder<Episode>.CreateListOfSize(6)
|
episodes = Builder<Episode>.CreateListOfSize(6)
|
||||||
.All()
|
.All()
|
||||||
|
@ -42,8 +42,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
series = Builder<Series>.CreateNew().With(s => s.SeriesId = 1).Build();
|
series = Builder<Series>.CreateNew().With(s => s.SeriesId = 1).Build();
|
||||||
|
|
||||||
base.Setup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -28,11 +28,8 @@ namespace NzbDrone.Core.Test
|
||||||
|
|
||||||
|
|
||||||
[TestFixtureSetUp]
|
[TestFixtureSetUp]
|
||||||
public new void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
base.Setup();
|
|
||||||
db = MockLib.GetEmptyDatabase();
|
db = MockLib.GetEmptyDatabase();
|
||||||
int currentFileId = 0;
|
int currentFileId = 0;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="AutoMoq" version="1.3.1.3" />
|
<package id="AutoMoq" version="1.3.1.3" />
|
||||||
<package id="CommonServiceLocator" version="1.0" />
|
<package id="FluentAssertions" version="1.5.0.0" />
|
||||||
<package id="Moq" version="4.0.10827" />
|
<package id="Moq" version="4.0.10827" />
|
||||||
<package id="NBuilder" version="3.0.1" />
|
<package id="NBuilder" version="3.0.1" />
|
||||||
<package id="Ninject" version="2.2.1.4" />
|
<package id="Ninject" version="2.2.1.4" />
|
||||||
|
<package id="NLog" version="2.0.0.2000" />
|
||||||
<package id="NUnit" version="2.5.10.11092" />
|
<package id="NUnit" version="2.5.10.11092" />
|
||||||
<package id="SqlServerCompact" version="4.0.8482.1" />
|
<package id="SqlServerCompact" version="4.0.8482.1" />
|
||||||
<package id="Unity" version="2.1.505.0" />
|
|
||||||
<package id="FluentAssertions" version="1.5.0.0" />
|
|
||||||
<package id="NLog" version="2.0.0.2000" />
|
|
||||||
</packages>
|
</packages>
|
|
@ -42,7 +42,7 @@ namespace NzbDrone.Core
|
||||||
|
|
||||||
MigrationsHelper.Run(Connection.MainConnectionString, true);
|
MigrationsHelper.Run(Connection.MainConnectionString, true);
|
||||||
|
|
||||||
LogConfiguration.StartDbLogging();
|
LogConfiguration.RegisterDatabaseLogger(_kernel.Get<DatabaseTarget>());
|
||||||
|
|
||||||
_kernel.Get<QualityProvider>().SetupDefaultProfiles();
|
_kernel.Get<QualityProvider>().SetupDefaultProfiles();
|
||||||
_kernel.Get<QualityTypeProvider>().SetupDefault();
|
_kernel.Get<QualityTypeProvider>().SetupDefault();
|
||||||
|
|
|
@ -3,6 +3,7 @@ using Ninject;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
using NLog.Targets.Wrappers;
|
using NLog.Targets.Wrappers;
|
||||||
|
using NzbDrone.Common;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Instrumentation
|
namespace NzbDrone.Core.Instrumentation
|
||||||
|
@ -18,19 +19,15 @@ namespace NzbDrone.Core.Instrumentation
|
||||||
_database = database;
|
_database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected override void Write(LogEventInfo logEvent)
|
protected override void Write(LogEventInfo logEvent)
|
||||||
{
|
{
|
||||||
var log = new Log();
|
var log = new Log();
|
||||||
log.Time = logEvent.TimeStamp;
|
log.Time = logEvent.TimeStamp;
|
||||||
log.Message = logEvent.FormattedMessage;
|
log.Message = logEvent.FormattedMessage;
|
||||||
|
|
||||||
if (logEvent.UserStackFrame != null)
|
log.Method = logEvent.UserStackFrame.GetMethod().Name;
|
||||||
{
|
|
||||||
log.Method = logEvent.UserStackFrame.GetMethod().Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Logger = logEvent.LoggerName;
|
log.Logger = logEvent.LoggerName;
|
||||||
|
|
||||||
if (log.Logger.StartsWith("NzbDrone."))
|
if (log.Logger.StartsWith("NzbDrone."))
|
||||||
|
@ -57,7 +54,6 @@ namespace NzbDrone.Core.Instrumentation
|
||||||
|
|
||||||
log.Level = logEvent.Level.Name;
|
log.Level = logEvent.Level.Name;
|
||||||
|
|
||||||
|
|
||||||
_database.Insert(log);
|
_database.Insert(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Diagnostics;
|
using System.IO;
|
||||||
using System.IO;
|
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
|
@ -9,32 +8,27 @@ namespace NzbDrone.Core.Instrumentation
|
||||||
{
|
{
|
||||||
public static class LogConfiguration
|
public static class LogConfiguration
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Setup()
|
public static void Setup()
|
||||||
{
|
{
|
||||||
if (Debugger.IsAttached)
|
if (Common.EnviromentProvider.IsProduction)
|
||||||
{
|
{
|
||||||
LogManager.ThrowExceptions = true;
|
LogManager.ThrowExceptions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().AppPath, "log.config"),
|
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().AppPath, "log.config"), false);
|
||||||
false);
|
|
||||||
|
|
||||||
LogManager.ConfigurationReloaded += ((s, e) => StartDbLogging());
|
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
|
||||||
|
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
|
||||||
|
|
||||||
|
LogManager.ConfigurationReloaded += ((s, e) => RegisterDatabaseLogger(CentralDispatch.NinjectKernel.Get<DatabaseTarget>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StartDbLogging()
|
public static void RegisterDatabaseLogger(DatabaseTarget databaseTarget)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
LogManager.Configuration.AddTarget("DbLogger", databaseTarget);
|
||||||
#else
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, databaseTarget));
|
||||||
var exTarget = new ExceptioneerTarget();
|
Common.LogConfiguration.Reload();
|
||||||
LogManager.Configuration.AddTarget("Exceptioneer", exTarget);
|
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Error, exTarget));
|
|
||||||
#endif
|
|
||||||
var sonicTarget = CentralDispatch.NinjectKernel.Get<DatabaseTarget>();
|
|
||||||
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
|
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, sonicTarget));
|
|
||||||
|
|
||||||
LogManager.Configuration.Reload();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -189,7 +189,6 @@
|
||||||
<Compile Include="Helpers\SortHelper.cs" />
|
<Compile Include="Helpers\SortHelper.cs" />
|
||||||
<Compile Include="Instrumentation\LogProvider.cs" />
|
<Compile Include="Instrumentation\LogProvider.cs" />
|
||||||
<Compile Include="Instrumentation\DatabaseTarget.cs" />
|
<Compile Include="Instrumentation\DatabaseTarget.cs" />
|
||||||
<Compile Include="Instrumentation\ExceptioneerTarget.cs" />
|
|
||||||
<Compile Include="Instrumentation\NlogWriter.cs" />
|
<Compile Include="Instrumentation\NlogWriter.cs" />
|
||||||
<Compile Include="Datastore\PetaPoco\PetaPoco.cs" />
|
<Compile Include="Datastore\PetaPoco\PetaPoco.cs" />
|
||||||
<Compile Include="Model\AtomicParsleyTitleType.cs" />
|
<Compile Include="Model\AtomicParsleyTitleType.cs" />
|
||||||
|
@ -336,7 +335,12 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="NzbDrone.jpg" />
|
<EmbeddedResource Include="NzbDrone.jpg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj">
|
||||||
|
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
||||||
|
<Name>NzbDrone.Common</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
@ -8,7 +7,6 @@ using NzbDrone.Core.Providers.Core;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Repository.Quality;
|
using NzbDrone.Core.Repository.Quality;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
using TvdbLib.Data;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers
|
namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// ReSharper disable RedundantUsingDirective
|
// ReSharper disable RedundantUsingDirective
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -6,7 +7,7 @@ using NLog;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Framework
|
namespace NzbDrone.Test.Common
|
||||||
{
|
{
|
||||||
public class ExceptionVerification : Target
|
public class ExceptionVerification : Target
|
||||||
{
|
{
|
||||||
|
@ -20,12 +21,12 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Reset()
|
public static void Reset()
|
||||||
{
|
{
|
||||||
_logs = new List<LogEventInfo>();
|
_logs = new List<LogEventInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void AssertNoUnexcpectedLogs()
|
public static void AssertNoUnexcpectedLogs()
|
||||||
{
|
{
|
||||||
ExcpectedFatals(0);
|
ExcpectedFatals(0);
|
||||||
ExcpectedErrors(0);
|
ExcpectedErrors(0);
|
||||||
|
@ -47,32 +48,32 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void ExcpectedErrors(int count)
|
public static void ExcpectedErrors(int count)
|
||||||
{
|
{
|
||||||
Excpected(LogLevel.Error, count);
|
Excpected(LogLevel.Error, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void ExcpectedFatals(int count)
|
public static void ExcpectedFatals(int count)
|
||||||
{
|
{
|
||||||
Excpected(LogLevel.Fatal, count);
|
Excpected(LogLevel.Fatal, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void ExcpectedWarns(int count)
|
public static void ExcpectedWarns(int count)
|
||||||
{
|
{
|
||||||
Excpected(LogLevel.Warn, count);
|
Excpected(LogLevel.Warn, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void IgnoreWarns()
|
public static void IgnoreWarns()
|
||||||
{
|
{
|
||||||
Ignore(LogLevel.Warn);
|
Ignore(LogLevel.Warn);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void IgnoreErrors()
|
public static void IgnoreErrors()
|
||||||
{
|
{
|
||||||
Ignore(LogLevel.Error);
|
Ignore(LogLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void MarkInconclusive(Type exception)
|
public static void MarkInconclusive(Type exception)
|
||||||
{
|
{
|
||||||
var inconclusiveLogs = _logs.Where(l => l.Exception.GetType() == exception).ToList();
|
var inconclusiveLogs = _logs.Where(l => l.Exception.GetType() == exception).ToList();
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
using NLog;
|
||||||
|
using NLog.Config;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Test.Common
|
||||||
|
{
|
||||||
|
public abstract class LoggingFixtures
|
||||||
|
{
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUpBase()
|
||||||
|
{
|
||||||
|
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
|
||||||
|
LogConfiguration.RegisterUdpLogger();
|
||||||
|
|
||||||
|
RegisterExceptionVerification();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RegisterExceptionVerification()
|
||||||
|
{
|
||||||
|
var exceptionVerification = new ExceptionVerification();
|
||||||
|
LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification);
|
||||||
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, exceptionVerification));
|
||||||
|
LogConfiguration.Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?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>{CADDFCE0-7509-4430-8364-2074E1EEFCA2}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>NzbDrone.Test.Common</RootNamespace>
|
||||||
|
<AssemblyName>NzbDrone.Test.Common</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>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
</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="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>
|
||||||
|
<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.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="AutoMoq\AutoMoqer.cs" />
|
||||||
|
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
|
||||||
|
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
|
||||||
|
<Compile Include="ExceptionVerification.cs" />
|
||||||
|
<Compile Include="LoggingFixtures.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="AutoMoq\License.txt" />
|
||||||
|
</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>
|
||||||
|
</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>
|
|
@ -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.Test.Common")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Microsoft")]
|
||||||
|
[assembly: AssemblyProduct("NzbDrone.Test.Common")]
|
||||||
|
[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("f3e91f6e-d01d-4f20-8255-147cc10f04e3")]
|
||||||
|
|
||||||
|
// 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")]
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="CommonServiceLocator" version="1.0" />
|
||||||
|
<package id="Moq" version="4.0.10827" />
|
||||||
|
<package id="NLog" version="2.0.0.2000" />
|
||||||
|
<package id="NUnit" version="2.5.10.11092" />
|
||||||
|
<package id="Unity" version="2.1.505.0" />
|
||||||
|
</packages>
|
|
@ -1,166 +0,0 @@
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,187 +0,0 @@
|
||||||
// ReSharper disable RedundantUsingDirective
|
|
||||||
using System;
|
|
||||||
using AutoMoq;
|
|
||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace NzbDrone.App.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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
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.
|
|
|
@ -1,84 +0,0 @@
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// ReSharper disable CheckNamespace
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
[SetUpFixture]
|
||||||
|
public class Fixtures : LoggingFixtures
|
||||||
|
{
|
||||||
|
}
|
|
@ -44,15 +44,6 @@
|
||||||
<Reference Include="FluentAssertions">
|
<Reference Include="FluentAssertions">
|
||||||
<HintPath>..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll</HintPath>
|
<HintPath>..\packages\FluentAssertions.1.5.0.0\Lib\.NetFramework 4.0\FluentAssertions.dll</HintPath>
|
||||||
</Reference>
|
</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">
|
<Reference Include="Moq">
|
||||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -74,10 +65,7 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AutoMoq\AutoMoqer.cs" />
|
<Compile Include="Fixtures.cs" />
|
||||||
<Compile Include="AutoMoq\AutoMoqerTest.cs" />
|
|
||||||
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
|
|
||||||
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
|
|
||||||
<Compile Include="UpdateProviderVerifyTest.cs" />
|
<Compile Include="UpdateProviderVerifyTest.cs" />
|
||||||
<Compile Include="UpdateProviderStartTest.cs" />
|
<Compile Include="UpdateProviderStartTest.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
@ -90,14 +78,15 @@
|
||||||
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
||||||
<Name>NzbDrone.Common</Name>
|
<Name>NzbDrone.Common</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\NzbDrone.Test.Common\NzbDrone.Test.Common.csproj">
|
||||||
|
<Project>{CADDFCE0-7509-4430-8364-2074E1EEFCA2}</Project>
|
||||||
|
<Name>NzbDrone.Test.Common</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\NzbDrone.Update\NzbDrone.Update.csproj">
|
<ProjectReference Include="..\NzbDrone.Update\NzbDrone.Update.csproj">
|
||||||
<Project>{4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}</Project>
|
<Project>{4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}</Project>
|
||||||
<Name>NzbDrone.Update</Name>
|
<Name>NzbDrone.Update</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="AutoMoq\License.txt" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="CommonServiceLocator" version="1.0" />
|
|
||||||
<package id="FluentAssertions" version="1.5.0.0" />
|
<package id="FluentAssertions" version="1.5.0.0" />
|
||||||
<package id="Moq" version="4.0.10827" />
|
<package id="Moq" version="4.0.10827" />
|
||||||
<package id="NBuilder" version="3.0.1" />
|
<package id="NBuilder" version="3.0.1" />
|
||||||
<package id="NUnit" version="2.5.10.11092" />
|
<package id="NUnit" version="2.5.10.11092" />
|
||||||
<package id="Unity" version="2.1.505.0" />
|
|
||||||
</packages>
|
</packages>
|
|
@ -10,17 +10,15 @@ namespace NzbDrone.Update.Providers
|
||||||
{
|
{
|
||||||
private readonly DiskProvider _diskProvider;
|
private readonly DiskProvider _diskProvider;
|
||||||
private readonly EnviromentProvider _enviromentProvider;
|
private readonly EnviromentProvider _enviromentProvider;
|
||||||
private readonly ConsoleProvider _consoleProvider;
|
|
||||||
private readonly ServiceProvider _serviceProvider;
|
private readonly ServiceProvider _serviceProvider;
|
||||||
private readonly ProcessProvider _processProvider;
|
private readonly ProcessProvider _processProvider;
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public UpdateProvider(DiskProvider diskProvider, EnviromentProvider enviromentProvider, ConsoleProvider consoleProvider,
|
public UpdateProvider(DiskProvider diskProvider, EnviromentProvider enviromentProvider,
|
||||||
ServiceProvider serviceProvider, ProcessProvider processProvider)
|
ServiceProvider serviceProvider, ProcessProvider processProvider)
|
||||||
{
|
{
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
_enviromentProvider = enviromentProvider;
|
_enviromentProvider = enviromentProvider;
|
||||||
_consoleProvider = consoleProvider;
|
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_processProvider = processProvider;
|
_processProvider = processProvider;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace NzbDrone.Web
|
||||||
|
|
||||||
RegisterGlobalFilters(GlobalFilters.Filters);
|
RegisterGlobalFilters(GlobalFilters.Filters);
|
||||||
|
|
||||||
Logger.Debug("Fully initialized and ready.");
|
Logger.Info("Fully initialized and ready.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IKernel CreateKernel()
|
protected override IKernel CreateKernel()
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
|
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
|
||||||
<targets>
|
<targets>
|
||||||
<target name="consoleTarget" xsi:type="Console" layout="${message} ${exception}" />
|
|
||||||
<target name="udpTarget" xsi:type="Chainsaw" address="udp://127.0.0.1:20480"
|
<target name="udpTarget" xsi:type="Chainsaw" address="udp://127.0.0.1:20480"
|
||||||
includeCallSite="true" includeSourceInfo="true" includeNLogData="true" includeNDC="true" includeMDC="true">
|
includeCallSite="true" includeSourceInfo="true" includeNLogData="true" includeNDC="true" includeMDC="true">
|
||||||
<parameter name="exception" layout="${exception:format=ToString}" xsi:type="NLogViewerParameterInfo" />
|
<parameter name="exception" layout="${exception:format=ToString}" xsi:type="NLogViewerParameterInfo" />
|
||||||
|
@ -18,9 +17,6 @@
|
||||||
</targets>
|
</targets>
|
||||||
|
|
||||||
<rules>
|
<rules>
|
||||||
<logger name="Host.*" minlevel="Trace" writeTo="consoleTarget"/>
|
|
||||||
<logger name="NzbDrone.Web.MvcApplication" minlevel="Trace" writeTo="consoleTarget"/>
|
|
||||||
<logger name="NzbDrone.Core.CentralDispatch" minlevel="Trace" writeTo="consoleTarget"/>
|
|
||||||
<logger name="*" minlevel="Debug" writeTo="udpTarget"/>
|
<logger name="*" minlevel="Debug" writeTo="udpTarget"/>
|
||||||
<logger name="*" minlevel="Off" writeTo="xmlFile"/>
|
<logger name="*" minlevel="Off" writeTo="xmlFile"/>
|
||||||
<logger name="*" minlevel="Warn" writeTo="file"/>
|
<logger name="*" minlevel="Warn" writeTo="file"/>
|
||||||
|
|
20
NzbDrone.sln
20
NzbDrone.sln
|
@ -23,6 +23,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Common", "NzbDrone
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Common.Test", "NzbDrone.Common.Test\NzbDrone.Common.Test.csproj", "{BEC74619-DDBB-4FBA-B517-D3E20AFC9997}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Common.Test", "NzbDrone.Common.Test\NzbDrone.Common.Test.csproj", "{BEC74619-DDBB-4FBA-B517-D3E20AFC9997}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Test.Common", "NzbDrone.Test.Common\NzbDrone.Test.Common.csproj", "{CADDFCE0-7509-4430-8364-2074E1EEFCA2}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test.Common", "Test.Common", "{47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -161,6 +165,18 @@ Global
|
||||||
{BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|Mixed Platforms.Build.0 = 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|x64.ActiveCfg = Release|Any CPU
|
||||||
{BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|x86.ActiveCfg = Release|Any CPU
|
{BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -168,9 +184,11 @@ Global
|
||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{193ADD3B-792B-4173-8E4C-5A3F8F0237F0} = {57A04B72-8088-4F75-A582-1158CF8291F7}
|
{193ADD3B-792B-4173-8E4C-5A3F8F0237F0} = {57A04B72-8088-4F75-A582-1158CF8291F7}
|
||||||
{C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5} = {57A04B72-8088-4F75-A582-1158CF8291F7}
|
{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}
|
{35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97} = {57A04B72-8088-4F75-A582-1158CF8291F7}
|
||||||
{BEC74619-DDBB-4FBA-B517-D3E20AFC9997} = {57A04B72-8088-4F75-A582-1158CF8291F7}
|
{BEC74619-DDBB-4FBA-B517-D3E20AFC9997} = {57A04B72-8088-4F75-A582-1158CF8291F7}
|
||||||
|
{47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97} = {57A04B72-8088-4F75-A582-1158CF8291F7}
|
||||||
|
{CADDFCE0-7509-4430-8364-2074E1EEFCA2} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}
|
||||||
|
{FAFB5948-A222-4CF6-AD14-026BE7564802} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.0\lib\NET35
|
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.0\lib\NET35
|
||||||
|
|
|
@ -43,7 +43,8 @@ namespace NzbDrone
|
||||||
|
|
||||||
private static void InitilizeApp()
|
private static void InitilizeApp()
|
||||||
{
|
{
|
||||||
_kernel.Get<ConfigProvider>().ConfigureNlog();
|
LogConfiguration.RegisterConsoleLogger(LogLevel.Debug);
|
||||||
|
LogConfiguration.RegisterUdpLogger();
|
||||||
_kernel.Get<ConfigProvider>().CreateDefaultConfigFile();
|
_kernel.Get<ConfigProvider>().CreateDefaultConfigFile();
|
||||||
Logger.Info("Start-up Path:'{0}'", _kernel.Get<EnviromentProvider>().ApplicationPath);
|
Logger.Info("Start-up Path:'{0}'", _kernel.Get<EnviromentProvider>().ApplicationPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,11 +72,6 @@ namespace NzbDrone.Providers
|
||||||
get { return (AuthenticationType)GetValueInt("AuthenticationType", 0); }
|
get { return (AuthenticationType)GetValueInt("AuthenticationType", 0); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void ConfigureNlog()
|
|
||||||
{
|
|
||||||
LogManager.Configuration = new XmlLoggingConfiguration(NlogConfigPath, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void UpdateIISConfig(string configPath)
|
public virtual void UpdateIISConfig(string configPath)
|
||||||
{
|
{
|
||||||
Logger.Info(@"Server configuration file: {0}", configPath);
|
Logger.Info(@"Server configuration file: {0}", configPath);
|
||||||
|
|
|
@ -120,7 +120,7 @@ namespace NzbDrone.Providers
|
||||||
e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called"))
|
e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (e.Data.Contains(" NzbDrone."))
|
//if (e.Data.Contains(" NzbDrone."))
|
||||||
{
|
{
|
||||||
Console.WriteLine(e.Data);
|
Console.WriteLine(e.Data);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -9,4 +9,5 @@
|
||||||
<repository path="..\NzbDrone.Update\packages.config" />
|
<repository path="..\NzbDrone.Update\packages.config" />
|
||||||
<repository path="..\NzbDrone.Common\packages.config" />
|
<repository path="..\NzbDrone.Common\packages.config" />
|
||||||
<repository path="..\NzbDrone.Common.Test\packages.config" />
|
<repository path="..\NzbDrone.Common.Test\packages.config" />
|
||||||
|
<repository path="..\NzbDrone.Test.Common\packages.config" />
|
||||||
</repositories>
|
</repositories>
|
Loading…
Reference in New Issue