Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus
Fixed CentalDispatch Conflicts.
This commit is contained in:
commit
bbd5cba272
|
@ -3,6 +3,6 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
[SetUpFixture]
|
[SetUpFixture]
|
||||||
public class Fixtures : LoggingFixtures
|
public class Fixtures : LoggingTest
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
@ -9,35 +10,21 @@ namespace NzbDrone.Common.Test
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class EnviromentProviderTest
|
public class EnviromentProviderTest
|
||||||
{
|
{
|
||||||
readonly EnviromentProvider enviromentController = new EnviromentProvider();
|
readonly EnviromentProvider enviromentProvider = new EnviromentProvider();
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Is_user_interactive_should_be_false()
|
|
||||||
{
|
|
||||||
enviromentController.IsUserInteractive.Should().BeTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Log_path_should_not_be_empty()
|
|
||||||
{
|
|
||||||
enviromentController.LogPath.Should().NotBeBlank();
|
|
||||||
Path.IsPathRooted(enviromentController.LogPath).Should().BeTrue("Path is not rooted");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void StartupPath_should_not_be_empty()
|
public void StartupPath_should_not_be_empty()
|
||||||
{
|
{
|
||||||
enviromentController.StartUpPath.Should().NotBeBlank();
|
enviromentProvider.StartUpPath.Should().NotBeBlank();
|
||||||
Path.IsPathRooted(enviromentController.StartUpPath).Should().BeTrue("Path is not rooted");
|
Path.IsPathRooted(enviromentProvider.StartUpPath).Should().BeTrue("Path is not rooted");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ApplicationPath_should_not_be_empty()
|
public void ApplicationPath_should_not_be_empty()
|
||||||
{
|
{
|
||||||
enviromentController.ApplicationPath.Should().NotBeBlank();
|
enviromentProvider.ApplicationPath.Should().NotBeBlank();
|
||||||
Path.IsPathRooted(enviromentController.ApplicationPath).Should().BeTrue("Path is not rooted");
|
Path.IsPathRooted(enviromentProvider.ApplicationPath).Should().BeTrue("Path is not rooted");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +32,7 @@ namespace NzbDrone.Common.Test
|
||||||
public void ApplicationPath_should_find_iis_in_current_folder()
|
public void ApplicationPath_should_find_iis_in_current_folder()
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(EnviromentProvider.IIS_FOLDER_NAME);
|
Directory.CreateDirectory(EnviromentProvider.IIS_FOLDER_NAME);
|
||||||
enviromentController.ApplicationPath.Should().BeEquivalentTo(Directory.GetCurrentDirectory());
|
enviromentProvider.ApplicationPath.Should().BeEquivalentTo(Directory.GetCurrentDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -53,5 +40,12 @@ namespace NzbDrone.Common.Test
|
||||||
{
|
{
|
||||||
EnviromentProvider.IsProduction.Should().BeFalse();
|
EnviromentProvider.IsProduction.Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase("0.0.0.0")]
|
||||||
|
[TestCase("1.0.0.0")]
|
||||||
|
public void Application_version_should_not_be_default(string version)
|
||||||
|
{
|
||||||
|
enviromentProvider.Version.Should().NotBe(new Version(version));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,6 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
[SetUpFixture]
|
[SetUpFixture]
|
||||||
public class Fixtures : LoggingFixtures
|
public class Fixtures : LoggingTest
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,6 @@
|
||||||
<Compile Include="EnviromentProviderTest.cs" />
|
<Compile Include="EnviromentProviderTest.cs" />
|
||||||
<Compile Include="Fixtures.cs" />
|
<Compile Include="Fixtures.cs" />
|
||||||
<Compile Include="ProcessProviderTests.cs" />
|
<Compile Include="ProcessProviderTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="ServiceControllerTests.cs" />
|
<Compile Include="ServiceControllerTests.cs" />
|
||||||
<Compile Include="WebClientTests.cs" />
|
<Compile Include="WebClientTests.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -86,6 +85,9 @@
|
||||||
<Name>NzbDrone.Test.Dummy</Name>
|
<Name>NzbDrone.Test.Dummy</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Properties\" />
|
||||||
|
</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,36 +0,0 @@
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
|
||||||
// set of attributes. Change these attribute values to modify the information
|
|
||||||
// associated with an assembly.
|
|
||||||
[assembly: AssemblyTitle("NzbDrone.Common.Test")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("Microsoft")]
|
|
||||||
[assembly: AssemblyProduct("NzbDrone.Common.Test")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
|
||||||
// to COM components. If you need to access a type in this assembly from
|
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|
||||||
[assembly: Guid("dc28491a-9f47-4823-a239-0e195d2ee42b")]
|
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
|
||||||
//
|
|
||||||
// Major Version
|
|
||||||
// Minor Version
|
|
||||||
// Build Number
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
|
||||||
// by using the '*' as shown below:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
|
@ -32,11 +32,6 @@ namespace NzbDrone.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual String LogPath
|
|
||||||
{
|
|
||||||
get { return Environment.CurrentDirectory; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool IsUserInteractive
|
public virtual bool IsUserInteractive
|
||||||
{
|
{
|
||||||
get { return Environment.UserInteractive; }
|
get { return Environment.UserInteractive; }
|
||||||
|
@ -68,25 +63,6 @@ namespace NzbDrone.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual string WebRoot
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return Path.Combine(ApplicationPath, "NzbDrone.Web");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual string AppDataPath
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var path = Path.Combine(WebRoot, "App_Data");
|
|
||||||
if (!Directory.Exists(path))
|
|
||||||
Directory.CreateDirectory(path);
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual string StartUpPath
|
public virtual string StartUpPath
|
||||||
{
|
{
|
||||||
|
@ -111,15 +87,6 @@ namespace NzbDrone.Common
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual String TempPath
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return Path.GetTempPath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool ContainsIIS(DirectoryInfo dir)
|
private static bool ContainsIIS(DirectoryInfo dir)
|
||||||
{
|
{
|
||||||
return dir.GetDirectories(IIS_FOLDER_NAME).Length != 0;
|
return dir.GetDirectories(IIS_FOLDER_NAME).Length != 0;
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace NzbDrone.Common
|
||||||
new Client
|
new Client
|
||||||
{
|
{
|
||||||
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
|
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
|
||||||
ApplicationName = "NZBDrone",
|
ApplicationName = "NzbDrone",
|
||||||
CurrentException = logEvent.Exception
|
CurrentException = logEvent.Exception
|
||||||
}.Submit();
|
}.Submit();
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ConsoleProvider.cs" />
|
<Compile Include="ConsoleProvider.cs" />
|
||||||
|
<Compile Include="PathProvider.cs" />
|
||||||
<Compile Include="DiskProvider.cs" />
|
<Compile Include="DiskProvider.cs" />
|
||||||
<Compile Include="EnviromentProvider.cs" />
|
<Compile Include="EnviromentProvider.cs" />
|
||||||
<Compile Include="ExceptioneerTarget.cs" />
|
<Compile Include="ExceptioneerTarget.cs" />
|
||||||
|
@ -57,6 +58,7 @@
|
||||||
<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" />
|
||||||
|
<Compile Include="Properties\SharedAssemblyInfo.cs" />
|
||||||
<Compile Include="ServiceProvider.cs" />
|
<Compile Include="ServiceProvider.cs" />
|
||||||
<Compile Include="WebClientProvider.cs" />
|
<Compile Include="WebClientProvider.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common
|
||||||
|
{
|
||||||
|
public class PathProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
private const string WEB_FOLDER = "NzbDrone.Web";
|
||||||
|
private const string APP_DATA = "App_Data";
|
||||||
|
|
||||||
|
private const string LOG_CONFIG_FILE = "log.config";
|
||||||
|
private const string APP_CONFIG_FILE = "config.xml";
|
||||||
|
|
||||||
|
private const string NZBDRONE_DB_FILE = "nzbdrone.sdf";
|
||||||
|
private const string LOG_DB_FILE = "log.sdf";
|
||||||
|
|
||||||
|
public const string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update";
|
||||||
|
|
||||||
|
private readonly string _applicationPath;
|
||||||
|
|
||||||
|
|
||||||
|
public PathProvider(EnviromentProvider enviromentProvider)
|
||||||
|
{
|
||||||
|
_applicationPath = enviromentProvider.ApplicationPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PathProvider()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual String LogPath
|
||||||
|
{
|
||||||
|
get { return Environment.CurrentDirectory; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string WebRoot
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Path.Combine(_applicationPath, WEB_FOLDER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string AppData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var path = Path.Combine(WebRoot, APP_DATA);
|
||||||
|
if (!Directory.Exists(path))
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string NzbDronoeDbFile
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
|
||||||
|
return Path.Combine(AppData, NZBDRONE_DB_FILE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string LogDbFile
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
|
||||||
|
return Path.Combine(AppData, LOG_DB_FILE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual String SystemTemp
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Path.GetTempPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LogConfigFile
|
||||||
|
{
|
||||||
|
get { return Path.Combine(WebRoot, LOG_CONFIG_FILE); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AppConfigFile
|
||||||
|
{
|
||||||
|
get { return Path.Combine(_applicationPath, APP_CONFIG_FILE); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string BannerPath
|
||||||
|
{
|
||||||
|
get { return Path.Combine(WebRoot, "Content", "Images", "Banners"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CacheFolder
|
||||||
|
{
|
||||||
|
get { return Path.Combine(AppData, "Cache"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string UpdateSandboxFolder
|
||||||
|
{
|
||||||
|
get { return Path.Combine(SystemTemp, UPDATE_SANDBOX_FOLDER_NAME); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,36 +1,16 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("NzbDrone.Common")]
|
[assembly: AssemblyTitle("NzbDrone.Common")]
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("Microsoft")]
|
|
||||||
[assembly: AssemblyProduct("NzbDrone.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
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
[assembly: Guid("b6eaa144-e13b-42e5-a738-c60d89c0f728")]
|
[assembly: Guid("b6eaa144-e13b-42e5-a738-c60d89c0f728")]
|
||||||
|
|
||||||
// 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
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("0.6.0.*")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("0.6.0.*")]
|
|
@ -0,0 +1,15 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("www.nzbdrone.com")]
|
||||||
|
[assembly: AssemblyProduct("NzbDrone")]
|
||||||
|
[assembly: AssemblyCopyright("GNU General Public v3")]
|
||||||
|
[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)]
|
|
@ -1,11 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
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;
|
||||||
|
@ -16,16 +13,23 @@ namespace NzbDrone.Core.Test
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
class CentralDispatchTest : TestBase
|
class CentralDispatchFixture : TestBase
|
||||||
{
|
{
|
||||||
readonly IList<Type> indexers = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(IndexerBase))).ToList();
|
readonly IList<Type> indexers = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(IndexerBase))).ToList();
|
||||||
readonly IList<Type> jobs = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IJob))).ToList();
|
readonly IList<Type> jobs = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IJob))).ToList();
|
||||||
|
|
||||||
|
private CentralDispatch centralDispatch;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
centralDispatch = new CentralDispatch();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void InitAppTest()
|
public void InitAppTest()
|
||||||
{
|
{
|
||||||
CentralDispatch.NinjectKernel.Should().NotBeNull();
|
centralDispatch.Kernel.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -38,7 +42,7 @@ namespace NzbDrone.Core.Test
|
||||||
foreach (var provider in providers)
|
foreach (var provider in providers)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Resolving " + provider.Name);
|
Console.WriteLine("Resolving " + provider.Name);
|
||||||
CentralDispatch.NinjectKernel.Get(provider).Should().NotBeNull();
|
centralDispatch.Kernel.Get(provider).Should().NotBeNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +52,7 @@ namespace NzbDrone.Core.Test
|
||||||
{
|
{
|
||||||
//Assert
|
//Assert
|
||||||
|
|
||||||
var registeredJobs = CentralDispatch.NinjectKernel.GetAll<IJob>();
|
var registeredJobs = centralDispatch.Kernel.GetAll<IJob>();
|
||||||
|
|
||||||
jobs.Should().NotBeEmpty();
|
jobs.Should().NotBeEmpty();
|
||||||
|
|
||||||
|
@ -61,7 +65,7 @@ namespace NzbDrone.Core.Test
|
||||||
{
|
{
|
||||||
//Assert
|
//Assert
|
||||||
|
|
||||||
var registeredIndexers = CentralDispatch.NinjectKernel.GetAll<IndexerBase>();
|
var registeredIndexers = centralDispatch.Kernel.GetAll<IndexerBase>();
|
||||||
|
|
||||||
indexers.Should().NotBeEmpty();
|
indexers.Should().NotBeEmpty();
|
||||||
|
|
||||||
|
@ -72,26 +76,26 @@ namespace NzbDrone.Core.Test
|
||||||
[Test]
|
[Test]
|
||||||
public void jobs_are_initialized()
|
public void jobs_are_initialized()
|
||||||
{
|
{
|
||||||
CentralDispatch.NinjectKernel.Get<JobProvider>().All().Should().HaveSameCount(jobs);
|
centralDispatch.Kernel.Get<JobProvider>().All().Should().HaveSameCount(jobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void indexers_are_initialized()
|
public void indexers_are_initialized()
|
||||||
{
|
{
|
||||||
CentralDispatch.NinjectKernel.Get<IndexerProvider>().All().Should().HaveSameCount(indexers);
|
centralDispatch.Kernel.Get<IndexerProvider>().All().Should().HaveSameCount(indexers);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void quality_profile_initialized()
|
public void quality_profile_initialized()
|
||||||
{
|
{
|
||||||
CentralDispatch.NinjectKernel.Get<QualityProvider>().All().Should().HaveCount(2);
|
centralDispatch.Kernel.Get<QualityProvider>().All().Should().HaveCount(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void JobProvider_should_be_singletone()
|
public void JobProvider_should_be_singletone()
|
||||||
{
|
{
|
||||||
var first = CentralDispatch.NinjectKernel.Get<JobProvider>();
|
var first = centralDispatch.Kernel.Get<JobProvider>();
|
||||||
var second = CentralDispatch.NinjectKernel.Get<JobProvider>();
|
var second = centralDispatch.Kernel.Get<JobProvider>();
|
||||||
|
|
||||||
first.Should().BeSameAs(second);
|
first.Should().BeSameAs(second);
|
||||||
}
|
}
|
|
@ -4,22 +4,22 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
[SetUpFixture]
|
//[SetUpFixture]
|
||||||
public class Fixtures : LoggingFixtures
|
//public class Fixtures : LoggingFixtures
|
||||||
{
|
//{
|
||||||
[SetUp]
|
// //[SetUp]
|
||||||
public void SetUp()
|
// //public void SetUp()
|
||||||
{
|
// //{
|
||||||
var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
// // var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
||||||
foreach (var file in oldDbFiles)
|
// // foreach (var file in oldDbFiles)
|
||||||
{
|
// // {
|
||||||
try
|
// // try
|
||||||
{
|
// // {
|
||||||
File.Delete(file);
|
// // File.Delete(file);
|
||||||
}
|
// // }
|
||||||
catch { }
|
// // catch { }
|
||||||
}
|
// // }
|
||||||
|
|
||||||
MockLib.CreateDataBaseTemplate();
|
// // MockLib.CreateDataBaseTemplate();
|
||||||
}
|
// //}
|
||||||
}
|
//}
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
|
|
||||||
public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
|
public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("====================DataBase====================");
|
||||||
Console.WriteLine("Cloning database from template.");
|
Console.WriteLine("Cloning database from template.");
|
||||||
|
|
||||||
if (String.IsNullOrWhiteSpace(fileName))
|
if (String.IsNullOrWhiteSpace(fileName))
|
||||||
|
@ -31,6 +32,10 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
|
|
||||||
var database = Connection.GetPetaPocoDb(connectionString);
|
var database = Connection.GetPetaPocoDb(connectionString);
|
||||||
|
|
||||||
|
Console.WriteLine("====================DataBase====================");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,52 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using AutoMoq;
|
||||||
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Ninject;
|
||||||
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Framework
|
namespace NzbDrone.Core.Test.Framework
|
||||||
{
|
{
|
||||||
public class TestBase
|
public class TestBase : LoggingTest
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
{
|
{
|
||||||
|
static TestBase()
|
||||||
|
{
|
||||||
|
var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
||||||
|
foreach (var file in oldDbFiles)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
MockLib.CreateDataBaseTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected StandardKernel LiveKernel = null;
|
||||||
|
protected AutoMoqer Mocker = null;
|
||||||
|
protected IDatabase Db = null;
|
||||||
|
|
||||||
|
protected string VirtualPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var virtualPath = Path.Combine(TempFolder, "VirtualNzbDrone");
|
||||||
|
if (!Directory.Exists(virtualPath)) Directory.CreateDirectory(virtualPath);
|
||||||
|
|
||||||
|
return virtualPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public virtual void SetupBase()
|
public virtual void SetupBase()
|
||||||
{
|
{
|
||||||
|
InitLogging();
|
||||||
|
|
||||||
ExceptionVerification.Reset();
|
ExceptionVerification.Reset();
|
||||||
if (Directory.Exists(TempFolder))
|
if (Directory.Exists(TempFolder))
|
||||||
{
|
{
|
||||||
|
@ -18,12 +54,42 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(TempFolder);
|
Directory.CreateDirectory(TempFolder);
|
||||||
|
|
||||||
|
LiveKernel = new StandardKernel();
|
||||||
|
Mocker = new AutoMoqer();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void WithStrictMocker()
|
||||||
|
{
|
||||||
|
Mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
|
if (Db != null)
|
||||||
|
{
|
||||||
|
Mocker.SetConstant(Db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void WithRealDb()
|
||||||
|
{
|
||||||
|
Db = MockLib.GetEmptyDatabase();
|
||||||
|
Mocker.SetConstant(Db);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
public void TearDownBase()
|
public void TearDownBase()
|
||||||
{
|
{
|
||||||
ExceptionVerification.AssertNoUnexcpectedLogs();
|
ExceptionVerification.AssertNoUnexcpectedLogs();
|
||||||
|
Mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
|
WebTimer.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void WithTempAsStartUpPath()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<EnviromentProvider>()
|
||||||
|
.SetupGet(c => c.ApplicationPath)
|
||||||
|
.Returns(VirtualPath);
|
||||||
|
|
||||||
|
Mocker.Resolve<PathProvider>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,14 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class BannerDownloadJobTest : TestBase
|
public class BannerDownloadJobTest : TestBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
WithStrictMocker();
|
||||||
|
WithTempAsStartUpPath();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void BannerDownload_all()
|
public void BannerDownload_all()
|
||||||
{
|
{
|
||||||
|
@ -26,28 +34,25 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
||||||
mocker.Resolve<EnviromentProvider>();
|
|
||||||
|
|
||||||
var notification = new ProgressNotification("Banner Download");
|
var notification = new ProgressNotification("Banner Download");
|
||||||
|
|
||||||
mocker.GetMock<SeriesProvider>()
|
Mocker.GetMock<SeriesProvider>()
|
||||||
.Setup(c => c.GetAllSeries())
|
.Setup(c => c.GetAllSeries())
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
Mocker.GetMock<DiskProvider>()
|
||||||
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Exactly(fakeSeries.Count));
|
Times.Exactly(fakeSeries.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,28 +65,25 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
.With(s => s.BannerUrl = null)
|
.With(s => s.BannerUrl = null)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
||||||
mocker.Resolve<EnviromentProvider>();
|
|
||||||
|
|
||||||
var notification = new ProgressNotification("Banner Download");
|
var notification = new ProgressNotification("Banner Download");
|
||||||
|
|
||||||
mocker.GetMock<SeriesProvider>()
|
Mocker.GetMock<SeriesProvider>()
|
||||||
.Setup(c => c.GetAllSeries())
|
.Setup(c => c.GetAllSeries())
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
Mocker.GetMock<DiskProvider>()
|
||||||
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Exactly(8));
|
Times.Exactly(8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,66 +94,64 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var path = Path.Combine(new EnviromentProvider().WebRoot, "Content", "Images", "Banners");
|
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
var pathProvider = Mocker.Resolve<PathProvider>();
|
||||||
mocker.Resolve<EnviromentProvider>();
|
|
||||||
|
|
||||||
var notification = new ProgressNotification("Banner Download");
|
var notification = new ProgressNotification("Banner Download");
|
||||||
|
|
||||||
mocker.GetMock<SeriesProvider>()
|
Mocker.GetMock<SeriesProvider>()
|
||||||
.Setup(c => c.GetAllSeries())
|
.Setup(c => c.GetAllSeries())
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "1.jpg")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "1.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "2.jpg")));
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "2.jpg")));
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "3.jpg")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "3.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "4.jpg")));
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "4.jpg")));
|
||||||
|
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "5.jpg")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "5.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "6.jpg")));
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "6.jpg")));
|
||||||
|
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "7.jpg")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "7.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "8.jpg")));
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "8.jpg")));
|
||||||
|
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "9.jpg")))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "9.jpg")))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "10.jpg")));
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "10.jpg")));
|
||||||
|
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
Mocker.GetMock<DiskProvider>()
|
||||||
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Exactly(fakeSeries.Count));
|
Times.Exactly(fakeSeries.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,29 +162,26 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
||||||
mocker.Resolve<EnviromentProvider>();
|
|
||||||
|
|
||||||
var notification = new ProgressNotification("Banner Download");
|
var notification = new ProgressNotification("Banner Download");
|
||||||
|
|
||||||
mocker.GetMock<SeriesProvider>()
|
Mocker.GetMock<SeriesProvider>()
|
||||||
.Setup(c => c.GetAllSeries())
|
.Setup(c => c.GetAllSeries())
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
Mocker.GetMock<DiskProvider>()
|
||||||
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Exactly(fakeSeries.Count));
|
Times.Exactly(fakeSeries.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,29 +193,26 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
.With(s => s.SeriesId = 1)
|
.With(s => s.SeriesId = 1)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
||||||
mocker.Resolve<EnviromentProvider>();
|
|
||||||
|
|
||||||
var notification = new ProgressNotification("Banner Download");
|
var notification = new ProgressNotification("Banner Download");
|
||||||
|
|
||||||
mocker.GetMock<SeriesProvider>()
|
Mocker.GetMock<SeriesProvider>()
|
||||||
.Setup(c => c.GetSeries(1))
|
.Setup(c => c.GetSeries(1))
|
||||||
.Returns(fakeSeries);
|
.Returns(fakeSeries);
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
mocker.GetMock<DiskProvider>()
|
Mocker.GetMock<DiskProvider>()
|
||||||
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
|
||||||
.Returns("");
|
.Returns("");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
|
Mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Once());
|
Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,20 +224,18 @@ namespace NzbDrone.Core.Test.JobTests
|
||||||
.With(s => s.SeriesId = 1)
|
.With(s => s.SeriesId = 1)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
||||||
|
|
||||||
var notification = new ProgressNotification("Banner Download");
|
var notification = new ProgressNotification("Banner Download");
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
||||||
.Throws(new WebException());
|
.Throws(new WebException());
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
|
Mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
mocker.VerifyAllMocks();
|
Mocker.VerifyAllMocks();
|
||||||
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
|
||||||
Times.Once());
|
Times.Once());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@
|
||||||
<Compile Include="ProviderTests\PostDownloadProviderTests\PostDownloadProviderFixture.cs" />
|
<Compile Include="ProviderTests\PostDownloadProviderTests\PostDownloadProviderFixture.cs" />
|
||||||
<Compile Include="JobTests\SearchJobTest.cs" />
|
<Compile Include="JobTests\SearchJobTest.cs" />
|
||||||
<Compile Include="ProviderTests\PostDownloadProviderTests\ProcessDownloadFixture.cs" />
|
<Compile Include="ProviderTests\PostDownloadProviderTests\ProcessDownloadFixture.cs" />
|
||||||
|
<Compile Include="ProviderTests\JobProviderTests\TestJobs.cs" />
|
||||||
<Compile Include="ProviderTests\UpdateProviderTests\PreformUpdateFixture.cs" />
|
<Compile Include="ProviderTests\UpdateProviderTests\PreformUpdateFixture.cs" />
|
||||||
<Compile Include="ProviderTests\UpdateProviderTests\GetAvilableUpdateFixture.cs" />
|
<Compile Include="ProviderTests\UpdateProviderTests\GetAvilableUpdateFixture.cs" />
|
||||||
<Compile Include="SortHelperTest.cs" />
|
<Compile Include="SortHelperTest.cs" />
|
||||||
|
@ -103,7 +104,7 @@
|
||||||
<Compile Include="JobTests\SeriesSearchJobTest.cs" />
|
<Compile Include="JobTests\SeriesSearchJobTest.cs" />
|
||||||
<Compile Include="ProviderTests\SearchProviderTest_Season.cs" />
|
<Compile Include="ProviderTests\SearchProviderTest_Season.cs" />
|
||||||
<Compile Include="ProviderTests\EventClientProviderTest.cs" />
|
<Compile Include="ProviderTests\EventClientProviderTest.cs" />
|
||||||
<Compile Include="CentralDispatchTest.cs" />
|
<Compile Include="CentralDispatchFixture.cs" />
|
||||||
<Compile Include="ProviderTests\XbmcProviderTest.cs" />
|
<Compile Include="ProviderTests\XbmcProviderTest.cs" />
|
||||||
<Compile Include="ProviderTests\DiskScanProviderTest.cs" />
|
<Compile Include="ProviderTests\DiskScanProviderTest.cs" />
|
||||||
<Compile Include="ProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" />
|
<Compile Include="ProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" />
|
||||||
|
@ -122,7 +123,7 @@
|
||||||
<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="ProviderTests\JobProviderTest.cs" />
|
<Compile Include="ProviderTests\JobProviderTests\JobProviderTest.cs" />
|
||||||
<Compile Include="QualityTest.cs" />
|
<Compile Include="QualityTest.cs" />
|
||||||
<Compile Include="ProviderTests\RootDirProviderTest.cs" />
|
<Compile Include="ProviderTests\RootDirProviderTest.cs" />
|
||||||
<Compile Include="ProviderTests\IndexerProviderTest.cs" />
|
<Compile Include="ProviderTests\IndexerProviderTest.cs" />
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using AutoMoq;
|
using AutoMoq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Core.Model;
|
using NzbDrone.Core.Model;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
@ -15,14 +16,15 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
|
WithTempAsStartUpPath();
|
||||||
|
|
||||||
//Reset config file
|
//Reset config file
|
||||||
var mocker = new AutoMoqer();
|
var configFile = Mocker.Resolve<PathProvider>().AppConfigFile;
|
||||||
var configFile = mocker.Resolve<ConfigFileProvider>().ConfigFile;
|
|
||||||
|
|
||||||
if (File.Exists(configFile))
|
if (File.Exists(configFile))
|
||||||
File.Delete(configFile);
|
File.Delete(configFile);
|
||||||
|
|
||||||
mocker.Resolve<ConfigFileProvider>().CreateDefaultConfigFile();
|
Mocker.Resolve<ConfigFileProvider>().CreateDefaultConfigFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -31,10 +33,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Port";
|
const string key = "Port";
|
||||||
const string value = "8989";
|
const string value = "8989";
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -46,10 +46,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Port";
|
const string key = "Port";
|
||||||
const int value = 8989;
|
const int value = 8989;
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -64,7 +62,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
|
@ -76,7 +74,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(true);
|
result.Should().Be(true);
|
||||||
|
@ -87,10 +85,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
const int value = 8989;
|
const int value = 8989;
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().Port;
|
var result = Mocker.Resolve<ConfigFileProvider>().Port;
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -102,13 +98,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "LaunchBrowser";
|
const string key = "LaunchBrowser";
|
||||||
const bool value = false;
|
const bool value = false;
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +112,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Port";
|
const string key = "Port";
|
||||||
const int value = 12345;
|
const int value = 12345;
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().Port;
|
var result = Mocker.Resolve<ConfigFileProvider>().Port;
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,10 +126,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Hello";
|
const string key = "Hello";
|
||||||
const string value = "World";
|
const string value = "World";
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -149,10 +139,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
const string key = "Hello";
|
const string key = "Hello";
|
||||||
const string value = "World";
|
const string value = "World";
|
||||||
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value, "Universe");
|
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value, "Universe");
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(value);
|
result.Should().Be(value);
|
||||||
|
@ -161,10 +149,9 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void GetAuthenticationType_No_Existing_Value()
|
public void GetAuthenticationType_No_Existing_Value()
|
||||||
{
|
{
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(AuthenticationType.Anonymous);
|
result.Should().Be(AuthenticationType.Anonymous);
|
||||||
|
@ -173,11 +160,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void GetAuthenticationType_Windows()
|
public void GetAuthenticationType_Windows()
|
||||||
{
|
{
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
|
Mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be(AuthenticationType.Windows);
|
result.Should().Be(AuthenticationType.Windows);
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
private EpisodeParseResult parseResultSingle;
|
private EpisodeParseResult parseResultSingle;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public new void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
parseResultMulti = new EpisodeParseResult()
|
parseResultMulti = new EpisodeParseResult()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// ReSharper disable RedundantUsingDirective
|
// ReSharper disable RedundantUsingDirective
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
@ -7,12 +8,11 @@ using AutoMoq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Model;
|
using NzbDrone.Core.Model;
|
||||||
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;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
@ -21,11 +21,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void Run_Jobs_Updates_Last_Execution()
|
public void Run_Jobs_Updates_Last_Execution()
|
||||||
{
|
{
|
||||||
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
IList<IJob> BaseFakeJobs = new List<IJob> { new FakeJob() };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
|
@ -42,11 +42,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
public void Run_Jobs_Updates_Last_Execution_Mark_as_unsuccesful()
|
public void Run_Jobs_Updates_Last_Execution_Mark_as_unsuccesful()
|
||||||
{
|
{
|
||||||
|
|
||||||
IList<IJob> fakeJobs = new List<IJob> { new BrokenJob() };
|
IList<IJob> BaseFakeJobs = new List<IJob> { new BrokenJob() };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
|
@ -65,12 +65,12 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void scheduler_skips_jobs_that_arent_mature_yet()
|
public void scheduler_skips_jobs_that_arent_mature_yet()
|
||||||
{
|
{
|
||||||
var fakeJob = new FakeJob();
|
var BaseFakeJob = new FakeJob();
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
|
IList<IJob> BaseFakeJobs = new List<IJob> { BaseFakeJob };
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
|
@ -79,7 +79,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
timerProvider.QueueScheduled();
|
timerProvider.QueueScheduled();
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
|
|
||||||
fakeJob.ExecutionCount.Should().Be(1);
|
BaseFakeJob.ExecutionCount.Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -87,12 +87,12 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
//after execution so the job can successfully run.
|
//after execution so the job can successfully run.
|
||||||
public void can_run_async_job_again()
|
public void can_run_async_job_again()
|
||||||
{
|
{
|
||||||
var fakeJob = new FakeJob();
|
var BaseFakeJob = new FakeJob();
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
|
IList<IJob> BaseFakeJobs = new List<IJob> { BaseFakeJob };
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var jobProvider = mocker.Resolve<JobProvider>();
|
var jobProvider = mocker.Resolve<JobProvider>();
|
||||||
jobProvider.Initialize();
|
jobProvider.Initialize();
|
||||||
|
@ -101,17 +101,17 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
jobProvider.QueueJob(typeof(FakeJob));
|
jobProvider.QueueJob(typeof(FakeJob));
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(2000);
|
||||||
jobProvider.Queue.Should().BeEmpty();
|
jobProvider.Queue.Should().BeEmpty();
|
||||||
fakeJob.ExecutionCount.Should().Be(2);
|
BaseFakeJob.ExecutionCount.Should().Be(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void no_concurent_jobs()
|
public void no_concurent_jobs()
|
||||||
{
|
{
|
||||||
IList<IJob> fakeJobs = new List<IJob> { new SlowJob() };
|
IList<IJob> BaseFakeJobs = new List<IJob> { new SlowJob() };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var jobProvider = mocker.Resolve<JobProvider>();
|
var jobProvider = mocker.Resolve<JobProvider>();
|
||||||
jobProvider.Initialize();
|
jobProvider.Initialize();
|
||||||
|
@ -132,11 +132,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
public void can_run_broken_async_job_again()
|
public void can_run_broken_async_job_again()
|
||||||
{
|
{
|
||||||
var brokenJob = new BrokenJob();
|
var brokenJob = new BrokenJob();
|
||||||
IList<IJob> fakeJobs = new List<IJob> { brokenJob };
|
IList<IJob> BaseFakeJobs = new List<IJob> { brokenJob };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var jobProvider = mocker.Resolve<JobProvider>();
|
var jobProvider = mocker.Resolve<JobProvider>();
|
||||||
jobProvider.Initialize();
|
jobProvider.Initialize();
|
||||||
|
@ -152,54 +152,48 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
//This test will confirm that the concurrency checks are rest
|
|
||||||
//after execution so the job can successfully run.
|
|
||||||
public void can_run_two_jobs_at_the_same_time()
|
public void can_run_two_jobs_at_the_same_time()
|
||||||
{
|
{
|
||||||
var slowJob = new SlowJob();
|
WithRealDb();
|
||||||
IList<IJob> fakeJobs = new List<IJob> { slowJob };
|
|
||||||
var mocker = new AutoMoqer();
|
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
var fakeJob = new FakeJob();
|
||||||
mocker.SetConstant(fakeJobs);
|
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
|
||||||
|
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
Mocker.SetConstant(fakeJobs);
|
||||||
timerProvider.Initialize();
|
|
||||||
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
||||||
|
jobProvider.Initialize();
|
||||||
|
|
||||||
|
|
||||||
var thread1 = new Thread(() => timerProvider.QueueScheduled());
|
jobProvider.QueueScheduled();
|
||||||
thread1.Start();
|
jobProvider.QueueScheduled();
|
||||||
Thread.Sleep(1000);
|
|
||||||
var thread2 = new Thread(() => timerProvider.QueueScheduled());
|
|
||||||
thread2.Start();
|
|
||||||
|
|
||||||
thread1.Join();
|
|
||||||
thread2.Join();
|
|
||||||
|
|
||||||
|
|
||||||
slowJob.ExecutionCount = 2;
|
Thread.Sleep(2000);
|
||||||
|
|
||||||
|
fakeJob.ExecutionCount.Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
//This test will confirm that the concurrency checks are rest
|
|
||||||
//after execution so the job can successfully run.
|
|
||||||
public void can_queue_jobs_at_the_same_time()
|
public void can_queue_jobs_at_the_same_time()
|
||||||
{
|
{
|
||||||
var slowJob = new SlowJob();
|
var slowJob = new SlowJob();
|
||||||
|
var BaseFakeJob = new FakeJob();
|
||||||
|
|
||||||
IList<IJob> fakeJobs = new List<IJob> { slowJob };
|
IList<IJob> BaseFakeJobs = new List<IJob> { slowJob, BaseFakeJob };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var jobProvider = mocker.Resolve<JobProvider>();
|
var jobProvider = mocker.Resolve<JobProvider>();
|
||||||
jobProvider.Initialize();
|
jobProvider.Initialize();
|
||||||
|
|
||||||
var thread1 = new Thread(() => jobProvider.QueueJob(typeof(SlowJob)));
|
|
||||||
var thread2 = new Thread(() => jobProvider.QueueJob(typeof(SlowJob)));
|
jobProvider.QueueJob(typeof(SlowJob));
|
||||||
|
var thread1 = new Thread(() => jobProvider.QueueJob(typeof(FakeJob)));
|
||||||
|
var thread2 = new Thread(() => jobProvider.QueueJob(typeof(FakeJob)));
|
||||||
|
|
||||||
thread1.Start();
|
thread1.Start();
|
||||||
thread2.Start();
|
thread2.Start();
|
||||||
|
@ -209,20 +203,19 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
|
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
|
|
||||||
Assert.AreEqual(1, slowJob.ExecutionCount);
|
BaseFakeJob.ExecutionCount.Should().Be(1);
|
||||||
jobProvider.Queue.Should().BeEmpty();
|
jobProvider.Queue.Should().BeEmpty();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Init_Jobs()
|
public void Init_Jobs()
|
||||||
{
|
{
|
||||||
var fakeTimer = new FakeJob();
|
var fakeTimer = new FakeJob();
|
||||||
IList<IJob> fakeJobs = new List<IJob> { fakeTimer };
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeTimer };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
|
@ -248,11 +241,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
var fakeTimer = new FakeJob();
|
var fakeTimer = new FakeJob();
|
||||||
IList<IJob> fakeJobs = new List<IJob> { fakeTimer };
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeTimer };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(repo);
|
mocker.SetConstant(repo);
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
|
@ -279,11 +272,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
var disabledJob = new DisabledJob();
|
var disabledJob = new DisabledJob();
|
||||||
IList<IJob> fakeJobs = new List<IJob> { disabledJob };
|
IList<IJob> BaseFakeJobs = new List<IJob> { disabledJob };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(repo);
|
mocker.SetConstant(repo);
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
|
@ -305,11 +298,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void Get_Next_Execution_Time()
|
public void Get_Next_Execution_Time()
|
||||||
{
|
{
|
||||||
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
IList<IJob> BaseFakeJobs = new List<IJob> { new FakeJob() };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
|
@ -330,11 +323,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
|
|
||||||
|
|
||||||
var disabledJob = new DisabledJob();
|
var disabledJob = new DisabledJob();
|
||||||
IList<IJob> fakeJobs = new List<IJob> { disabledJob };
|
IList<IJob> BaseFakeJobs = new List<IJob> { disabledJob };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(repo);
|
mocker.SetConstant(repo);
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
|
@ -351,11 +344,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void SingleId_do_not_update_last_execution()
|
public void SingleId_do_not_update_last_execution()
|
||||||
{
|
{
|
||||||
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
IList<IJob> BaseFakeJobs = new List<IJob> { new FakeJob() };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var jobProvider = mocker.Resolve<JobProvider>();
|
var jobProvider = mocker.Resolve<JobProvider>();
|
||||||
|
@ -373,11 +366,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void SingleId_do_not_set_success()
|
public void SingleId_do_not_set_success()
|
||||||
{
|
{
|
||||||
IList<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
IList<IJob> BaseFakeJobs = new List<IJob> { new FakeJob() };
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var jobProvider = mocker.Resolve<JobProvider>();
|
var jobProvider = mocker.Resolve<JobProvider>();
|
||||||
|
@ -397,16 +390,16 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
{
|
{
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
var fakeJob = new FakeJob();
|
var BaseFakeJob = new FakeJob();
|
||||||
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
|
IList<IJob> BaseFakeJobs = new List<IJob> { BaseFakeJob };
|
||||||
|
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var fakeQueueItem = new JobQueueItem
|
var fakeQueueItem = new JobQueueItem
|
||||||
{
|
{
|
||||||
JobType = fakeJob.GetType(),
|
JobType = BaseFakeJob.GetType(),
|
||||||
TargetId = 12,
|
TargetId = 12,
|
||||||
SecondaryTargetId = 0
|
SecondaryTargetId = 0
|
||||||
};
|
};
|
||||||
|
@ -415,11 +408,11 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
var jobProvider = mocker.Resolve<JobProvider>();
|
var jobProvider = mocker.Resolve<JobProvider>();
|
||||||
jobProvider.Initialize();
|
jobProvider.Initialize();
|
||||||
jobProvider.Queue.Add(fakeQueueItem);
|
jobProvider.Queue.Add(fakeQueueItem);
|
||||||
jobProvider.QueueJob(fakeJob.GetType(), 12);
|
jobProvider.QueueJob(BaseFakeJob.GetType(), 12);
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
fakeJob.ExecutionCount.Should().Be(1);
|
BaseFakeJob.ExecutionCount.Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -430,16 +423,16 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
|
|
||||||
var slowJob = new SlowJob();
|
var slowJob = new SlowJob();
|
||||||
var disabledJob = new DisabledJob();
|
var disabledJob = new DisabledJob();
|
||||||
IList<IJob> fakeJobs = new List<IJob> { slowJob, disabledJob };
|
IList<IJob> BaseFakeJobs = new List<IJob> { slowJob, disabledJob };
|
||||||
|
|
||||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||||
mocker.SetConstant(fakeJobs);
|
mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
var jobProvider = mocker.Resolve<JobProvider>();
|
var jobProvider = mocker.Resolve<JobProvider>();
|
||||||
|
|
||||||
jobProvider.Initialize();
|
jobProvider.Initialize();
|
||||||
|
|
||||||
var _jobThread = new Thread(() => jobProvider.QueueScheduled());
|
var _jobThread = new Thread(jobProvider.QueueScheduled);
|
||||||
_jobThread.Start();
|
_jobThread.Start();
|
||||||
|
|
||||||
Thread.Sleep(200);
|
Thread.Sleep(200);
|
||||||
|
@ -453,89 +446,25 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
slowJob.ExecutionCount.Should().Be(1);
|
slowJob.ExecutionCount.Should().Be(1);
|
||||||
disabledJob.ExecutionCount.Should().Be(1);
|
disabledJob.ExecutionCount.Should().Be(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public class FakeJob : IJob
|
[Test]
|
||||||
|
public void trygin_to_queue_unregistered_job_should_fail()
|
||||||
{
|
{
|
||||||
public string Name
|
WithRealDb();
|
||||||
{
|
|
||||||
get { return "FakeJob"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int DefaultInterval
|
IList<IJob> BaseFakeJobs = new List<IJob> { new SlowJob(), new DisabledJob() };
|
||||||
{
|
|
||||||
get { return 15; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ExecutionCount { get; set; }
|
Mocker.SetConstant(BaseFakeJobs);
|
||||||
|
|
||||||
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
||||||
{
|
|
||||||
ExecutionCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DisabledJob : IJob
|
jobProvider.Initialize();
|
||||||
{
|
jobProvider.QueueJob(typeof(string));
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get { return "DisabledJob"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int DefaultInterval
|
|
||||||
{
|
|
||||||
get { return 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ExecutionCount { get; set; }
|
|
||||||
|
|
||||||
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
|
||||||
{
|
|
||||||
ExecutionCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class BrokenJob : IJob
|
|
||||||
{
|
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get { return "FakeJob"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int DefaultInterval
|
|
||||||
{
|
|
||||||
get { return 15; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ExecutionCount { get; set; }
|
|
||||||
|
|
||||||
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
|
||||||
{
|
|
||||||
ExecutionCount++;
|
|
||||||
throw new ApplicationException("Broken job is broken");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SlowJob : IJob
|
|
||||||
{
|
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get { return "FakeJob"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int DefaultInterval
|
|
||||||
{
|
|
||||||
get { return 15; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ExecutionCount { get; set; }
|
|
||||||
|
|
||||||
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Starting Job");
|
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
ExecutionCount++;
|
ExceptionVerification.ExcpectedErrors(1);
|
||||||
Console.WriteLine("Finishing Job");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using NzbDrone.Core.Model.Notification;
|
||||||
|
using NzbDrone.Core.Providers.Jobs;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
|
||||||
|
{
|
||||||
|
|
||||||
|
public class FakeJob : IJob
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return GetType().Name; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual int DefaultInterval
|
||||||
|
{
|
||||||
|
get { return 15; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ExecutionCount { get; private set; }
|
||||||
|
|
||||||
|
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
||||||
|
{
|
||||||
|
ExecutionCount++;
|
||||||
|
Console.WriteLine("Begin " + Name);
|
||||||
|
Start();
|
||||||
|
Console.WriteLine("End " + Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Start()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DisabledJob : FakeJob
|
||||||
|
{
|
||||||
|
public override int DefaultInterval
|
||||||
|
{
|
||||||
|
get { return 0; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BrokenJob : FakeJob
|
||||||
|
{
|
||||||
|
protected override void Start()
|
||||||
|
{
|
||||||
|
throw new ApplicationException("Broken job is broken");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SlowJob : FakeJob
|
||||||
|
{
|
||||||
|
protected override void Start()
|
||||||
|
{
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Ninject;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Core.Providers;
|
using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
@ -16,30 +17,31 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class TvDbProviderTest : TestBase
|
public class TvDbProviderTest : TestBase
|
||||||
{
|
{
|
||||||
|
private TvDbProvider tvDbProvider;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
tvDbProvider = LiveKernel.Get<TvDbProvider>();
|
||||||
|
}
|
||||||
|
|
||||||
[TestCase("The Simpsons")]
|
[TestCase("The Simpsons")]
|
||||||
[TestCase("Family Guy")]
|
[TestCase("Family Guy")]
|
||||||
[TestCase("South Park")]
|
[TestCase("South Park")]
|
||||||
public void successful_search(string title)
|
public void successful_search(string title)
|
||||||
{
|
{
|
||||||
var result = new TvDbProvider(new EnviromentProvider()).SearchSeries(title);
|
var result = tvDbProvider.SearchSeries(title);
|
||||||
|
|
||||||
result.Should().NotBeEmpty();
|
result.Should().NotBeEmpty();
|
||||||
result[0].SeriesName.Should().Be(title);
|
result[0].SeriesName.Should().Be(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void no_search_result()
|
public void no_search_result()
|
||||||
{
|
{
|
||||||
//setup
|
|
||||||
var tvdbProvider = new TvDbProvider(new EnviromentProvider());
|
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var result = tvdbProvider.SearchSeries(Guid.NewGuid().ToString());
|
var result = tvDbProvider.SearchSeries(Guid.NewGuid().ToString());
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
result.Should().BeEmpty();
|
result.Should().BeEmpty();
|
||||||
|
@ -49,11 +51,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void none_unique_season_episode_number()
|
public void none_unique_season_episode_number()
|
||||||
{
|
{
|
||||||
//setup
|
|
||||||
var tvdbProvider = new TvDbProvider(new EnviromentProvider());
|
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var result = tvdbProvider.GetSeries(75978, true);//Family guy
|
var result = tvDbProvider.GetSeries(75978, true);//Family guy
|
||||||
|
|
||||||
//Asserts that when episodes are grouped by Season/Episode each group contains maximum of
|
//Asserts that when episodes are grouped by Season/Episode each group contains maximum of
|
||||||
//one item.
|
//one item.
|
||||||
|
@ -65,11 +64,8 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
[Test]
|
[Test]
|
||||||
public void American_dad_fix()
|
public void American_dad_fix()
|
||||||
{
|
{
|
||||||
//setup
|
|
||||||
var tvdbProvider = new TvDbProvider(new EnviromentProvider());
|
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var result = tvdbProvider.GetSeries(73141, true);
|
var result = tvDbProvider.GetSeries(73141, true);
|
||||||
|
|
||||||
var seasonsNumbers = result.Episodes.Select(e => e.SeasonNumber)
|
var seasonsNumbers = result.Episodes.Select(e => e.SeasonNumber)
|
||||||
.Distinct().ToList();
|
.Distinct().ToList();
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
|
||||||
public void setup()
|
public void setup()
|
||||||
{
|
{
|
||||||
_mocker = new AutoMoqer(MockBehavior.Strict);
|
_mocker = new AutoMoqer(MockBehavior.Strict);
|
||||||
_mocker.GetMock<EnviromentProvider>()
|
_mocker.GetMock<PathProvider>()
|
||||||
.SetupGet(c => c.TempPath).Returns(TempFolder);
|
.SetupGet(c => c.SystemTemp).Returns(TempFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,11 +39,11 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
|
||||||
};
|
};
|
||||||
|
|
||||||
_mocker.GetMock<HttpProvider>().Setup(
|
_mocker.GetMock<HttpProvider>().Setup(
|
||||||
c => c.DownloadFile(updatePackage.Url, Path.Combine(TempFolder, UpdateProvider.SandboxFolderName ,updatePackage.FileName)));
|
c => c.DownloadFile(updatePackage.Url, Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME, updatePackage.FileName)));
|
||||||
|
|
||||||
_mocker.GetMock<DiskProvider>().Setup(
|
_mocker.GetMock<DiskProvider>().Setup(
|
||||||
c => c.ExtractArchive(Path.Combine(TempFolder, UpdateProvider.SandboxFolderName, updatePackage.FileName),
|
c => c.ExtractArchive(Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME, updatePackage.FileName),
|
||||||
Path.Combine(TempFolder, UpdateProvider.SandboxFolderName)));
|
Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME)));
|
||||||
|
|
||||||
_mocker.Resolve<UpdateProvider>().PreformUpdate(updatePackage);
|
_mocker.Resolve<UpdateProvider>().PreformUpdate(updatePackage);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
|
||||||
public void Should_download_and_extract_to_temp_folder()
|
public void Should_download_and_extract_to_temp_folder()
|
||||||
{
|
{
|
||||||
|
|
||||||
var updateSubFolder = new DirectoryInfo(Path.Combine(TempFolder, UpdateProvider.SandboxFolderName));
|
var updateSubFolder = new DirectoryInfo(Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME));
|
||||||
|
|
||||||
var updatePackage = new UpdatePackage
|
var updatePackage = new UpdatePackage
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,6 +15,7 @@ using PetaPoco;
|
||||||
namespace NzbDrone.Core.Test
|
namespace NzbDrone.Core.Test
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
|
[Explicit]
|
||||||
[Category("Benchmark")]
|
[Category("Benchmark")]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class DbBenchmark : TestBase
|
public class DbBenchmark : TestBase
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Web.Hosting;
|
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
|
@ -17,106 +14,106 @@ using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core
|
namespace NzbDrone.Core
|
||||||
{
|
{
|
||||||
public static class CentralDispatch
|
public class CentralDispatch
|
||||||
{
|
{
|
||||||
private static StandardKernel _kernel;
|
private readonly Object KernelLock = new object();
|
||||||
private static readonly Object KernelLock = new object();
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public static StandardKernel NinjectKernel
|
public CentralDispatch()
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_kernel == null)
|
|
||||||
{
|
{
|
||||||
InitializeApp();
|
InitializeApp();
|
||||||
}
|
}
|
||||||
return _kernel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void InitializeApp()
|
public StandardKernel Kernel { get; private set; }
|
||||||
|
|
||||||
|
private void InitializeApp()
|
||||||
{
|
{
|
||||||
BindKernel();
|
BindKernel();
|
||||||
|
|
||||||
MigrationsHelper.Run(Connection.MainConnectionString, true);
|
Kernel.Get<LogConfiguration>().Setup();
|
||||||
|
|
||||||
LogConfiguration.RegisterDatabaseLogger(_kernel.Get<DatabaseTarget>());
|
var mainConnectionString = Kernel.Get<Connection>().MainConnectionString;
|
||||||
|
|
||||||
_kernel.Get<QualityProvider>().SetupDefaultProfiles();
|
MigrationsHelper.Run(mainConnectionString, true);
|
||||||
_kernel.Get<QualityTypeProvider>().SetupDefault();
|
|
||||||
_kernel.Get<ConfigFileProvider>().CreateDefaultConfigFile();
|
LogConfiguration.RegisterDatabaseLogger(Kernel.Get<DatabaseTarget>());
|
||||||
|
|
||||||
|
Kernel.Get<QualityProvider>().SetupDefaultProfiles();
|
||||||
|
Kernel.Get<QualityTypeProvider>().SetupDefault();
|
||||||
|
Kernel.Get<ConfigFileProvider>().CreateDefaultConfigFile();
|
||||||
|
|
||||||
BindExternalNotifications();
|
BindExternalNotifications();
|
||||||
BindIndexers();
|
BindIndexers();
|
||||||
BindJobs();
|
BindJobs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BindKernel()
|
private void BindKernel()
|
||||||
{
|
{
|
||||||
lock (KernelLock)
|
lock (KernelLock)
|
||||||
{
|
{
|
||||||
Logger.Debug("Binding Ninject's Kernel");
|
Logger.Debug("Binding Ninject's Kernel");
|
||||||
_kernel = new StandardKernel();
|
Kernel = new StandardKernel();
|
||||||
|
|
||||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InTransientScope();
|
var connection = Kernel.Get<Connection>();
|
||||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString, false)).WhenInjectedInto<DatabaseTarget>().InSingletonScope();
|
|
||||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto<LogProvider>().InSingletonScope();
|
|
||||||
|
|
||||||
_kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
|
Kernel.Bind<IDatabase>().ToMethod(c => connection.GetMainPetaPocoDb()).InTransientScope();
|
||||||
|
Kernel.Bind<IDatabase>().ToMethod(c => connection.GetLogPetaPocoDb(false)).WhenInjectedInto<DatabaseTarget>().InSingletonScope();
|
||||||
|
Kernel.Bind<IDatabase>().ToMethod(c => connection.GetLogPetaPocoDb()).WhenInjectedInto<LogProvider>().InSingletonScope();
|
||||||
|
|
||||||
|
Kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BindIndexers()
|
private void BindIndexers()
|
||||||
{
|
{
|
||||||
_kernel.Bind<IndexerBase>().To<NzbsOrg>();
|
Kernel.Bind<IndexerBase>().To<NzbsOrg>();
|
||||||
_kernel.Bind<IndexerBase>().To<NzbMatrix>();
|
Kernel.Bind<IndexerBase>().To<NzbMatrix>();
|
||||||
_kernel.Bind<IndexerBase>().To<NzbsRUs>();
|
Kernel.Bind<IndexerBase>().To<NzbsRUs>();
|
||||||
_kernel.Bind<IndexerBase>().To<Newzbin>();
|
Kernel.Bind<IndexerBase>().To<Newzbin>();
|
||||||
|
|
||||||
var indexers = _kernel.GetAll<IndexerBase>();
|
var indexers = Kernel.GetAll<IndexerBase>();
|
||||||
_kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());
|
Kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BindJobs()
|
private void BindJobs()
|
||||||
{
|
{
|
||||||
_kernel.Bind<IJob>().To<RssSyncJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<RssSyncJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<ImportNewSeriesJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<ImportNewSeriesJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<UpdateInfoJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<UpdateInfoJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<DiskScanJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<DiskScanJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<DeleteSeriesJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<DeleteSeriesJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<EpisodeSearchJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<EpisodeSearchJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<RenameEpisodeJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<RenameEpisodeJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<PostDownloadScanJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<PostDownloadScanJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<UpdateSceneMappingsJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<UpdateSceneMappingsJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<SeasonSearchJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<SeasonSearchJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<RenameSeasonJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<RenameSeasonJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<SeriesSearchJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<SeriesSearchJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<RenameSeriesJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<RenameSeriesJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<BacklogSearchJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<BacklogSearchJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
|
||||||
_kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
|
Kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
|
||||||
|
|
||||||
_kernel.Get<JobProvider>().Initialize();
|
Kernel.Get<JobProvider>().Initialize();
|
||||||
_kernel.Get<WebTimer>().StartTimer(30);
|
Kernel.Get<WebTimer>().StartTimer(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BindExternalNotifications()
|
private void BindExternalNotifications()
|
||||||
{
|
{
|
||||||
_kernel.Bind<ExternalNotificationBase>().To<Xbmc>();
|
Kernel.Bind<ExternalNotificationBase>().To<Xbmc>();
|
||||||
_kernel.Bind<ExternalNotificationBase>().To<Smtp>();
|
Kernel.Bind<ExternalNotificationBase>().To<Smtp>();
|
||||||
_kernel.Bind<ExternalNotificationBase>().To<Twitter>();
|
Kernel.Bind<ExternalNotificationBase>().To<Twitter>();
|
||||||
_kernel.Bind<ExternalNotificationBase>().To<Providers.ExternalNotification.Growl>();
|
Kernel.Bind<ExternalNotificationBase>().To<Providers.ExternalNotification.Growl>();
|
||||||
_kernel.Bind<ExternalNotificationBase>().To<Prowl>();
|
Kernel.Bind<ExternalNotificationBase>().To<Prowl>();
|
||||||
|
|
||||||
var notifiers = _kernel.GetAll<ExternalNotificationBase>();
|
var notifiers = Kernel.GetAll<ExternalNotificationBase>();
|
||||||
_kernel.Get<ExternalNotificationProvider>().InitializeNotifiers(notifiers.ToList());
|
Kernel.Get<ExternalNotificationProvider>().InitializeNotifiers(notifiers.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Forces IISExpress process to exit with the host application
|
/// Forces IISExpress process to exit with the host application
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void DedicateToHost()
|
public void DedicateToHost()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -144,6 +141,7 @@ namespace NzbDrone.Core
|
||||||
private static void ShutDown()
|
private static void ShutDown()
|
||||||
{
|
{
|
||||||
Logger.Info("Shutting down application.");
|
Logger.Info("Shutting down application.");
|
||||||
|
WebTimer.Stop();
|
||||||
Process.GetCurrentProcess().Kill();
|
Process.GetCurrentProcess().Kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,35 @@ using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore
|
namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
public static class Connection
|
public class Connection
|
||||||
{
|
{
|
||||||
private static EnviromentProvider _enviromentProvider = new EnviromentProvider();
|
private readonly PathProvider _pathProvider;
|
||||||
|
|
||||||
|
public Connection(PathProvider pathProvider)
|
||||||
|
{
|
||||||
|
_pathProvider = pathProvider;
|
||||||
|
}
|
||||||
|
|
||||||
static Connection()
|
static Connection()
|
||||||
{
|
{
|
||||||
Database.Mapper = new CustomeMapper();
|
Database.Mapper = new CustomeMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String MainConnectionString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetConnectionString(_pathProvider.NzbDronoeDbFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String LogConnectionString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetConnectionString(_pathProvider.LogDbFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetConnectionString(string path)
|
public static string GetConnectionString(string path)
|
||||||
{
|
{
|
||||||
|
@ -26,22 +46,15 @@ namespace NzbDrone.Core.Datastore
|
||||||
return String.Format("Data Source={0}", path);
|
return String.Format("Data Source={0}", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String MainConnectionString
|
public IDatabase GetMainPetaPocoDb(Boolean profiled = true)
|
||||||
{
|
{
|
||||||
get
|
return GetPetaPocoDb(MainConnectionString, profiled);
|
||||||
{
|
|
||||||
return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "nzbdrone.sdf"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String LogConnectionString
|
public IDatabase GetLogPetaPocoDb(Boolean profiled = true)
|
||||||
{
|
{
|
||||||
get
|
return GetPetaPocoDb(LogConnectionString, profiled);
|
||||||
{
|
|
||||||
return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "log.sdf"));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
|
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,6 +54,8 @@ namespace NzbDrone.Core
|
||||||
return dateTime.ToShortDateString();
|
return dateTime.ToShortDateString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: this should be moved to DiskProvider
|
||||||
public static ulong FreeDiskSpace(this DirectoryInfo directoryInfo)
|
public static ulong FreeDiskSpace(this DirectoryInfo directoryInfo)
|
||||||
{
|
{
|
||||||
ulong freeBytesAvailable;
|
ulong freeBytesAvailable;
|
||||||
|
|
|
@ -7,22 +7,30 @@ using NzbDrone.Core.Providers;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Instrumentation
|
namespace NzbDrone.Core.Instrumentation
|
||||||
{
|
{
|
||||||
public static class LogConfiguration
|
public class LogConfiguration
|
||||||
{
|
{
|
||||||
|
private readonly PathProvider _pathProvider;
|
||||||
|
private readonly DatabaseTarget _databaseTarget;
|
||||||
|
|
||||||
public static void Setup()
|
public LogConfiguration(PathProvider pathProvider, DatabaseTarget databaseTarget)
|
||||||
|
{
|
||||||
|
_pathProvider = pathProvider;
|
||||||
|
_databaseTarget = databaseTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Setup()
|
||||||
{
|
{
|
||||||
if (Common.EnviromentProvider.IsProduction)
|
if (Common.EnviromentProvider.IsProduction)
|
||||||
{
|
{
|
||||||
LogManager.ThrowExceptions = false;
|
LogManager.ThrowExceptions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().WebRoot, "log.config"), false);
|
LogManager.Configuration = new XmlLoggingConfiguration(_pathProvider.LogConfigFile, false);
|
||||||
|
|
||||||
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
|
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
|
||||||
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
|
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
|
||||||
|
|
||||||
LogManager.ConfigurationReloaded += ((s, e) => RegisterDatabaseLogger(CentralDispatch.NinjectKernel.Get<DatabaseTarget>()));
|
LogManager.ConfigurationReloaded += ((s, e) => RegisterDatabaseLogger(_databaseTarget));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterDatabaseLogger(DatabaseTarget databaseTarget)
|
public static void RegisterDatabaseLogger(DatabaseTarget databaseTarget)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Model
|
namespace NzbDrone.Core.Model
|
||||||
{
|
{
|
||||||
|
@ -12,13 +10,13 @@ namespace NzbDrone.Core.Model
|
||||||
|
|
||||||
public bool Equals(JobQueueItem other)
|
public bool Equals(JobQueueItem other)
|
||||||
{
|
{
|
||||||
if (JobType == other.JobType && TargetId == other.TargetId
|
return (JobType == other.JobType && TargetId == other.TargetId
|
||||||
&& SecondaryTargetId == other.SecondaryTargetId)
|
&& SecondaryTargetId == other.SecondaryTargetId);
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Format("[{0}({1}, {2})]", JobType.Name, TargetId, SecondaryTargetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,6 +189,9 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
|
||||||
|
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Constants.cs" />
|
<Compile Include="Constants.cs" />
|
||||||
<Compile Include="Datastore\Connection.cs" />
|
<Compile Include="Datastore\Connection.cs" />
|
||||||
<Compile Include="Datastore\MigrationLogger.cs" />
|
<Compile Include="Datastore\MigrationLogger.cs" />
|
||||||
|
|
|
@ -1,18 +1,4 @@
|
||||||
// * This program is free software: you can redistribute it and/or modify
|
using System.Reflection;
|
||||||
// * it under the terms of the GNU General Public License as published by
|
|
||||||
// * the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// * (at your option) any later version.
|
|
||||||
// *
|
|
||||||
// * This program is distributed in the hope that it will be useful,
|
|
||||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// * GNU General Public License for more details.
|
|
||||||
// *
|
|
||||||
// * You should have received a copy of the GNU General Public License
|
|
||||||
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
// *
|
|
||||||
// */
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
@ -20,35 +6,15 @@ using System.Runtime.InteropServices;
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
|
|
||||||
[assembly: AssemblyTitle("NZBDrone.Core")]
|
[assembly: AssemblyTitle("NzbDrone.Core")]
|
||||||
[assembly: AssemblyDescription("NZBDrone Core Component")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("www.nzbdrone.com")]
|
|
||||||
[assembly: AssemblyProduct("NZBDrone")]
|
|
||||||
[assembly: AssemblyCopyright("GNU General Public v3")]
|
|
||||||
[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
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
|
||||||
[assembly: Guid("3C29FEF7-4B07-49ED-822E-1C29DC49BFAB")]
|
[assembly: Guid("3C29FEF7-4B07-49ED-822E-1C29DC49BFAB")]
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
[assembly: InternalsVisibleTo("NzbDrone.Core.Test")]
|
||||||
//
|
|
||||||
// Major Version
|
|
||||||
// Minor Version
|
|
||||||
// Build Number
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
|
|
||||||
[assembly: AssemblyVersion("0.6.0.*")]
|
[assembly: AssemblyVersion("0.6.0.*")]
|
||||||
[assembly: InternalsVisibleTo("NzbDrone.Core.Test")]
|
[assembly: AssemblyFileVersion("0.6.0.*")]
|
|
@ -9,12 +9,13 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
{
|
{
|
||||||
public class ConfigFileProvider
|
public class ConfigFileProvider
|
||||||
{
|
{
|
||||||
private string _configFile = Path.Combine(new EnviromentProvider().AppDataPath, "Config.xml");
|
private readonly PathProvider _pathProvider;
|
||||||
|
|
||||||
public string ConfigFile
|
private readonly string _configFile;
|
||||||
|
public ConfigFileProvider(PathProvider pathProvider)
|
||||||
{
|
{
|
||||||
get { return _configFile; }
|
_pathProvider = pathProvider;
|
||||||
set { _configFile = value; }
|
_configFile = _pathProvider.AppConfigFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual int Port
|
public virtual int Port
|
||||||
|
@ -37,7 +38,7 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
|
|
||||||
public virtual string GetValue(string key, object defaultValue, string parent = null)
|
public virtual string GetValue(string key, object defaultValue, string parent = null)
|
||||||
{
|
{
|
||||||
var xDoc = XDocument.Load(ConfigFile);
|
var xDoc = XDocument.Load(_configFile);
|
||||||
var config = xDoc.Descendants("Config").Single();
|
var config = xDoc.Descendants("Config").Single();
|
||||||
|
|
||||||
var parentContainer = config;
|
var parentContainer = config;
|
||||||
|
@ -50,7 +51,7 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
SetValue(key, defaultValue, parent);
|
SetValue(key, defaultValue, parent);
|
||||||
|
|
||||||
//Reload the configFile
|
//Reload the configFile
|
||||||
xDoc = XDocument.Load(ConfigFile);
|
xDoc = XDocument.Load(_configFile);
|
||||||
config = xDoc.Descendants("Config").Single();
|
config = xDoc.Descendants("Config").Single();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
|
|
||||||
public virtual void SetValue(string key, object value, string parent = null)
|
public virtual void SetValue(string key, object value, string parent = null)
|
||||||
{
|
{
|
||||||
var xDoc = XDocument.Load(ConfigFile);
|
var xDoc = XDocument.Load(_configFile);
|
||||||
var config = xDoc.Descendants("Config").Single();
|
var config = xDoc.Descendants("Config").Single();
|
||||||
|
|
||||||
var parentContainer = config;
|
var parentContainer = config;
|
||||||
|
@ -105,18 +106,18 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
else
|
else
|
||||||
parentContainer.Descendants(key).Single().Value = value.ToString();
|
parentContainer.Descendants(key).Single().Value = value.ToString();
|
||||||
|
|
||||||
xDoc.Save(ConfigFile);
|
xDoc.Save(_configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void CreateDefaultConfigFile()
|
public virtual void CreateDefaultConfigFile()
|
||||||
{
|
{
|
||||||
if (!File.Exists(ConfigFile))
|
if (!File.Exists(_configFile))
|
||||||
{
|
{
|
||||||
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
|
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
|
||||||
|
|
||||||
xDoc.Add(new XElement("Config"));
|
xDoc.Add(new XElement("Config"));
|
||||||
|
|
||||||
xDoc.Save(ConfigFile);
|
xDoc.Save(_configFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ namespace NzbDrone.Core.Providers.ExternalNotification
|
||||||
{
|
{
|
||||||
private readonly GrowlProvider _growlProvider;
|
private readonly GrowlProvider _growlProvider;
|
||||||
|
|
||||||
private readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
|
|
||||||
public Growl(ConfigProvider configProvider, GrowlProvider growlProvider)
|
public Growl(ConfigProvider configProvider, GrowlProvider growlProvider)
|
||||||
: base(configProvider)
|
: base(configProvider)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +39,7 @@ namespace NzbDrone.Core.Providers.ExternalNotification
|
||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.WarnException(ex.Message, ex);
|
_logger.WarnException(ex.Message, ex);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +63,7 @@ namespace NzbDrone.Core.Providers.ExternalNotification
|
||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.WarnException(ex.Message, ex);
|
_logger.WarnException(ex.Message, ex);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,20 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
private readonly HttpProvider _httpProvider;
|
private readonly HttpProvider _httpProvider;
|
||||||
private readonly DiskProvider _diskProvider;
|
private readonly DiskProvider _diskProvider;
|
||||||
private readonly EnviromentProvider _enviromentProvider;
|
private readonly EnviromentProvider _enviromentProvider;
|
||||||
|
private readonly PathProvider _pathProvider;
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
private string _bannerPath = "";
|
|
||||||
private const string _bannerUrlPrefix = "http://www.thetvdb.com/banners/";
|
private const string _bannerUrlPrefix = "http://www.thetvdb.com/banners/";
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public BannerDownloadJob(SeriesProvider seriesProvider, HttpProvider httpProvider, DiskProvider diskProvider, EnviromentProvider enviromentProvider)
|
public BannerDownloadJob(SeriesProvider seriesProvider, HttpProvider httpProvider, DiskProvider diskProvider,
|
||||||
|
EnviromentProvider enviromentProvider, PathProvider pathProvider)
|
||||||
{
|
{
|
||||||
_seriesProvider = seriesProvider;
|
_seriesProvider = seriesProvider;
|
||||||
_httpProvider = httpProvider;
|
_httpProvider = httpProvider;
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
_enviromentProvider = enviromentProvider;
|
_enviromentProvider = enviromentProvider;
|
||||||
|
_pathProvider = pathProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BannerDownloadJob()
|
public BannerDownloadJob()
|
||||||
|
@ -51,8 +53,8 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
{
|
{
|
||||||
Logger.Debug("Starting banner download job");
|
Logger.Debug("Starting banner download job");
|
||||||
|
|
||||||
_bannerPath = Path.Combine(_enviromentProvider.WebRoot, "Content", "Images", "Banners");
|
|
||||||
_diskProvider.CreateDirectory(_bannerPath);
|
_diskProvider.CreateDirectory(_pathProvider.BannerPath);
|
||||||
|
|
||||||
if (targetId > 0)
|
if (targetId > 0)
|
||||||
{
|
{
|
||||||
|
@ -76,7 +78,7 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
|
|
||||||
public virtual void DownloadBanner(ProgressNotification notification, Series series)
|
public virtual void DownloadBanner(ProgressNotification notification, Series series)
|
||||||
{
|
{
|
||||||
var bannerFilename = String.Format("{0}{1}{2}.jpg", _bannerPath, Path.DirectorySeparatorChar, series.SeriesId);
|
var bannerFilename = Path.Combine(_pathProvider.BannerPath, series.SeriesId.ToString()) + ".jpg";
|
||||||
|
|
||||||
notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title);
|
notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ using NzbDrone.Core.Model;
|
||||||
using NzbDrone.Core.Model.Notification;
|
using NzbDrone.Core.Model.Notification;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
using ThreadState = System.Threading.ThreadState;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers.Jobs
|
namespace NzbDrone.Core.Providers.Jobs
|
||||||
{
|
{
|
||||||
|
@ -21,15 +20,15 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JobProvider
|
public class JobProvider
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
private readonly IDatabase _database;
|
private readonly IDatabase _database;
|
||||||
private readonly NotificationProvider _notificationProvider;
|
private readonly NotificationProvider _notificationProvider;
|
||||||
private readonly IList<IJob> _jobs;
|
private readonly IList<IJob> _jobs;
|
||||||
|
|
||||||
private Thread _jobThread;
|
private Thread _jobThread;
|
||||||
|
private Stopwatch _jobThreadStopWatch;
|
||||||
|
|
||||||
private readonly object ExecutionLock = new object();
|
private readonly object executionLock = new object();
|
||||||
private bool _isRunning;
|
|
||||||
private readonly List<JobQueueItem> _queue = new List<JobQueueItem>();
|
private readonly List<JobQueueItem> _queue = new List<JobQueueItem>();
|
||||||
|
|
||||||
private ProgressNotification _notification;
|
private ProgressNotification _notification;
|
||||||
|
@ -40,6 +39,7 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
_database = database;
|
_database = database;
|
||||||
_notificationProvider = notificationProvider;
|
_notificationProvider = notificationProvider;
|
||||||
_jobs = jobs;
|
_jobs = jobs;
|
||||||
|
ResetThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -68,243 +68,13 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
return _database.Fetch<JobDefinition>().ToList();
|
return _database.Fetch<JobDefinition>().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds/Updates definitions for a job
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="definitions">Settings to be added/updated</param>
|
|
||||||
public virtual void SaveDefinition(JobDefinition definitions)
|
|
||||||
{
|
|
||||||
if (definitions.Id == 0)
|
|
||||||
{
|
|
||||||
Logger.Trace("Adding job definitions for {0}", definitions.Name);
|
|
||||||
_database.Insert(definitions);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Logger.Trace("Updating job definitions for {0}", definitions.Name);
|
|
||||||
_database.Update(definitions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Iterates through all registered jobs and queues any that are due for an execution.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>Will ignore request if queue is already running.</remarks>
|
|
||||||
public virtual void QueueScheduled()
|
|
||||||
{
|
|
||||||
lock (ExecutionLock)
|
|
||||||
{
|
|
||||||
if (_isRunning)
|
|
||||||
{
|
|
||||||
Logger.Trace("Queue is already running. Ignoring scheduler's request.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var counter = 0;
|
|
||||||
|
|
||||||
var pendingJobs = All().Where(
|
|
||||||
t => t.Enable &&
|
|
||||||
(DateTime.Now - t.LastExecution) > TimeSpan.FromMinutes(t.Interval)
|
|
||||||
).Select(c => _jobs.Where(t => t.GetType().ToString() == c.TypeName).Single());
|
|
||||||
|
|
||||||
foreach (var job in pendingJobs)
|
|
||||||
{
|
|
||||||
QueueJob(job.GetType());
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Trace("{0} Scheduled tasks have been added to the queue", counter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queues the execution of a job asynchronously
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="jobType">Type of the job that should be queued.</param>
|
|
||||||
/// <param name="targetId">The targetId could be any Id parameter eg. SeriesId. it will be passed to the job implementation
|
|
||||||
/// to allow it to filter it's target of execution.</param>
|
|
||||||
/// /// <param name="secondaryTargetId">The secondaryTargetId could be any Id parameter eg. SeasonNumber. it will be passed to
|
|
||||||
/// the timer implementation to further allow it to filter it's target of execution</param>
|
|
||||||
/// <remarks>Job is only added to the queue if same job with the same targetId doesn't already exist in the queue.</remarks>
|
|
||||||
public virtual void QueueJob(Type jobType, int targetId = 0, int secondaryTargetId = 0)
|
|
||||||
{
|
|
||||||
Logger.Debug("Adding [{0}:{1}] to the queue", jobType.Name, targetId);
|
|
||||||
|
|
||||||
lock (ExecutionLock)
|
|
||||||
{
|
|
||||||
lock (Queue)
|
|
||||||
{
|
|
||||||
var queueItem = new JobQueueItem
|
|
||||||
{
|
|
||||||
JobType = jobType,
|
|
||||||
TargetId = targetId,
|
|
||||||
SecondaryTargetId = secondaryTargetId
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!Queue.Contains(queueItem))
|
|
||||||
{
|
|
||||||
Queue.Add(queueItem);
|
|
||||||
Logger.Trace("Job [{0}:{1}] added to the queue", jobType.Name, targetId);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Logger.Info("[{0}:{1}] already exists in the queue. Skipping.", jobType.Name, targetId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_isRunning)
|
|
||||||
{
|
|
||||||
Logger.Trace("Queue is already running. No need to start it up.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_isRunning = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_jobThread == null || _jobThread.ThreadState != ThreadState.Running)
|
|
||||||
{
|
|
||||||
Logger.Trace("Initializing queue processor thread");
|
|
||||||
|
|
||||||
ThreadStart starter = () =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ProcessQueue();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.ErrorException("Error has occurred in queue processor thread", e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_isRunning = false;
|
|
||||||
_jobThread.Abort();
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
_jobThread = new Thread(starter) { Name = "JobQueueThread" };
|
|
||||||
_jobThread.Start();
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var messge = "Job Thread is null";
|
|
||||||
|
|
||||||
if (_jobThread != null)
|
|
||||||
{
|
|
||||||
messge = "Job Thread State: " + _jobThread.ThreadState;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Error("Execution lock has fucked up. {0}. Ignoring request.", messge);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Starts processing of queue synchronously.
|
|
||||||
/// </summary>
|
|
||||||
private void ProcessQueue()
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
using (NestedDiagnosticsContext.Push(Guid.NewGuid().ToString()))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JobQueueItem job = null;
|
|
||||||
|
|
||||||
lock (Queue)
|
|
||||||
{
|
|
||||||
if (Queue.Count != 0)
|
|
||||||
{
|
|
||||||
job = Queue.First();
|
|
||||||
Queue.Remove(job);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (job != null)
|
|
||||||
{
|
|
||||||
Execute(job.JobType, job.TargetId, job.SecondaryTargetId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.FatalException("An error has occurred while processing queued job.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (Queue.Count != 0);
|
|
||||||
|
|
||||||
Logger.Trace("Finished processing jobs in the queue.");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Executes the job synchronously
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="jobType">Type of the job that should be executed</param>
|
|
||||||
/// <param name="targetId">The targetId could be any Id parameter eg. SeriesId. it will be passed to the timer implementation
|
|
||||||
/// to allow it to filter it's target of execution</param>
|
|
||||||
/// /// <param name="secondaryTargetId">The secondaryTargetId could be any Id parameter eg. SeasonNumber. it will be passed to
|
|
||||||
/// the timer implementation to further allow it to filter it's target of execution</param>
|
|
||||||
private void Execute(Type jobType, int targetId = 0, int secondaryTargetId = 0)
|
|
||||||
{
|
|
||||||
var jobImplementation = _jobs.Where(t => t.GetType() == jobType).Single();
|
|
||||||
if (jobImplementation == null)
|
|
||||||
{
|
|
||||||
Logger.Error("Unable to locate implementation for '{0}'. Make sure it is properly registered.", jobType);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var settings = All().Where(j => j.TypeName == jobType.ToString()).Single();
|
|
||||||
|
|
||||||
using (_notification = new ProgressNotification(jobImplementation.Name))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Logger.Debug("Starting '{0}' job. Last execution {1}", settings.Name, settings.LastExecution);
|
|
||||||
|
|
||||||
var sw = Stopwatch.StartNew();
|
|
||||||
|
|
||||||
_notificationProvider.Register(_notification);
|
|
||||||
jobImplementation.Start(_notification, targetId, secondaryTargetId);
|
|
||||||
_notification.Status = ProgressNotificationStatus.Completed;
|
|
||||||
|
|
||||||
settings.LastExecution = DateTime.Now;
|
|
||||||
settings.Success = true;
|
|
||||||
|
|
||||||
sw.Stop();
|
|
||||||
Logger.Debug("Job '{0}' successfully completed in {1:0}.{2} seconds.", jobImplementation.Name, sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds / 100,
|
|
||||||
sw.Elapsed.Seconds);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.ErrorException("An error has occurred while executing job " + jobImplementation.Name, e);
|
|
||||||
_notification.Status = ProgressNotificationStatus.Failed;
|
|
||||||
_notification.CurrentMessage = jobImplementation.Name + " Failed.";
|
|
||||||
|
|
||||||
settings.LastExecution = DateTime.Now;
|
|
||||||
settings.Success = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Only update last execution status if was triggered by the scheduler
|
|
||||||
if (targetId == 0)
|
|
||||||
{
|
|
||||||
SaveDefinition(settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes jobs in the database using the IJob instances that are
|
/// Initializes jobs in the database using the IJob instances that are
|
||||||
/// registered using ninject
|
/// registered using ninject
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Initialize()
|
public virtual void Initialize()
|
||||||
{
|
{
|
||||||
Logger.Debug("Initializing jobs. Count {0}", _jobs.Count());
|
logger.Debug("Initializing jobs. Count {0}", _jobs.Count());
|
||||||
var currentTimer = All();
|
var currentTimer = All();
|
||||||
|
|
||||||
foreach (var timer in _jobs)
|
foreach (var timer in _jobs)
|
||||||
|
@ -326,6 +96,47 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds/Updates definitions for a job
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="definitions">Settings to be added/updated</param>
|
||||||
|
public virtual void SaveDefinition(JobDefinition definitions)
|
||||||
|
{
|
||||||
|
if (definitions.Id == 0)
|
||||||
|
{
|
||||||
|
logger.Trace("Adding job definitions for {0}", definitions.Name);
|
||||||
|
_database.Insert(definitions);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Trace("Updating job definitions for {0}", definitions.Name);
|
||||||
|
_database.Update(definitions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void QueueScheduled()
|
||||||
|
{
|
||||||
|
lock (executionLock)
|
||||||
|
{
|
||||||
|
VerifyThreadTime();
|
||||||
|
|
||||||
|
if (_jobThread.IsAlive)
|
||||||
|
{
|
||||||
|
logger.Trace("Queue is already running. Ignoring scheduler's request.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var pendingJobTypes = All().Where(
|
||||||
|
t => t.Enable &&
|
||||||
|
(DateTime.Now - t.LastExecution) > TimeSpan.FromMinutes(t.Interval)
|
||||||
|
).Select(c => _jobs.Where(t => t.GetType().ToString() == c.TypeName).Single().GetType()).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
pendingJobTypes.ForEach(jobType => QueueJob(jobType));
|
||||||
|
logger.Trace("{0} Scheduled tasks have been added to the queue", pendingJobTypes.Count);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the next scheduled run time for a specific job
|
/// Gets the next scheduled run time for a specific job
|
||||||
/// (Estimated due to schedule timer)
|
/// (Estimated due to schedule timer)
|
||||||
|
@ -336,5 +147,179 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
var job = All().Where(t => t.TypeName == jobType.ToString()).Single();
|
var job = All().Where(t => t.TypeName == jobType.ToString()).Single();
|
||||||
return job.LastExecution.AddMinutes(job.Interval);
|
return job.LastExecution.AddMinutes(job.Interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void QueueJob(Type jobType, int targetId = 0, int secondaryTargetId = 0)
|
||||||
|
{
|
||||||
|
var queueItem = new JobQueueItem
|
||||||
|
{
|
||||||
|
JobType = jobType,
|
||||||
|
TargetId = targetId,
|
||||||
|
SecondaryTargetId = secondaryTargetId
|
||||||
|
};
|
||||||
|
|
||||||
|
logger.Debug("Attempting to queue {0}", queueItem);
|
||||||
|
|
||||||
|
lock (executionLock)
|
||||||
|
{
|
||||||
|
VerifyThreadTime();
|
||||||
|
|
||||||
|
lock (Queue)
|
||||||
|
{
|
||||||
|
if (!Queue.Contains(queueItem))
|
||||||
|
{
|
||||||
|
Queue.Add(queueItem);
|
||||||
|
logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, Queue.Count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, Queue.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_jobThread.IsAlive)
|
||||||
|
{
|
||||||
|
logger.Trace("Queue is already running. No need to start it up.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResetThread();
|
||||||
|
_jobThreadStopWatch = Stopwatch.StartNew();
|
||||||
|
_jobThread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessQueue()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
using (NestedDiagnosticsContext.Push(Guid.NewGuid().ToString()))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JobQueueItem job = null;
|
||||||
|
|
||||||
|
lock (Queue)
|
||||||
|
{
|
||||||
|
if (Queue.Count != 0)
|
||||||
|
{
|
||||||
|
job = Queue.First();
|
||||||
|
Queue.Remove(job);
|
||||||
|
logger.Debug("Popping {0} from the queue.", job);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (job != null)
|
||||||
|
{
|
||||||
|
Execute(job);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ThreadAbortException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.FatalException("An error has occurred while executing job.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (Queue.Count != 0);
|
||||||
|
|
||||||
|
logger.Trace("Finished processing jobs in the queue.");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (ThreadAbortException e)
|
||||||
|
{
|
||||||
|
logger.Warn(e.Message);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.ErrorException("Error has occurred in queue processor thread", e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ResetThread();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Execute(JobQueueItem queueItem)
|
||||||
|
{
|
||||||
|
var jobImplementation = _jobs.Where(t => t.GetType() == queueItem.JobType).SingleOrDefault();
|
||||||
|
if (jobImplementation == null)
|
||||||
|
{
|
||||||
|
logger.Error("Unable to locate implementation for '{0}'. Make sure it is properly registered.", queueItem.JobType);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var settings = All().Where(j => j.TypeName == queueItem.JobType.ToString()).Single();
|
||||||
|
|
||||||
|
using (_notification = new ProgressNotification(jobImplementation.Name))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger.Debug("Starting {0}. Last execution {1}", queueItem, settings.LastExecution);
|
||||||
|
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
_notificationProvider.Register(_notification);
|
||||||
|
jobImplementation.Start(_notification, queueItem.TargetId, queueItem.SecondaryTargetId);
|
||||||
|
_notification.Status = ProgressNotificationStatus.Completed;
|
||||||
|
|
||||||
|
settings.LastExecution = DateTime.Now;
|
||||||
|
settings.Success = true;
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
logger.Debug("Job {0} successfully completed in {1:0}.{2} seconds.", queueItem, sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds / 100,
|
||||||
|
sw.Elapsed.Seconds);
|
||||||
|
}
|
||||||
|
catch (ThreadAbortException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.ErrorException("An error has occurred while executing job [" + jobImplementation.Name + "].", e);
|
||||||
|
_notification.Status = ProgressNotificationStatus.Failed;
|
||||||
|
_notification.CurrentMessage = jobImplementation.Name + " Failed.";
|
||||||
|
|
||||||
|
settings.LastExecution = DateTime.Now;
|
||||||
|
settings.Success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Only update last execution status if was triggered by the scheduler
|
||||||
|
if (queueItem.TargetId == 0)
|
||||||
|
{
|
||||||
|
SaveDefinition(settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void VerifyThreadTime()
|
||||||
|
{
|
||||||
|
if (_jobThreadStopWatch.Elapsed.TotalHours > 1)
|
||||||
|
{
|
||||||
|
logger.Warn("Thread job has been running for more than an hour. fuck it!");
|
||||||
|
ResetThread();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetThread()
|
||||||
|
{
|
||||||
|
if (_jobThread != null)
|
||||||
|
{
|
||||||
|
_jobThread.Abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Trace("resetting queue processor thread");
|
||||||
|
_jobThread = new Thread(ProcessQueue) { Name = "JobQueueThread" };
|
||||||
|
_jobThreadStopWatch = new Stopwatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,17 +13,15 @@ namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
public class TvDbProvider
|
public class TvDbProvider
|
||||||
{
|
{
|
||||||
private readonly EnviromentProvider _enviromentProvider;
|
|
||||||
private const string TVDB_APIKEY = "5D2D188E86E07F4F";
|
private const string TVDB_APIKEY = "5D2D188E86E07F4F";
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
private readonly TvdbHandler _handler;
|
private readonly TvdbHandler _handler;
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public TvDbProvider(EnviromentProvider enviromentProvider)
|
public TvDbProvider(PathProvider pathProvider)
|
||||||
{
|
{
|
||||||
_enviromentProvider = enviromentProvider;
|
_handler = new TvdbHandler(new XmlCacheProvider(pathProvider.CacheFolder), TVDB_APIKEY);
|
||||||
_handler = new TvdbHandler(new XmlCacheProvider(_enviromentProvider.AppDataPath + @"\cache\tvdb"), TVDB_APIKEY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TvDbProvider()
|
public TvDbProvider()
|
||||||
|
|
|
@ -18,19 +18,22 @@ namespace NzbDrone.Core.Providers
|
||||||
private readonly HttpProvider _httpProvider;
|
private readonly HttpProvider _httpProvider;
|
||||||
private readonly ConfigProvider _configProvider;
|
private readonly ConfigProvider _configProvider;
|
||||||
private readonly EnviromentProvider _enviromentProvider;
|
private readonly EnviromentProvider _enviromentProvider;
|
||||||
|
private readonly PathProvider _pathProvider;
|
||||||
private readonly DiskProvider _diskProvider;
|
private readonly DiskProvider _diskProvider;
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase);
|
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
public const string SandboxFolderName = "nzbdrone_update";
|
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, EnviromentProvider enviromentProvider, DiskProvider diskProvider)
|
public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, EnviromentProvider enviromentProvider,
|
||||||
|
PathProvider pathProvider, DiskProvider diskProvider)
|
||||||
{
|
{
|
||||||
_httpProvider = httpProvider;
|
_httpProvider = httpProvider;
|
||||||
_configProvider = configProvider;
|
_configProvider = configProvider;
|
||||||
_enviromentProvider = enviromentProvider;
|
_enviromentProvider = enviromentProvider;
|
||||||
|
_pathProvider = pathProvider;
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,15 +76,14 @@ namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
public virtual void PreformUpdate(UpdatePackage updatePackage)
|
public virtual void PreformUpdate(UpdatePackage updatePackage)
|
||||||
{
|
{
|
||||||
var tempSubFolder = Path.Combine(_enviromentProvider.TempPath, SandboxFolderName);
|
var packageDestination = Path.Combine(_pathProvider.UpdateSandboxFolder, updatePackage.FileName);
|
||||||
var packageDestination = Path.Combine(tempSubFolder, updatePackage.FileName);
|
|
||||||
|
|
||||||
Logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
|
Logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
|
||||||
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
|
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
|
||||||
Logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
|
Logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
|
||||||
|
|
||||||
Logger.Info("Extracting Update package");
|
Logger.Info("Extracting Update package");
|
||||||
_diskProvider.ExtractArchive(packageDestination, tempSubFolder);
|
_diskProvider.ExtractArchive(packageDestination, _pathProvider.UpdateSandboxFolder);
|
||||||
Logger.Info("Update package extracted successfully");
|
Logger.Info("Update package extracted successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,18 +6,23 @@ using NzbDrone.Core.Providers.Jobs;
|
||||||
|
|
||||||
namespace NzbDrone.Core
|
namespace NzbDrone.Core
|
||||||
{
|
{
|
||||||
class WebTimer
|
public class WebTimer
|
||||||
{
|
{
|
||||||
private readonly JobProvider _jobProvider;
|
private readonly JobProvider _jobProvider;
|
||||||
|
|
||||||
private static CacheItemRemovedCallback _onCacheRemove;
|
private static CacheItemRemovedCallback _onCacheRemove;
|
||||||
|
private static bool _stop;
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public WebTimer(JobProvider jobProvider)
|
public WebTimer(JobProvider jobProvider)
|
||||||
{
|
{
|
||||||
_jobProvider = jobProvider;
|
_jobProvider = jobProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Make timer doesn't keep running during unit tests.
|
||||||
public void StartTimer(int secondInterval)
|
public void StartTimer(int secondInterval)
|
||||||
{
|
{
|
||||||
_onCacheRemove = new CacheItemRemovedCallback(DoWork);
|
_onCacheRemove = new CacheItemRemovedCallback(DoWork);
|
||||||
|
@ -29,9 +34,18 @@ namespace NzbDrone.Core
|
||||||
|
|
||||||
|
|
||||||
public void DoWork(string k, object v, CacheItemRemovedReason r)
|
public void DoWork(string k, object v, CacheItemRemovedReason r)
|
||||||
|
{
|
||||||
|
if (!_stop)
|
||||||
{
|
{
|
||||||
_jobProvider.QueueScheduled();
|
_jobProvider.QueueScheduled();
|
||||||
StartTimer(Convert.ToInt32(v));
|
StartTimer(Convert.ToInt32(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Stop()
|
||||||
|
{
|
||||||
|
Logger.Info("Stopping Web Timer");
|
||||||
|
_stop = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,10 @@ namespace NzbDrone.Test.Common
|
||||||
string exception = "";
|
string exception = "";
|
||||||
if (log.Exception != null)
|
if (log.Exception != null)
|
||||||
{
|
{
|
||||||
exception = log.Exception.Message;
|
exception = "[" + log.Exception.Message + "]";
|
||||||
}
|
}
|
||||||
errors += Environment.NewLine + String.Format("[{0}] {1}: {2} [{3}]", log.Level, log.LoggerName, log.FormattedMessage, exception);
|
|
||||||
|
errors += Environment.NewLine + String.Format("[{0}] {1}: {2} {3}", log.Level, log.LoggerName, log.FormattedMessage, exception);
|
||||||
}
|
}
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
@ -87,8 +88,6 @@ namespace NzbDrone.Test.Common
|
||||||
|
|
||||||
private static void Excpected(LogLevel level, int count)
|
private static void Excpected(LogLevel level, int count)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
var levelLogs = _logs.Where(l => l.Level == level).ToList();
|
var levelLogs = _logs.Where(l => l.Level == level).ToList();
|
||||||
|
|
||||||
if (levelLogs.Count != count)
|
if (levelLogs.Count != count)
|
||||||
|
@ -97,9 +96,9 @@ namespace NzbDrone.Test.Common
|
||||||
var message = String.Format("{0} {1}(s) were expected but {2} were logged.\n\r{3}",
|
var message = String.Format("{0} {1}(s) were expected but {2} were logged.\n\r{3}",
|
||||||
count, level, levelLogs.Count, GetLogsString(levelLogs));
|
count, level, levelLogs.Count, GetLogsString(levelLogs));
|
||||||
|
|
||||||
message = "********************************************************************************************************************************\n\r"
|
message = "\n\r****************************************************************************************\n\r"
|
||||||
+ message +
|
+ message +
|
||||||
"\n\r********************************************************************************************************************************";
|
"\n\r****************************************************************************************";
|
||||||
|
|
||||||
Assert.Fail(message);
|
Assert.Fail(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
|
|
||||||
namespace NzbDrone.Test.Common
|
namespace NzbDrone.Test.Common
|
||||||
{
|
{
|
||||||
public abstract class LoggingFixtures
|
public abstract class LoggingTest
|
||||||
{
|
{
|
||||||
|
protected static void InitLogging()
|
||||||
[SetUp]
|
|
||||||
public void SetUpBase()
|
|
||||||
{
|
{
|
||||||
|
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
|
||||||
|
{
|
||||||
|
LogManager.Configuration = new LoggingConfiguration();
|
||||||
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
|
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
|
||||||
LogConfiguration.RegisterUdpLogger();
|
LogConfiguration.RegisterUdpLogger();
|
||||||
|
|
||||||
RegisterExceptionVerification();
|
RegisterExceptionVerification();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void RegisterExceptionVerification()
|
private static void RegisterExceptionVerification()
|
||||||
{
|
{
|
|
@ -69,7 +69,7 @@
|
||||||
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
|
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
|
||||||
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
|
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
|
||||||
<Compile Include="ExceptionVerification.cs" />
|
<Compile Include="ExceptionVerification.cs" />
|
||||||
<Compile Include="LoggingFixtures.cs" />
|
<Compile Include="LoggingTest.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -3,6 +3,6 @@ using NUnit.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
[SetUpFixture]
|
[SetUpFixture]
|
||||||
public class Fixtures : LoggingFixtures
|
public class Fixtures : LoggingTest
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,9 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
|
||||||
|
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Providers\UpdateProvider.cs" />
|
<Compile Include="Providers\UpdateProvider.cs" />
|
||||||
|
|
|
@ -1,36 +1,16 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("NzbDrone.Update")]
|
[assembly: AssemblyTitle("NzbDrone.Update")]
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("Microsoft")]
|
|
||||||
[assembly: AssemblyProduct("NzbDrone.Update")]
|
|
||||||
[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
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
[assembly: Guid("e4560a3d-8053-4d57-a260-bfe52f4cc357")]
|
[assembly: Guid("e4560a3d-8053-4d57-a260-bfe52f4cc357")]
|
||||||
|
|
||||||
// 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
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("0.6.0.*")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("0.6.0.*")]
|
|
@ -130,15 +130,10 @@ hr
|
||||||
|
|
||||||
|
|
||||||
/* Footer */
|
/* Footer */
|
||||||
.timer
|
.footer
|
||||||
{
|
{
|
||||||
text-align: center;
|
padding: 1px 1px 1px 1px;
|
||||||
color: #065EFE;
|
color: #065EFE;
|
||||||
}
|
|
||||||
|
|
||||||
#footer
|
|
||||||
{
|
|
||||||
padding: 1px, 1px, 1px, 1px;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
display: none;
|
display: none;
|
||||||
|
|
||||||
@*Rounded Edges*@
|
|
||||||
border:1px solid #444444;
|
border:1px solid #444444;
|
||||||
-moz-border-radius-bottomright: 8px;
|
-moz-border-radius-bottomright: 8px;
|
||||||
-webkit-border-bottom-right-radius: 8px;
|
-webkit-border-bottom-right-radius: 8px;
|
||||||
|
@ -37,7 +36,6 @@
|
||||||
color:#FFFFFF;
|
color:#FFFFFF;
|
||||||
|
|
||||||
|
|
||||||
@*Rounded Edges*@
|
|
||||||
border: 1px solid #444444;
|
border: 1px solid #444444;
|
||||||
border-top: 0px;
|
border-top: 0px;
|
||||||
-moz-border-radius-bottomright: 10px;
|
-moz-border-radius-bottomright: 10px;
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Core.Providers;
|
using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.Jobs;
|
using NzbDrone.Core.Providers.Jobs;
|
||||||
|
using NzbDrone.Web.Models;
|
||||||
|
|
||||||
namespace NzbDrone.Web.Controllers
|
namespace NzbDrone.Web.Controllers
|
||||||
{
|
{
|
||||||
public class SharedController : Controller
|
public class SharedController : Controller
|
||||||
{
|
{
|
||||||
private readonly JobProvider _jobProvider;
|
private readonly JobProvider _jobProvider;
|
||||||
|
private readonly EnviromentProvider _enviromentProvider;
|
||||||
|
|
||||||
public SharedController(JobProvider jobProvider)
|
public SharedController(JobProvider jobProvider, EnviromentProvider enviromentProvider)
|
||||||
{
|
{
|
||||||
_jobProvider = jobProvider;
|
_jobProvider = jobProvider;
|
||||||
|
_enviromentProvider = enviromentProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
|
@ -22,8 +26,8 @@ namespace NzbDrone.Web.Controllers
|
||||||
[ChildActionOnly]
|
[ChildActionOnly]
|
||||||
public ActionResult Footer()
|
public ActionResult Footer()
|
||||||
{
|
{
|
||||||
ViewData["RssTimer"] = _jobProvider.NextScheduledRun(typeof(RssSyncJob)).ToString("yyyyMMddHHmmss");
|
|
||||||
return PartialView();
|
return PartialView(new FooterModel { BuildTime = _enviromentProvider.BuildDateTime, Version = _enviromentProvider.Version });
|
||||||
}
|
}
|
||||||
|
|
||||||
[ChildActionOnly]
|
[ChildActionOnly]
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace NzbDrone.Web
|
||||||
//base.OnApplicationStarted();
|
//base.OnApplicationStarted();
|
||||||
AreaRegistration.RegisterAllAreas();
|
AreaRegistration.RegisterAllAreas();
|
||||||
|
|
||||||
var razor =ViewEngines.Engines.Where(e => e.GetType() == typeof (RazorViewEngine)).Single();
|
var razor = ViewEngines.Engines.Where(e => e.GetType() == typeof(RazorViewEngine)).Single();
|
||||||
ViewEngines.Engines.Clear();
|
ViewEngines.Engines.Clear();
|
||||||
ViewEngines.Engines.Add(razor);
|
ViewEngines.Engines.Add(razor);
|
||||||
|
|
||||||
|
@ -54,15 +54,14 @@ namespace NzbDrone.Web
|
||||||
|
|
||||||
protected override IKernel CreateKernel()
|
protected override IKernel CreateKernel()
|
||||||
{
|
{
|
||||||
LogConfiguration.Setup();
|
|
||||||
Logger.Info("NZBDrone Starting up.");
|
|
||||||
CentralDispatch.DedicateToHost();
|
|
||||||
|
|
||||||
var kernel = CentralDispatch.NinjectKernel;
|
var dispatch = new CentralDispatch();
|
||||||
|
Logger.Info("NzbDrone Starting up.");
|
||||||
|
|
||||||
// kernel.Bind<IRepository>().ToConstant(kernel.Get<IRepository>("LogDb"));
|
dispatch.DedicateToHost();
|
||||||
kernel.Load(Assembly.GetExecutingAssembly());
|
|
||||||
return kernel;
|
dispatch.Kernel.Load(Assembly.GetExecutingAssembly());
|
||||||
|
return dispatch.Kernel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace NzbDrone.Web.Models
|
||||||
|
{
|
||||||
|
public class FooterModel
|
||||||
|
{
|
||||||
|
public Version Version { get; set; }
|
||||||
|
public DateTime BuildTime { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -338,6 +338,9 @@
|
||||||
<Content Include="Content\Images\Unpacking.png" />
|
<Content Include="Content\Images\Unpacking.png" />
|
||||||
<Content Include="Content\jquery.gritter.css" />
|
<Content Include="Content\jquery.gritter.css" />
|
||||||
<Content Include="Content\Menu.css" />
|
<Content Include="Content\Menu.css" />
|
||||||
|
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
|
||||||
|
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="App_GlobalResources\EditorLocalization.bg-BG.designer.cs">
|
<Compile Include="App_GlobalResources\EditorLocalization.bg-BG.designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
@ -486,6 +489,7 @@
|
||||||
<Compile Include="Helpers\DescriptionExtension.cs" />
|
<Compile Include="Helpers\DescriptionExtension.cs" />
|
||||||
<Compile Include="Helpers\HtmlPrefixScopeExtensions.cs" />
|
<Compile Include="Helpers\HtmlPrefixScopeExtensions.cs" />
|
||||||
<Compile Include="Helpers\IsCurrentActionHelper.cs" />
|
<Compile Include="Helpers\IsCurrentActionHelper.cs" />
|
||||||
|
<Compile Include="Models\CodeFile1.cs" />
|
||||||
<Compile Include="Models\ExistingSeriesModel.cs" />
|
<Compile Include="Models\ExistingSeriesModel.cs" />
|
||||||
<Compile Include="Models\AddNewSeriesModel.cs" />
|
<Compile Include="Models\AddNewSeriesModel.cs" />
|
||||||
<Compile Include="Models\JobQueueItemModel.cs" />
|
<Compile Include="Models\JobQueueItemModel.cs" />
|
||||||
|
|
|
@ -1,37 +1,13 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
[assembly: AssemblyTitle("NzbDrone.Web")]
|
||||||
// set of attributes. Change these attribute values to modify the information
|
|
||||||
// associated with an assembly.
|
|
||||||
|
|
||||||
[assembly: AssemblyTitle("NZBDrone.Web")]
|
|
||||||
[assembly: AssemblyDescription("NZBDrone Web Interface")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("www.nzbdrone.com")]
|
|
||||||
[assembly: AssemblyProduct("NZBDrone")]
|
|
||||||
[assembly: AssemblyCopyright("GNU General Public v3")]
|
|
||||||
[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
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
|
||||||
[assembly: Guid("1ec2c814-7c1e-470d-bbae-59b129b720fd")]
|
[assembly: Guid("1ec2c814-7c1e-470d-bbae-59b129b720fd")]
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
//
|
|
||||||
// Major Version
|
|
||||||
// Minor Version
|
|
||||||
// Build Number
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// You can specify all the values or you can default the Revision and Build Numbers
|
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
|
|
||||||
[assembly: AssemblyVersion("0.6.0.*")]
|
[assembly: AssemblyVersion("0.6.0.*")]
|
||||||
|
[assembly: AssemblyFileVersion("0.6.0.*")]
|
|
@ -2,7 +2,7 @@
|
||||||
@using NzbDrone.Web.Models;
|
@using NzbDrone.Web.Models;
|
||||||
@model IEnumerable<NzbDrone.Core.Repository.Series>
|
@model IEnumerable<NzbDrone.Core.Repository.Series>
|
||||||
@section TitleContent{
|
@section TitleContent{
|
||||||
NZBDrone
|
NzbDrone
|
||||||
}
|
}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
@model System.Web.Mvc.HandleErrorInfo
|
@model HandleErrorInfo
|
||||||
|
|
||||||
@section TitleContent
|
@section TitleContent
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
@using NzbDrone.Core
|
@using NzbDrone.Web.Models
|
||||||
|
@model FooterModel
|
||||||
<div>
|
<div>
|
||||||
@*NZBDrone @CentralDispatch.Version (@CentralDispatch.BuildDateTime.ToString("MMM d, yyyy"))*@
|
NzbDrone @Model.Version (@Model.BuildTime.ToString("MMM d, yyyy"))
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head runat="server">
|
<head runat="server">
|
||||||
<link rel="SHORTCUT ICON" href="../../favicon.ico" />
|
<link rel="SHORTCUT ICON" href="../../favicon.ico" />
|
||||||
<title>NZBDrone</title>
|
<title>NzbDrone</title>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<link type="text/css" rel="stylesheet" href="/Content/2011.2.712/telerik.common.min.css" />
|
<link type="text/css" rel="stylesheet" href="/Content/2011.2.712/telerik.common.min.css" />
|
||||||
<link type="text/css" rel="stylesheet" href="/Content/2011.2.712/telerik.sitefinity.min.css" />
|
<link type="text/css" rel="stylesheet" href="/Content/2011.2.712/telerik.sitefinity.min.css" />
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
<div id="footer" class="span-24 last">
|
<div class="span-24 last footer">
|
||||||
@{Html.RenderAction("Footer", "Shared");}
|
@{Html.RenderAction("Footer", "Shared");}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -87,6 +87,9 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
|
||||||
|
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="ApplicationServer.cs">
|
<Compile Include="ApplicationServer.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
@ -5,35 +5,11 @@ using System.Runtime.InteropServices;
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
|
|
||||||
[assembly: AssemblyTitle("NZBDrone")]
|
[assembly: AssemblyTitle("NzbDrone.exe")]
|
||||||
[assembly: AssemblyDescription("NZBDrone")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("www.nzbdrone.com")]
|
|
||||||
[assembly: AssemblyProduct("NZBDrone")]
|
|
||||||
[assembly: AssemblyCopyright("GNU General Public v3")]
|
|
||||||
[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("67AADCD9-89AA-4D95-8281-3193740E70E5")]
|
[assembly: Guid("67AADCD9-89AA-4D95-8281-3193740E70E5")]
|
||||||
|
|
||||||
|
|
||||||
// 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
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
|
|
||||||
[assembly: AssemblyVersion("0.6.0.*")]
|
[assembly: AssemblyVersion("0.6.0.*")]
|
||||||
|
[assembly: AssemblyFileVersion("0.6.0.*")]
|
|
@ -112,7 +112,7 @@ namespace NzbDrone.Providers
|
||||||
new Client
|
new Client
|
||||||
{
|
{
|
||||||
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
|
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
|
||||||
ApplicationName = "NZBDrone",
|
ApplicationName = "NzbDrone",
|
||||||
CurrentException = excepion as Exception
|
CurrentException = excepion as Exception
|
||||||
}.Submit();
|
}.Submit();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||||
|
<Config />
|
Loading…
Reference in New Issue