Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus

Fixed CentalDispatch Conflicts.
pull/7/merge
Mark McDowall 13 years ago
commit bbd5cba272

@ -3,6 +3,6 @@ using NUnit.Framework;
using NzbDrone.Test.Common;
[SetUpFixture]
public class Fixtures : LoggingFixtures
public class Fixtures : LoggingTest
{
}

@ -1,5 +1,6 @@
// ReSharper disable InconsistentNaming
using System;
using System.IO;
using FluentAssertions;
using NUnit.Framework;
@ -9,35 +10,21 @@ namespace NzbDrone.Common.Test
[TestFixture]
public class EnviromentProviderTest
{
readonly EnviromentProvider enviromentController = new EnviromentProvider();
[Test]
public void Is_user_interactive_should_be_false()
{
enviromentController.IsUserInteractive.Should().BeTrue();
}
[Test]
public void Log_path_should_not_be_empty()
{
enviromentController.LogPath.Should().NotBeBlank();
Path.IsPathRooted(enviromentController.LogPath).Should().BeTrue("Path is not rooted");
}
readonly EnviromentProvider enviromentProvider = new EnviromentProvider();
[Test]
public void StartupPath_should_not_be_empty()
{
enviromentController.StartUpPath.Should().NotBeBlank();
Path.IsPathRooted(enviromentController.StartUpPath).Should().BeTrue("Path is not rooted");
enviromentProvider.StartUpPath.Should().NotBeBlank();
Path.IsPathRooted(enviromentProvider.StartUpPath).Should().BeTrue("Path is not rooted");
}
[Test]
public void ApplicationPath_should_not_be_empty()
{
enviromentController.ApplicationPath.Should().NotBeBlank();
Path.IsPathRooted(enviromentController.ApplicationPath).Should().BeTrue("Path is not rooted");
enviromentProvider.ApplicationPath.Should().NotBeBlank();
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()
{
Directory.CreateDirectory(EnviromentProvider.IIS_FOLDER_NAME);
enviromentController.ApplicationPath.Should().BeEquivalentTo(Directory.GetCurrentDirectory());
enviromentProvider.ApplicationPath.Should().BeEquivalentTo(Directory.GetCurrentDirectory());
}
[Test]
@ -53,5 +40,12 @@ namespace NzbDrone.Common.Test
{
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;
[SetUpFixture]
public class Fixtures : LoggingFixtures
public class Fixtures : LoggingTest
{
}

@ -65,7 +65,6 @@
<Compile Include="EnviromentProviderTest.cs" />
<Compile Include="Fixtures.cs" />
<Compile Include="ProcessProviderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceControllerTests.cs" />
<Compile Include="WebClientTests.cs" />
</ItemGroup>
@ -86,6 +85,9 @@
<Name>NzbDrone.Test.Dummy</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

@ -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
{
get { return Environment.UserInteractive; }
@ -68,26 +63,7 @@ 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
{
get
@ -111,15 +87,6 @@ namespace NzbDrone.Common
}
public virtual String TempPath
{
get
{
return Path.GetTempPath();
}
}
private static bool ContainsIIS(DirectoryInfo dir)
{
return dir.GetDirectories(IIS_FOLDER_NAME).Length != 0;

@ -21,7 +21,7 @@ namespace NzbDrone.Common
new Client
{
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
ApplicationName = "NZBDrone",
ApplicationName = "NzbDrone",
CurrentException = logEvent.Exception
}.Submit();

@ -50,6 +50,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ConsoleProvider.cs" />
<Compile Include="PathProvider.cs" />
<Compile Include="DiskProvider.cs" />
<Compile Include="EnviromentProvider.cs" />
<Compile Include="ExceptioneerTarget.cs" />
@ -57,6 +58,7 @@
<Compile Include="Model\ProcessInfo.cs" />
<Compile Include="ProcessProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\SharedAssemblyInfo.cs" />
<Compile Include="ServiceProvider.cs" />
<Compile Include="WebClientProvider.cs" />
</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.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")]
[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
[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
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.6.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.Collections.Generic;
using System.Linq;
using System.Text;
using FluentAssertions;
using NLog;
using NUnit.Framework;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Jobs;
@ -16,16 +13,23 @@ namespace NzbDrone.Core.Test
{
[TestFixture]
// 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> jobs = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IJob))).ToList();
private CentralDispatch centralDispatch;
[SetUp]
public void Setup()
{
centralDispatch = new CentralDispatch();
}
[Test]
public void InitAppTest()
{
CentralDispatch.NinjectKernel.Should().NotBeNull();
centralDispatch.Kernel.Should().NotBeNull();
}
[Test]
@ -38,7 +42,7 @@ namespace NzbDrone.Core.Test
foreach (var provider in providers)
{
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
var registeredJobs = CentralDispatch.NinjectKernel.GetAll<IJob>();
var registeredJobs = centralDispatch.Kernel.GetAll<IJob>();
jobs.Should().NotBeEmpty();
@ -61,7 +65,7 @@ namespace NzbDrone.Core.Test
{
//Assert
var registeredIndexers = CentralDispatch.NinjectKernel.GetAll<IndexerBase>();
var registeredIndexers = centralDispatch.Kernel.GetAll<IndexerBase>();
indexers.Should().NotBeEmpty();
@ -72,26 +76,26 @@ namespace NzbDrone.Core.Test
[Test]
public void jobs_are_initialized()
{
CentralDispatch.NinjectKernel.Get<JobProvider>().All().Should().HaveSameCount(jobs);
centralDispatch.Kernel.Get<JobProvider>().All().Should().HaveSameCount(jobs);
}
[Test]
public void indexers_are_initialized()
{
CentralDispatch.NinjectKernel.Get<IndexerProvider>().All().Should().HaveSameCount(indexers);
centralDispatch.Kernel.Get<IndexerProvider>().All().Should().HaveSameCount(indexers);
}
[Test]
public void quality_profile_initialized()
{
CentralDispatch.NinjectKernel.Get<QualityProvider>().All().Should().HaveCount(2);
centralDispatch.Kernel.Get<QualityProvider>().All().Should().HaveCount(2);
}
[Test]
public void JobProvider_should_be_singletone()
{
var first = CentralDispatch.NinjectKernel.Get<JobProvider>();
var second = CentralDispatch.NinjectKernel.Get<JobProvider>();
var first = centralDispatch.Kernel.Get<JobProvider>();
var second = centralDispatch.Kernel.Get<JobProvider>();
first.Should().BeSameAs(second);
}

@ -4,22 +4,22 @@ using NUnit.Framework;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
[SetUpFixture]
public class Fixtures : LoggingFixtures
{
[SetUp]
public void SetUp()
{
var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
foreach (var file in oldDbFiles)
{
try
{
File.Delete(file);
}
catch { }
}
//[SetUpFixture]
//public class Fixtures : LoggingFixtures
//{
// //[SetUp]
// //public void SetUp()
// //{
// // var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
// // foreach (var file in oldDbFiles)
// // {
// // try
// // {
// // File.Delete(file);
// // }
// // catch { }
// // }
MockLib.CreateDataBaseTemplate();
}
}
// // MockLib.CreateDataBaseTemplate();
// //}
//}

@ -18,6 +18,7 @@ namespace NzbDrone.Core.Test.Framework
public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
{
Console.WriteLine("====================DataBase====================");
Console.WriteLine("Cloning database from template.");
if (String.IsNullOrWhiteSpace(fileName))
@ -31,6 +32,10 @@ namespace NzbDrone.Core.Test.Framework
var database = Connection.GetPetaPocoDb(connectionString);
Console.WriteLine("====================DataBase====================");
Console.WriteLine();
Console.WriteLine();
return database;
}

@ -1,16 +1,52 @@
using System.IO;
using AutoMoq;
using Moq;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Test.Common;
using PetaPoco;
namespace NzbDrone.Core.Test.Framework
{
public class TestBase
public class TestBase : LoggingTest
// 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]
public virtual void SetupBase()
{
InitLogging();
ExceptionVerification.Reset();
if (Directory.Exists(TempFolder))
{
@ -18,12 +54,42 @@ namespace NzbDrone.Core.Test.Framework
}
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]
public void TearDownBase()
{
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
public class BannerDownloadJobTest : TestBase
{
[SetUp]
public void Setup()
{
WithStrictMocker();
WithTempAsStartUpPath();
}
[Test]
public void BannerDownload_all()
{
@ -26,28 +34,25 @@ namespace NzbDrone.Core.Test.JobTests
var fakeSeries = Builder<Series>.CreateListOfSize(10)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetAllSeries())
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Times.Exactly(fakeSeries.Count));
}
@ -60,28 +65,25 @@ namespace NzbDrone.Core.Test.JobTests
.With(s => s.BannerUrl = null)
.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())
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Times.Exactly(8));
}
@ -92,66 +94,64 @@ namespace NzbDrone.Core.Test.JobTests
var fakeSeries = Builder<Series>.CreateListOfSize(10)
.Build();
var path = Path.Combine(new EnviromentProvider().WebRoot, "Content", "Images", "Banners");
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var pathProvider = Mocker.Resolve<PathProvider>();
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetAllSeries())
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "1.jpg")))
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "1.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "2.jpg")));
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "2.jpg")));
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "3.jpg")))
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "3.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "4.jpg")));
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "4.jpg")));
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "5.jpg")))
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "5.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "6.jpg")));
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "6.jpg")));
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "7.jpg")))
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "7.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "8.jpg")));
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "8.jpg")));
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "9.jpg")))
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "9.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "10.jpg")));
Mocker.GetMock<HttpProvider>()
.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>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Times.Exactly(fakeSeries.Count));
}
@ -162,29 +162,26 @@ namespace NzbDrone.Core.Test.JobTests
var fakeSeries = Builder<Series>.CreateListOfSize(10)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetAllSeries())
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
.Throws(new WebException());
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Times.Exactly(fakeSeries.Count));
}
@ -196,29 +193,26 @@ namespace NzbDrone.Core.Test.JobTests
.With(s => s.SeriesId = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<SeriesProvider>()
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetSeries(1))
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
.Throws(new WebException());
mocker.GetMock<DiskProvider>()
Mocker.GetMock<DiskProvider>()
.Setup(S => S.CreateDirectory(It.IsAny<string>()))
.Returns("");
//Act
mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
Mocker.Resolve<BannerDownloadJob>().Start(notification, 1, 0);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Times.Once());
}
@ -230,20 +224,18 @@ namespace NzbDrone.Core.Test.JobTests
.With(s => s.SeriesId = 1)
.Build();
var mocker = new AutoMoqer(MockBehavior.Strict);
var notification = new ProgressNotification("Banner Download");
mocker.GetMock<HttpProvider>()
Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
.Throws(new WebException());
//Act
mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
Mocker.Resolve<BannerDownloadJob>().DownloadBanner(notification, fakeSeries);
//Assert
mocker.VerifyAllMocks();
mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Mocker.VerifyAllMocks();
Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
Times.Once());
}
}

@ -91,6 +91,7 @@
<Compile Include="ProviderTests\PostDownloadProviderTests\PostDownloadProviderFixture.cs" />
<Compile Include="JobTests\SearchJobTest.cs" />
<Compile Include="ProviderTests\PostDownloadProviderTests\ProcessDownloadFixture.cs" />
<Compile Include="ProviderTests\JobProviderTests\TestJobs.cs" />
<Compile Include="ProviderTests\UpdateProviderTests\PreformUpdateFixture.cs" />
<Compile Include="ProviderTests\UpdateProviderTests\GetAvilableUpdateFixture.cs" />
<Compile Include="SortHelperTest.cs" />
@ -103,7 +104,7 @@
<Compile Include="JobTests\SeriesSearchJobTest.cs" />
<Compile Include="ProviderTests\SearchProviderTest_Season.cs" />
<Compile Include="ProviderTests\EventClientProviderTest.cs" />
<Compile Include="CentralDispatchTest.cs" />
<Compile Include="CentralDispatchFixture.cs" />
<Compile Include="ProviderTests\XbmcProviderTest.cs" />
<Compile Include="ProviderTests\DiskScanProviderTest.cs" />
<Compile Include="ProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" />
@ -122,7 +123,7 @@
<Compile Include="JobTests\DiskScanJobTest.cs" />
<Compile Include="IndexerTests.cs" />
<Compile Include="ProviderTests\InventoryProvider_QualityNeededTest.cs" />
<Compile Include="ProviderTests\JobProviderTest.cs" />
<Compile Include="ProviderTests\JobProviderTests\JobProviderTest.cs" />
<Compile Include="QualityTest.cs" />
<Compile Include="ProviderTests\RootDirProviderTest.cs" />
<Compile Include="ProviderTests\IndexerProviderTest.cs" />

@ -2,6 +2,7 @@
using AutoMoq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework;
@ -15,14 +16,15 @@ namespace NzbDrone.Core.Test.ProviderTests
[SetUp]
public void SetUp()
{
WithTempAsStartUpPath();
//Reset config file
var mocker = new AutoMoqer();
var configFile = mocker.Resolve<ConfigFileProvider>().ConfigFile;
var configFile = Mocker.Resolve<PathProvider>().AppConfigFile;
if (File.Exists(configFile))
File.Delete(configFile);
mocker.Resolve<ConfigFileProvider>().CreateDefaultConfigFile();
Mocker.Resolve<ConfigFileProvider>().CreateDefaultConfigFile();
}
[Test]
@ -31,10 +33,8 @@ namespace NzbDrone.Core.Test.ProviderTests
const string key = "Port";
const string value = "8989";
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
//Assert
result.Should().Be(value);
@ -46,10 +46,8 @@ namespace NzbDrone.Core.Test.ProviderTests
const string key = "Port";
const int value = 8989;
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
var result = Mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
//Assert
result.Should().Be(value);
@ -64,7 +62,7 @@ namespace NzbDrone.Core.Test.ProviderTests
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
var result = Mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
//Assert
result.Should().BeTrue();
@ -76,7 +74,7 @@ namespace NzbDrone.Core.Test.ProviderTests
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
//Assert
result.Should().Be(true);
@ -87,10 +85,8 @@ namespace NzbDrone.Core.Test.ProviderTests
{
const int value = 8989;
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().Port;
var result = Mocker.Resolve<ConfigFileProvider>().Port;
//Assert
result.Should().Be(value);
@ -102,13 +98,11 @@ namespace NzbDrone.Core.Test.ProviderTests
const string key = "LaunchBrowser";
const bool value = false;
var mocker = new AutoMoqer();
//Act
mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
//Assert
var result = mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
var result = Mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
result.Should().Be(value);
}
@ -118,13 +112,11 @@ namespace NzbDrone.Core.Test.ProviderTests
const string key = "Port";
const int value = 12345;
var mocker = new AutoMoqer();
//Act
mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
Mocker.Resolve<ConfigFileProvider>().SetValue(key, value);
//Assert
var result = mocker.Resolve<ConfigFileProvider>().Port;
var result = Mocker.Resolve<ConfigFileProvider>().Port;
result.Should().Be(value);
}
@ -134,10 +126,8 @@ namespace NzbDrone.Core.Test.ProviderTests
const string key = "Hello";
const string value = "World";
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
//Assert
result.Should().Be(value);
@ -149,10 +139,8 @@ namespace NzbDrone.Core.Test.ProviderTests
const string key = "Hello";
const string value = "World";
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value, "Universe");
var result = Mocker.Resolve<ConfigFileProvider>().GetValue(key, value, "Universe");
//Assert
result.Should().Be(value);
@ -161,10 +149,9 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test]
public void GetAuthenticationType_No_Existing_Value()
{
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
//Assert
result.Should().Be(AuthenticationType.Anonymous);
@ -173,11 +160,11 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test]
public void GetAuthenticationType_Windows()
{
var mocker = new AutoMoqer();
mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
Mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
//Act
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
var result = Mocker.Resolve<ConfigFileProvider>().AuthenticationType;
//Assert
result.Should().Be(AuthenticationType.Windows);

@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.ProviderTests
private EpisodeParseResult parseResultSingle;
[SetUp]
public new void Setup()
public void Setup()
{
parseResultMulti = new EpisodeParseResult()
{

@ -1,5 +1,6 @@
// ReSharper disable RedundantUsingDirective
using System.Linq;
using System;
using System.Collections.Generic;
using System.Threading;
@ -7,12 +8,11 @@ using AutoMoq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests
namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
@ -21,11 +21,11 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test]
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();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
//Act
var timerProvider = mocker.Resolve<JobProvider>();
@ -42,11 +42,11 @@ namespace NzbDrone.Core.Test.ProviderTests
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();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
//Act
var timerProvider = mocker.Resolve<JobProvider>();
@ -65,12 +65,12 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test]
public void scheduler_skips_jobs_that_arent_mature_yet()
{
var fakeJob = new FakeJob();
var BaseFakeJob = new FakeJob();
var mocker = new AutoMoqer();
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
IList<IJob> BaseFakeJobs = new List<IJob> { BaseFakeJob };
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
@ -79,7 +79,7 @@ namespace NzbDrone.Core.Test.ProviderTests
timerProvider.QueueScheduled();
Thread.Sleep(500);
fakeJob.ExecutionCount.Should().Be(1);
BaseFakeJob.ExecutionCount.Should().Be(1);
}
[Test]
@ -87,12 +87,12 @@ namespace NzbDrone.Core.Test.ProviderTests
//after execution so the job can successfully run.
public void can_run_async_job_again()
{
var fakeJob = new FakeJob();
var BaseFakeJob = new FakeJob();
var mocker = new AutoMoqer();
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
IList<IJob> BaseFakeJobs = new List<IJob> { BaseFakeJob };
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var jobProvider = mocker.Resolve<JobProvider>();
jobProvider.Initialize();
@ -101,17 +101,17 @@ namespace NzbDrone.Core.Test.ProviderTests
jobProvider.QueueJob(typeof(FakeJob));
Thread.Sleep(2000);
jobProvider.Queue.Should().BeEmpty();
fakeJob.ExecutionCount.Should().Be(2);
BaseFakeJob.ExecutionCount.Should().Be(2);
}
[Test]
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();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var jobProvider = mocker.Resolve<JobProvider>();
jobProvider.Initialize();
@ -132,11 +132,11 @@ namespace NzbDrone.Core.Test.ProviderTests
public void can_run_broken_async_job_again()
{
var brokenJob = new BrokenJob();
IList<IJob> fakeJobs = new List<IJob> { brokenJob };
IList<IJob> BaseFakeJobs = new List<IJob> { brokenJob };
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var jobProvider = mocker.Resolve<JobProvider>();
jobProvider.Initialize();
@ -152,54 +152,48 @@ namespace NzbDrone.Core.Test.ProviderTests
}
[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()
{
var slowJob = new SlowJob();
IList<IJob> fakeJobs = new List<IJob> { slowJob };
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
WithRealDb();
var fakeJob = new FakeJob();
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
var thread1 = new Thread(() => timerProvider.QueueScheduled());
thread1.Start();
Thread.Sleep(1000);
var thread2 = new Thread(() => timerProvider.QueueScheduled());
thread2.Start();
Mocker.SetConstant(fakeJobs);
thread1.Join();
thread2.Join();
var jobProvider = Mocker.Resolve<JobProvider>();
jobProvider.Initialize();
slowJob.ExecutionCount = 2;
jobProvider.QueueScheduled();
jobProvider.QueueScheduled();
Thread.Sleep(2000);
fakeJob.ExecutionCount.Should().Be(1);
}
[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()
{
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();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var jobProvider = mocker.Resolve<JobProvider>();
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();
thread2.Start();
@ -209,20 +203,19 @@ namespace NzbDrone.Core.Test.ProviderTests
Thread.Sleep(5000);
Assert.AreEqual(1, slowJob.ExecutionCount);
BaseFakeJob.ExecutionCount.Should().Be(1);
jobProvider.Queue.Should().BeEmpty();
}
[Test]
public void Init_Jobs()
{
var fakeTimer = new FakeJob();
IList<IJob> fakeJobs = new List<IJob> { fakeTimer };
IList<IJob> BaseFakeJobs = new List<IJob> { fakeTimer };
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
@ -248,11 +241,11 @@ namespace NzbDrone.Core.Test.ProviderTests
for (int i = 0; i < 2; i++)
{
var fakeTimer = new FakeJob();
IList<IJob> fakeJobs = new List<IJob> { fakeTimer };
IList<IJob> BaseFakeJobs = new List<IJob> { fakeTimer };
var mocker = new AutoMoqer();
mocker.SetConstant(repo);
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
@ -279,11 +272,11 @@ namespace NzbDrone.Core.Test.ProviderTests
for (int i = 0; i < 2; i++)
{
var disabledJob = new DisabledJob();
IList<IJob> fakeJobs = new List<IJob> { disabledJob };
IList<IJob> BaseFakeJobs = new List<IJob> { disabledJob };
var mocker = new AutoMoqer();
mocker.SetConstant(repo);
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
@ -305,11 +298,11 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test]
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();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
//Act
var timerProvider = mocker.Resolve<JobProvider>();
@ -330,11 +323,11 @@ namespace NzbDrone.Core.Test.ProviderTests
var disabledJob = new DisabledJob();
IList<IJob> fakeJobs = new List<IJob> { disabledJob };
IList<IJob> BaseFakeJobs = new List<IJob> { disabledJob };
var mocker = new AutoMoqer();
mocker.SetConstant(repo);
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
@ -351,11 +344,11 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test]
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();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
//Act
var jobProvider = mocker.Resolve<JobProvider>();
@ -373,11 +366,11 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test]
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();
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
//Act
var jobProvider = mocker.Resolve<JobProvider>();
@ -397,16 +390,16 @@ namespace NzbDrone.Core.Test.ProviderTests
{
var mocker = new AutoMoqer();
var fakeJob = new FakeJob();
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
var BaseFakeJob = new FakeJob();
IList<IJob> BaseFakeJobs = new List<IJob> { BaseFakeJob };
mocker.SetConstant(MockLib.GetEmptyDatabase());
mocker.SetConstant(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var fakeQueueItem = new JobQueueItem
{
JobType = fakeJob.GetType(),
JobType = BaseFakeJob.GetType(),
TargetId = 12,
SecondaryTargetId = 0
};
@ -415,11 +408,11 @@ namespace NzbDrone.Core.Test.ProviderTests
var jobProvider = mocker.Resolve<JobProvider>();
jobProvider.Initialize();
jobProvider.Queue.Add(fakeQueueItem);
jobProvider.QueueJob(fakeJob.GetType(), 12);
jobProvider.QueueJob(BaseFakeJob.GetType(), 12);
Thread.Sleep(1000);
//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 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(fakeJobs);
mocker.SetConstant(BaseFakeJobs);
var jobProvider = mocker.Resolve<JobProvider>();
jobProvider.Initialize();
var _jobThread = new Thread(() => jobProvider.QueueScheduled());
var _jobThread = new Thread(jobProvider.QueueScheduled);
_jobThread.Start();
Thread.Sleep(200);
@ -453,89 +446,25 @@ namespace NzbDrone.Core.Test.ProviderTests
slowJob.ExecutionCount.Should().Be(1);
disabledJob.ExecutionCount.Should().Be(1);
}
}
public class FakeJob : 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++;
}
}
public class DisabledJob : IJob
{
public string Name
{
get { return "DisabledJob"; }
}
public int DefaultInterval
[Test]
public void trygin_to_queue_unregistered_job_should_fail()
{
get { return 0; }
}
WithRealDb();
public int ExecutionCount { get; set; }
IList<IJob> BaseFakeJobs = new List<IJob> { new SlowJob(), new DisabledJob() };
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
{
ExecutionCount++;
}
}
Mocker.SetConstant(BaseFakeJobs);
public class BrokenJob : IJob
{
public string Name
{
get { return "FakeJob"; }
}
var jobProvider = Mocker.Resolve<JobProvider>();
public int DefaultInterval
{
get { return 15; }
}
public int ExecutionCount { get; set; }
jobProvider.Initialize();
jobProvider.QueueJob(typeof(string));
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
{
ExecutionCount++;
throw new ApplicationException("Broken job is broken");
Thread.Sleep(1000);
ExceptionVerification.ExcpectedErrors(1);
}
}
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);
ExecutionCount++;
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 FluentAssertions;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
@ -16,30 +17,31 @@ namespace NzbDrone.Core.Test.ProviderTests
// ReSharper disable InconsistentNaming
public class TvDbProviderTest : TestBase
{
private TvDbProvider tvDbProvider;
[SetUp]
public void Setup()
{
tvDbProvider = LiveKernel.Get<TvDbProvider>();
}
[TestCase("The Simpsons")]
[TestCase("Family Guy")]
[TestCase("South Park")]
public void successful_search(string title)
{
var result = new TvDbProvider(new EnviromentProvider()).SearchSeries(title);
var result = tvDbProvider.SearchSeries(title);
result.Should().NotBeEmpty();
result[0].SeriesName.Should().Be(title);
}
[Test]
public void no_search_result()
{
//setup
var tvdbProvider = new TvDbProvider(new EnviromentProvider());
//act
var result = tvdbProvider.SearchSeries(Guid.NewGuid().ToString());
var result = tvDbProvider.SearchSeries(Guid.NewGuid().ToString());
//assert
result.Should().BeEmpty();
@ -49,11 +51,8 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test]
public void none_unique_season_episode_number()
{
//setup
var tvdbProvider = new TvDbProvider(new EnviromentProvider());
//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
//one item.
@ -65,11 +64,8 @@ namespace NzbDrone.Core.Test.ProviderTests
[Test]
public void American_dad_fix()
{
//setup
var tvdbProvider = new TvDbProvider(new EnviromentProvider());
//act
var result = tvdbProvider.GetSeries(73141, true);
var result = tvDbProvider.GetSeries(73141, true);
var seasonsNumbers = result.Episodes.Select(e => e.SeasonNumber)
.Distinct().ToList();

@ -22,8 +22,8 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
public void setup()
{
_mocker = new AutoMoqer(MockBehavior.Strict);
_mocker.GetMock<EnviromentProvider>()
.SetupGet(c => c.TempPath).Returns(TempFolder);
_mocker.GetMock<PathProvider>()
.SetupGet(c => c.SystemTemp).Returns(TempFolder);
}
@ -39,11 +39,11 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
};
_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(
c => c.ExtractArchive(Path.Combine(TempFolder, UpdateProvider.SandboxFolderName, updatePackage.FileName),
Path.Combine(TempFolder, UpdateProvider.SandboxFolderName)));
c => c.ExtractArchive(Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME, updatePackage.FileName),
Path.Combine(TempFolder, PathProvider.UPDATE_SANDBOX_FOLDER_NAME)));
_mocker.Resolve<UpdateProvider>().PreformUpdate(updatePackage);
}
@ -52,7 +52,7 @@ namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
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
{

@ -15,6 +15,7 @@ using PetaPoco;
namespace NzbDrone.Core.Test
{
[TestFixture]
[Explicit]
[Category("Benchmark")]
// ReSharper disable InconsistentNaming
public class DbBenchmark : TestBase

@ -1,9 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web.Hosting;
using Ninject;
using NLog;
using NzbDrone.Core.Datastore;
@ -17,106 +14,106 @@ using PetaPoco;
namespace NzbDrone.Core
{
public static class CentralDispatch
public class CentralDispatch
{
private static StandardKernel _kernel;
private static readonly Object KernelLock = new object();
private readonly Object KernelLock = new object();
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static StandardKernel NinjectKernel
public CentralDispatch()
{
get
{
if (_kernel == null)
{
InitializeApp();
}
return _kernel;
}
InitializeApp();
}
public static void InitializeApp()
public StandardKernel Kernel { get; private set; }
private void InitializeApp()
{
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();
_kernel.Get<QualityTypeProvider>().SetupDefault();
_kernel.Get<ConfigFileProvider>().CreateDefaultConfigFile();
MigrationsHelper.Run(mainConnectionString, true);
LogConfiguration.RegisterDatabaseLogger(Kernel.Get<DatabaseTarget>());
Kernel.Get<QualityProvider>().SetupDefaultProfiles();
Kernel.Get<QualityTypeProvider>().SetupDefault();
Kernel.Get<ConfigFileProvider>().CreateDefaultConfigFile();
BindExternalNotifications();
BindIndexers();
BindJobs();
}
private static void BindKernel()
private void BindKernel()
{
lock (KernelLock)
{
Logger.Debug("Binding Ninject's Kernel");
_kernel = new StandardKernel();
Kernel = new StandardKernel();
var connection = Kernel.Get<Connection>();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InTransientScope();
_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<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();
Kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
}
}
private static void BindIndexers()
private void BindIndexers()
{
_kernel.Bind<IndexerBase>().To<NzbsOrg>();
_kernel.Bind<IndexerBase>().To<NzbMatrix>();
_kernel.Bind<IndexerBase>().To<NzbsRUs>();
_kernel.Bind<IndexerBase>().To<Newzbin>();
Kernel.Bind<IndexerBase>().To<NzbsOrg>();
Kernel.Bind<IndexerBase>().To<NzbMatrix>();
Kernel.Bind<IndexerBase>().To<NzbsRUs>();
Kernel.Bind<IndexerBase>().To<Newzbin>();
var indexers = _kernel.GetAll<IndexerBase>();
_kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());
var indexers = Kernel.GetAll<IndexerBase>();
Kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());
}
private static void BindJobs()
private void BindJobs()
{
_kernel.Bind<IJob>().To<RssSyncJob>().InSingletonScope();
_kernel.Bind<IJob>().To<ImportNewSeriesJob>().InSingletonScope();
_kernel.Bind<IJob>().To<UpdateInfoJob>().InSingletonScope();
_kernel.Bind<IJob>().To<DiskScanJob>().InSingletonScope();
_kernel.Bind<IJob>().To<DeleteSeriesJob>().InSingletonScope();
_kernel.Bind<IJob>().To<EpisodeSearchJob>().InSingletonScope();
_kernel.Bind<IJob>().To<RenameEpisodeJob>().InSingletonScope();
_kernel.Bind<IJob>().To<PostDownloadScanJob>().InSingletonScope();
_kernel.Bind<IJob>().To<UpdateSceneMappingsJob>().InSingletonScope();
_kernel.Bind<IJob>().To<SeasonSearchJob>().InSingletonScope();
_kernel.Bind<IJob>().To<RenameSeasonJob>().InSingletonScope();
_kernel.Bind<IJob>().To<SeriesSearchJob>().InSingletonScope();
_kernel.Bind<IJob>().To<RenameSeriesJob>().InSingletonScope();
_kernel.Bind<IJob>().To<BacklogSearchJob>().InSingletonScope();
_kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
_kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
_kernel.Get<JobProvider>().Initialize();
_kernel.Get<WebTimer>().StartTimer(30);
Kernel.Bind<IJob>().To<RssSyncJob>().InSingletonScope();
Kernel.Bind<IJob>().To<ImportNewSeriesJob>().InSingletonScope();
Kernel.Bind<IJob>().To<UpdateInfoJob>().InSingletonScope();
Kernel.Bind<IJob>().To<DiskScanJob>().InSingletonScope();
Kernel.Bind<IJob>().To<DeleteSeriesJob>().InSingletonScope();
Kernel.Bind<IJob>().To<EpisodeSearchJob>().InSingletonScope();
Kernel.Bind<IJob>().To<RenameEpisodeJob>().InSingletonScope();
Kernel.Bind<IJob>().To<PostDownloadScanJob>().InSingletonScope();
Kernel.Bind<IJob>().To<UpdateSceneMappingsJob>().InSingletonScope();
Kernel.Bind<IJob>().To<SeasonSearchJob>().InSingletonScope();
Kernel.Bind<IJob>().To<RenameSeasonJob>().InSingletonScope();
Kernel.Bind<IJob>().To<SeriesSearchJob>().InSingletonScope();
Kernel.Bind<IJob>().To<RenameSeriesJob>().InSingletonScope();
Kernel.Bind<IJob>().To<BacklogSearchJob>().InSingletonScope();
Kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
Kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
Kernel.Get<JobProvider>().Initialize();
Kernel.Get<WebTimer>().StartTimer(30);
}
private static void BindExternalNotifications()
private void BindExternalNotifications()
{
_kernel.Bind<ExternalNotificationBase>().To<Xbmc>();
_kernel.Bind<ExternalNotificationBase>().To<Smtp>();
_kernel.Bind<ExternalNotificationBase>().To<Twitter>();
_kernel.Bind<ExternalNotificationBase>().To<Providers.ExternalNotification.Growl>();
_kernel.Bind<ExternalNotificationBase>().To<Prowl>();
var notifiers = _kernel.GetAll<ExternalNotificationBase>();
_kernel.Get<ExternalNotificationProvider>().InitializeNotifiers(notifiers.ToList());
Kernel.Bind<ExternalNotificationBase>().To<Xbmc>();
Kernel.Bind<ExternalNotificationBase>().To<Smtp>();
Kernel.Bind<ExternalNotificationBase>().To<Twitter>();
Kernel.Bind<ExternalNotificationBase>().To<Providers.ExternalNotification.Growl>();
Kernel.Bind<ExternalNotificationBase>().To<Prowl>();
var notifiers = Kernel.GetAll<ExternalNotificationBase>();
Kernel.Get<ExternalNotificationProvider>().InitializeNotifiers(notifiers.ToList());
}
/// <summary>
/// Forces IISExpress process to exit with the host application
/// </summary>
public static void DedicateToHost()
public void DedicateToHost()
{
try
{
@ -144,7 +141,8 @@ namespace NzbDrone.Core
private static void ShutDown()
{
Logger.Info("Shutting down application.");
WebTimer.Stop();
Process.GetCurrentProcess().Kill();
}
}
}
}

@ -10,38 +10,51 @@ using PetaPoco;
namespace NzbDrone.Core.Datastore
{
public static class Connection
public class Connection
{
private static EnviromentProvider _enviromentProvider = new EnviromentProvider();
private readonly PathProvider _pathProvider;
static Connection()
public Connection(PathProvider pathProvider)
{
Database.Mapper = new CustomeMapper();
_pathProvider = pathProvider;
}
public static string GetConnectionString(string path)
static Connection()
{
//return String.Format("Data Source={0};Version=3;Cache Size=30000;Pooling=true;Default Timeout=2", path);
return String.Format("Data Source={0}", path);
Database.Mapper = new CustomeMapper();
}
public static String MainConnectionString
public String MainConnectionString
{
get
{
return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "nzbdrone.sdf"));
return GetConnectionString(_pathProvider.NzbDronoeDbFile);
}
}
public static String LogConnectionString
public String LogConnectionString
{
get
{
return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "log.sdf"));
return GetConnectionString(_pathProvider.LogDbFile);
}
}
public static string GetConnectionString(string path)
{
//return String.Format("Data Source={0};Version=3;Cache Size=30000;Pooling=true;Default Timeout=2", path);
return String.Format("Data Source={0}", path);
}
public IDatabase GetMainPetaPocoDb(Boolean profiled = true)
{
return GetPetaPocoDb(MainConnectionString, profiled);
}
public IDatabase GetLogPetaPocoDb(Boolean profiled = true)
{
return GetPetaPocoDb(LogConnectionString, profiled);
}
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
{

@ -54,6 +54,8 @@ namespace NzbDrone.Core
return dateTime.ToShortDateString();
}
//TODO: this should be moved to DiskProvider
public static ulong FreeDiskSpace(this DirectoryInfo directoryInfo)
{
ulong freeBytesAvailable;

@ -7,22 +7,30 @@ using NzbDrone.Core.Providers;
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)
{
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.Core.CentralDispatch");
LogManager.ConfigurationReloaded += ((s, e) => RegisterDatabaseLogger(CentralDispatch.NinjectKernel.Get<DatabaseTarget>()));
LogManager.ConfigurationReloaded += ((s, e) => RegisterDatabaseLogger(_databaseTarget));
}
public static void RegisterDatabaseLogger(DatabaseTarget databaseTarget)

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NzbDrone.Core.Model
{
@ -12,13 +10,13 @@ namespace NzbDrone.Core.Model
public bool Equals(JobQueueItem other)
{
if (JobType == other.JobType && TargetId == other.TargetId
&& SecondaryTargetId == other.SecondaryTargetId)
{
return true;
}
return (JobType == other.JobType && TargetId == other.TargetId
&& SecondaryTargetId == other.SecondaryTargetId);
}
return false;
public override string ToString()
{
return string.Format("[{0}({1}, {2})]", JobType.Name, TargetId, SecondaryTargetId);
}
}
}

@ -189,6 +189,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Constants.cs" />
<Compile Include="Datastore\Connection.cs" />
<Compile Include="Datastore\MigrationLogger.cs" />

@ -1,18 +1,4 @@
// * This program is free software: you can redistribute it and/or modify
// * 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.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -20,35 +6,15 @@ using System.Runtime.InteropServices;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[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)]
[assembly: AssemblyTitle("NzbDrone.Core")]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3C29FEF7-4B07-49ED-822E-1C29DC49BFAB")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: InternalsVisibleTo("NzbDrone.Core.Test")]
// 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("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
{
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; }
set { _configFile = value; }
_pathProvider = pathProvider;
_configFile = _pathProvider.AppConfigFile;
}
public virtual int Port
@ -37,7 +38,7 @@ namespace NzbDrone.Core.Providers.Core
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 parentContainer = config;
@ -50,7 +51,7 @@ namespace NzbDrone.Core.Providers.Core
SetValue(key, defaultValue, parent);
//Reload the configFile
xDoc = XDocument.Load(ConfigFile);
xDoc = XDocument.Load(_configFile);
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)
{
var xDoc = XDocument.Load(ConfigFile);
var xDoc = XDocument.Load(_configFile);
var config = xDoc.Descendants("Config").Single();
var parentContainer = config;
@ -105,18 +106,18 @@ namespace NzbDrone.Core.Providers.Core
else
parentContainer.Descendants(key).Single().Value = value.ToString();
xDoc.Save(ConfigFile);
xDoc.Save(_configFile);
}
public virtual void CreateDefaultConfigFile()
{
if (!File.Exists(ConfigFile))
if (!File.Exists(_configFile))
{
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
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 Logger Logger = LogManager.GetCurrentClassLogger();
public Growl(ConfigProvider configProvider, GrowlProvider growlProvider)
: base(configProvider)
{
@ -41,7 +39,7 @@ namespace NzbDrone.Core.Providers.ExternalNotification
catch (Exception ex)
{
Logger.WarnException(ex.Message, ex);
_logger.WarnException(ex.Message, ex);
throw;
}
}
@ -65,7 +63,7 @@ namespace NzbDrone.Core.Providers.ExternalNotification
catch (Exception ex)
{
Logger.WarnException(ex.Message, ex);
_logger.WarnException(ex.Message, ex);
throw;
}
}

@ -18,18 +18,20 @@ namespace NzbDrone.Core.Providers.Jobs
private readonly HttpProvider _httpProvider;
private readonly DiskProvider _diskProvider;
private readonly EnviromentProvider _enviromentProvider;
private readonly PathProvider _pathProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private string _bannerPath = "";
private const string _bannerUrlPrefix = "http://www.thetvdb.com/banners/";
[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;
_httpProvider = httpProvider;
_diskProvider = diskProvider;
_enviromentProvider = enviromentProvider;
_pathProvider = pathProvider;
}
public BannerDownloadJob()
@ -51,8 +53,8 @@ namespace NzbDrone.Core.Providers.Jobs
{
Logger.Debug("Starting banner download job");
_bannerPath = Path.Combine(_enviromentProvider.WebRoot, "Content", "Images", "Banners");
_diskProvider.CreateDirectory(_bannerPath);
_diskProvider.CreateDirectory(_pathProvider.BannerPath);
if (targetId > 0)
{
@ -76,7 +78,7 @@ namespace NzbDrone.Core.Providers.Jobs
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);

@ -11,7 +11,6 @@ using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Repository;
using PetaPoco;
using ThreadState = System.Threading.ThreadState;
namespace NzbDrone.Core.Providers.Jobs
{
@ -21,15 +20,15 @@ namespace NzbDrone.Core.Providers.Jobs
/// </summary>
public class JobProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private readonly IDatabase _database;
private readonly NotificationProvider _notificationProvider;
private readonly IList<IJob> _jobs;
private Thread _jobThread;
private Stopwatch _jobThreadStopWatch;
private readonly object ExecutionLock = new object();
private bool _isRunning;
private readonly object executionLock = new object();
private readonly List<JobQueueItem> _queue = new List<JobQueueItem>();
private ProgressNotification _notification;
@ -40,6 +39,7 @@ namespace NzbDrone.Core.Providers.Jobs
_database = database;
_notificationProvider = notificationProvider;
_jobs = jobs;
ResetThread();
}
/// <summary>
@ -68,6 +68,34 @@ namespace NzbDrone.Core.Providers.Jobs
return _database.Fetch<JobDefinition>().ToList();
}
/// <summary>
/// Initializes jobs in the database using the IJob instances that are
/// registered using ninject
/// </summary>
public virtual void Initialize()
{
logger.Debug("Initializing jobs. Count {0}", _jobs.Count());
var currentTimer = All();
foreach (var timer in _jobs)
{
var timerProviderLocal = timer;
if (!currentTimer.Exists(c => c.TypeName == timerProviderLocal.GetType().ToString()))
{
var settings = new JobDefinition
{
Enable = timerProviderLocal.DefaultInterval > 0,
TypeName = timer.GetType().ToString(),
Name = timerProviderLocal.Name,
Interval = timerProviderLocal.DefaultInterval,
LastExecution = new DateTime(2000, 1, 1)
};
SaveDefinition(settings);
}
}
}
/// <summary>
/// Adds/Updates definitions for a job
/// </summary>
@ -76,213 +104,186 @@ namespace NzbDrone.Core.Providers.Jobs
{
if (definitions.Id == 0)
{
Logger.Trace("Adding job definitions for {0}", definitions.Name);
logger.Trace("Adding job definitions for {0}", definitions.Name);
_database.Insert(definitions);
}
else
{
Logger.Trace("Updating job definitions for {0}", definitions.Name);
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)
lock (executionLock)
{
if (_isRunning)
VerifyThreadTime();
if (_jobThread.IsAlive)
{
Logger.Trace("Queue is already running. Ignoring scheduler's request.");
logger.Trace("Queue is already running. Ignoring scheduler's request.");
return;
}
}
var counter = 0;
var pendingJobs = All().Where(
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());
).Select(c => _jobs.Where(t => t.GetType().ToString() == c.TypeName).Single().GetType()).ToList();
foreach (var job in pendingJobs)
{
QueueJob(job.GetType());
counter++;
}
Logger.Trace("{0} Scheduled tasks have been added to the queue", counter);
pendingJobTypes.ForEach(jobType => QueueJob(jobType));
logger.Trace("{0} Scheduled tasks have been added to the queue", pendingJobTypes.Count);
}
/// <summary>
/// Queues the execution of a job asynchronously
/// Gets the next scheduled run time for a specific job
/// (Estimated due to schedule timer)
/// </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>
/// <returns>DateTime of next scheduled job execution</returns>
public virtual DateTime NextScheduledRun(Type jobType)
{
var job = All().Where(t => t.TypeName == jobType.ToString()).Single();
return job.LastExecution.AddMinutes(job.Interval);
}
public virtual void QueueJob(Type jobType, int targetId = 0, int secondaryTargetId = 0)
{
Logger.Debug("Adding [{0}:{1}] to the queue", jobType.Name, targetId);
var queueItem = new JobQueueItem
{
JobType = jobType,
TargetId = targetId,
SecondaryTargetId = secondaryTargetId
};
lock (ExecutionLock)
logger.Debug("Attempting to queue {0}", queueItem);
lock (executionLock)
{
VerifyThreadTime();
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);
logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, Queue.Count);
}
else
{
Logger.Info("[{0}:{1}] already exists in the queue. Skipping.", jobType.Name, targetId);
logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, Queue.Count);
}
}
if (_isRunning)
if (_jobThread.IsAlive)
{
Logger.Trace("Queue is already running. No need to start it up.");
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" };
ResetThread();
_jobThreadStopWatch = Stopwatch.StartNew();
_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
try
{
using (NestedDiagnosticsContext.Push(Guid.NewGuid().ToString()))
do
{
try
using (NestedDiagnosticsContext.Push(Guid.NewGuid().ToString()))
{
JobQueueItem job = null;
lock (Queue)
try
{
if (Queue.Count != 0)
JobQueueItem job = null;
lock (Queue)
{
job = Queue.First();
Queue.Remove(job);
if (Queue.Count != 0)
{
job = Queue.First();
Queue.Remove(job);
logger.Debug("Popping {0} from the queue.", job);
}
}
}
if (job != null)
if (job != null)
{
Execute(job);
}
}
catch (ThreadAbortException)
{
Execute(job.JobType, job.TargetId, job.SecondaryTargetId);
throw;
}
catch (Exception e)
{
logger.FatalException("An error has occurred while executing job.", e);
}
}
catch (Exception e)
{
Logger.FatalException("An error has occurred while processing queued job.", e);
}
}
} while (Queue.Count != 0);
} while (Queue.Count != 0);
Logger.Trace("Finished processing jobs in the queue.");
logger.Trace("Finished processing jobs in the queue.");
return;
return;
}
catch (ThreadAbortException e)
{
logger.Warn(e.Message);
}
catch (Exception e)
{
logger.ErrorException("Error has occurred in queue processor thread", e);
}
finally
{
ResetThread();
}
}
/// <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)
private void Execute(JobQueueItem queueItem)
{
var jobImplementation = _jobs.Where(t => t.GetType() == jobType).Single();
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.", jobType);
logger.Error("Unable to locate implementation for '{0}'. Make sure it is properly registered.", queueItem.JobType);
return;
}
var settings = All().Where(j => j.TypeName == jobType.ToString()).Single();
var settings = All().Where(j => j.TypeName == queueItem.JobType.ToString()).Single();
using (_notification = new ProgressNotification(jobImplementation.Name))
{
try
{
Logger.Debug("Starting '{0}' job. Last execution {1}", settings.Name, settings.LastExecution);
logger.Debug("Starting {0}. Last execution {1}", queueItem, settings.LastExecution);
var sw = Stopwatch.StartNew();
_notificationProvider.Register(_notification);
jobImplementation.Start(_notification, targetId, secondaryTargetId);
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.", jobImplementation.Name, sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds / 100,
sw.Elapsed.Seconds);
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);
logger.ErrorException("An error has occurred while executing job [" + jobImplementation.Name + "].", e);
_notification.Status = ProgressNotificationStatus.Failed;
_notification.CurrentMessage = jobImplementation.Name + " Failed.";
@ -292,49 +293,33 @@ namespace NzbDrone.Core.Providers.Jobs
}
//Only update last execution status if was triggered by the scheduler
if (targetId == 0)
if (queueItem.TargetId == 0)
{
SaveDefinition(settings);
}
}
/// <summary>
/// Initializes jobs in the database using the IJob instances that are
/// registered using ninject
/// </summary>
public virtual void Initialize()
private void VerifyThreadTime()
{
Logger.Debug("Initializing jobs. Count {0}", _jobs.Count());
var currentTimer = All();
foreach (var timer in _jobs)
if (_jobThreadStopWatch.Elapsed.TotalHours > 1)
{
var timerProviderLocal = timer;
if (!currentTimer.Exists(c => c.TypeName == timerProviderLocal.GetType().ToString()))
{
var settings = new JobDefinition
{
Enable = timerProviderLocal.DefaultInterval > 0,
TypeName = timer.GetType().ToString(),
Name = timerProviderLocal.Name,
Interval = timerProviderLocal.DefaultInterval,
LastExecution = new DateTime(2000, 1, 1)
};
SaveDefinition(settings);
}
logger.Warn("Thread job has been running for more than an hour. fuck it!");
ResetThread();
}
}
/// <summary>
/// Gets the next scheduled run time for a specific job
/// (Estimated due to schedule timer)
/// </summary>
/// <returns>DateTime of next scheduled job execution</returns>
public virtual DateTime NextScheduledRun(Type jobType)
private void ResetThread()
{
var job = All().Where(t => t.TypeName == jobType.ToString()).Single();
return job.LastExecution.AddMinutes(job.Interval);
if (_jobThread != null)
{
_jobThread.Abort();
}
logger.Trace("resetting queue processor thread");
_jobThread = new Thread(ProcessQueue) { Name = "JobQueueThread" };
_jobThreadStopWatch = new Stopwatch();
}
}
}

@ -13,22 +13,20 @@ namespace NzbDrone.Core.Providers
{
public class TvDbProvider
{
private readonly EnviromentProvider _enviromentProvider;
private const string TVDB_APIKEY = "5D2D188E86E07F4F";
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly TvdbHandler _handler;
[Inject]
public TvDbProvider(EnviromentProvider enviromentProvider)
public TvDbProvider(PathProvider pathProvider)
{
_enviromentProvider = enviromentProvider;
_handler = new TvdbHandler(new XmlCacheProvider(_enviromentProvider.AppDataPath + @"\cache\tvdb"), TVDB_APIKEY);
_handler = new TvdbHandler(new XmlCacheProvider(pathProvider.CacheFolder), TVDB_APIKEY);
}
public TvDbProvider()
{
}
public virtual IList<TvdbSearchResult> SearchSeries(string title)

@ -18,19 +18,22 @@ namespace NzbDrone.Core.Providers
private readonly HttpProvider _httpProvider;
private readonly ConfigProvider _configProvider;
private readonly EnviromentProvider _enviromentProvider;
private readonly PathProvider _pathProvider;
private readonly DiskProvider _diskProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase);
public const string SandboxFolderName = "nzbdrone_update";
[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;
_configProvider = configProvider;
_enviromentProvider = enviromentProvider;
_pathProvider = pathProvider;
_diskProvider = diskProvider;
}
@ -73,15 +76,14 @@ namespace NzbDrone.Core.Providers
public virtual void PreformUpdate(UpdatePackage updatePackage)
{
var tempSubFolder = Path.Combine(_enviromentProvider.TempPath, SandboxFolderName);
var packageDestination = Path.Combine(tempSubFolder, updatePackage.FileName);
var packageDestination = Path.Combine(_pathProvider.UpdateSandboxFolder, updatePackage.FileName);
Logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination);
_httpProvider.DownloadFile(updatePackage.Url, packageDestination);
Logger.Info("Download completed for update package from [{0}]", updatePackage.FileName);
Logger.Info("Extracting Update package");
_diskProvider.ExtractArchive(packageDestination, tempSubFolder);
_diskProvider.ExtractArchive(packageDestination, _pathProvider.UpdateSandboxFolder);
Logger.Info("Update package extracted successfully");
}

@ -6,18 +6,23 @@ using NzbDrone.Core.Providers.Jobs;
namespace NzbDrone.Core
{
class WebTimer
public class WebTimer
{
private readonly JobProvider _jobProvider;
private static CacheItemRemovedCallback _onCacheRemove;
private static bool _stop;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public WebTimer(JobProvider jobProvider)
{
_jobProvider = jobProvider;
}
//TODO: Make timer doesn't keep running during unit tests.
public void StartTimer(int secondInterval)
{
_onCacheRemove = new CacheItemRemovedCallback(DoWork);
@ -30,8 +35,17 @@ namespace NzbDrone.Core
public void DoWork(string k, object v, CacheItemRemovedReason r)
{
_jobProvider.QueueScheduled();
StartTimer(Convert.ToInt32(v));
if (!_stop)
{
_jobProvider.QueueScheduled();
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 = "";
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;
}
@ -87,8 +88,6 @@ namespace NzbDrone.Test.Common
private static void Excpected(LogLevel level, int count)
{
var levelLogs = _logs.Where(l => l.Level == level).ToList();
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}",
count, level, levelLogs.Count, GetLogsString(levelLogs));
message = "********************************************************************************************************************************\n\r"
message = "\n\r****************************************************************************************\n\r"
+ message +
"\n\r********************************************************************************************************************************";
"\n\r****************************************************************************************";
Assert.Fail(message);
}

@ -1,20 +1,21 @@
using NLog;
using NLog.Config;
using NUnit.Framework;
using NzbDrone.Common;
namespace NzbDrone.Test.Common
{
public abstract class LoggingFixtures
public abstract class LoggingTest
{
[SetUp]
public void SetUpBase()
protected static void InitLogging()
{
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
LogConfiguration.RegisterUdpLogger();
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
{
LogManager.Configuration = new LoggingConfiguration();
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
LogConfiguration.RegisterUdpLogger();
RegisterExceptionVerification();
RegisterExceptionVerification();
}
}
private static void RegisterExceptionVerification()

@ -69,7 +69,7 @@
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
<Compile Include="ExceptionVerification.cs" />
<Compile Include="LoggingFixtures.cs" />
<Compile Include="LoggingTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

@ -3,6 +3,6 @@ using NUnit.Framework;
using NzbDrone.Test.Common;
[SetUpFixture]
public class Fixtures : LoggingFixtures
public class Fixtures : LoggingTest
{
}

@ -46,6 +46,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\UpdateProvider.cs" />

@ -1,36 +1,16 @@
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.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
[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
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.6.0.*")]
[assembly: AssemblyFileVersion("0.6.0.*")]

@ -130,15 +130,10 @@ hr
/* Footer */
.timer
.footer
{
text-align: center;
padding: 1px 1px 1px 1px;
color: #065EFE;
}
#footer
{
padding: 1px, 1px, 1px, 1px;
text-align: center;
}
@ -242,4 +237,4 @@ select, button, input[type="button"], input[type="submit"], input[type="reset"]
position: fixed;
top: 30px;
right: 15px;
}
}

@ -17,7 +17,6 @@
margin: 0px;
display: none;
@*Rounded Edges*@
border:1px solid #444444;
-moz-border-radius-bottomright: 8px;
-webkit-border-bottom-right-radius: 8px;
@ -37,7 +36,6 @@
color:#FFFFFF;
@*Rounded Edges*@
border: 1px solid #444444;
border-top: 0px;
-moz-border-radius-bottomright: 10px;

@ -1,17 +1,21 @@
using System;
using System.Web.Mvc;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Web.Models;
namespace NzbDrone.Web.Controllers
{
public class SharedController : Controller
{
private readonly JobProvider _jobProvider;
private readonly EnviromentProvider _enviromentProvider;
public SharedController(JobProvider jobProvider)
public SharedController(JobProvider jobProvider, EnviromentProvider enviromentProvider)
{
_jobProvider = jobProvider;
_enviromentProvider = enviromentProvider;
}
public ActionResult Index()
@ -22,8 +26,8 @@ namespace NzbDrone.Web.Controllers
[ChildActionOnly]
public ActionResult Footer()
{
ViewData["RssTimer"] = _jobProvider.NextScheduledRun(typeof(RssSyncJob)).ToString("yyyyMMddHHmmss");
return PartialView();
return PartialView(new FooterModel { BuildTime = _enviromentProvider.BuildDateTime, Version = _enviromentProvider.Version });
}
[ChildActionOnly]

@ -43,26 +43,25 @@ namespace NzbDrone.Web
//base.OnApplicationStarted();
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.Add(razor);
RegisterGlobalFilters(GlobalFilters.Filters);
Logger.Info("Fully initialized and ready.");
}
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.");
dispatch.DedicateToHost();
// kernel.Bind<IRepository>().ToConstant(kernel.Get<IRepository>("LogDb"));
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\jquery.gritter.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">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@ -486,6 +489,7 @@
<Compile Include="Helpers\DescriptionExtension.cs" />
<Compile Include="Helpers\HtmlPrefixScopeExtensions.cs" />
<Compile Include="Helpers\IsCurrentActionHelper.cs" />
<Compile Include="Models\CodeFile1.cs" />
<Compile Include="Models\ExistingSeriesModel.cs" />
<Compile Include="Models\AddNewSeriesModel.cs" />
<Compile Include="Models\JobQueueItemModel.cs" />

@ -1,37 +1,13 @@
using System.Reflection;
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.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)]
[assembly: AssemblyTitle("NzbDrone.Web")]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1ec2c814-7c1e-470d-bbae-59b129b720fd")]
// 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 Revision and Build Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// 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;
@model IEnumerable<NzbDrone.Core.Repository.Series>
@section TitleContent{
NZBDrone
NzbDrone
}
<style>

@ -1,4 +1,4 @@
@model System.Web.Mvc.HandleErrorInfo
@model HandleErrorInfo
@section TitleContent
{

@ -1,5 +1,5 @@
@using NzbDrone.Core
@using NzbDrone.Web.Models
@model FooterModel
<div>
@*NZBDrone @CentralDispatch.Version (@CentralDispatch.BuildDateTime.ToString("MMM d, yyyy"))*@
NzbDrone @Model.Version (@Model.BuildTime.ToString("MMM d, yyyy"))
</div>

@ -4,7 +4,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="SHORTCUT ICON" href="../../favicon.ico" />
<title>NZBDrone</title>
<title>NzbDrone</title>
<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.sitefinity.min.css" />
@ -61,7 +61,7 @@
</div>
</div>
<hr />
<div id="footer" class="span-24 last">
<div class="span-24 last footer">
@{Html.RenderAction("Footer", "Shared");}
</div>
</div>

@ -87,6 +87,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ApplicationServer.cs">
<SubType>Component</SubType>
</Compile>

@ -5,35 +5,11 @@ using System.Runtime.InteropServices;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NZBDrone")]
[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: AssemblyTitle("NzbDrone.exe")]
[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
// 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
{
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
ApplicationName = "NZBDrone",
ApplicationName = "NzbDrone",
CurrentException = excepion as Exception
}.Submit();
#endif

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Config />
Loading…
Cancel
Save