PathProvider. visit us for all of your pathing needs.

pull/2/head
kay.one 13 years ago
parent c503b497ed
commit 633f0b6197

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

@ -17,14 +17,6 @@ namespace NzbDrone.Common.Test
enviromentController.IsUserInteractive.Should().BeTrue();
}
[Test]
public void Log_path_should_not_be_empty()
{
enviromentController.LogPath.Should().NotBeBlank();
Path.IsPathRooted(enviromentController.LogPath).Should().BeTrue("Path is not rooted");
}
[Test]
public void StartupPath_should_not_be_empty()
{

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

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

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

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

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

@ -1,13 +1,47 @@
using System.IO;
using AutoMoq;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.Framework
{
public class TestBase
public class TestBase : LoggingTest
// ReSharper disable InconsistentNaming
{
static TestBase()
{
InitLogging();
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 string VirtualPath
{
get
{
var virtualPath = Path.Combine(TempFolder, "VirtualNzbDrone");
if (!Directory.Exists(virtualPath)) Directory.CreateDirectory(virtualPath);
return virtualPath;
}
}
[SetUp]
public virtual void SetupBase()
{
@ -18,6 +52,9 @@ namespace NzbDrone.Core.Test.Framework
}
Directory.CreateDirectory(TempFolder);
LiveKernel = new StandardKernel();
Mocker = new AutoMoqer();
}
[TearDown]
@ -27,6 +64,16 @@ namespace NzbDrone.Core.Test.Framework
}
protected void WithTempAsStartUpPath()
{
Mocker.GetMock<EnviromentProvider>()
.SetupGet(c => c.ApplicationPath)
.Returns(VirtualPath);
Mocker.Resolve<PathProvider>();
}
protected string TempFolder
{
get { return Path.Combine(Directory.GetCurrentDirectory(), "temp"); }

@ -92,7 +92,8 @@ namespace NzbDrone.Core.Test.JobTests
var fakeSeries = Builder<Series>.CreateListOfSize(10)
.Build();
var path = Path.Combine(new EnviromentProvider().WebRoot, "Content", "Images", "Banners");
var pathProvider = Mocker.Resolve<PathProvider>();
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();
@ -104,42 +105,42 @@ namespace NzbDrone.Core.Test.JobTests
.Returns(fakeSeries);
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "1.jpg")))
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "1.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "2.jpg")));
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "2.jpg")));
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "3.jpg")))
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "3.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "4.jpg")));
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "4.jpg")));
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "5.jpg")))
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "5.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "6.jpg")));
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "6.jpg")));
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "7.jpg")))
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "7.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "8.jpg")));
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "8.jpg")));
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "9.jpg")))
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "9.jpg")))
.Throws(new WebException());
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(path, "10.jpg")));
.Setup(s => s.DownloadFile(It.IsAny<string>(), Path.Combine(pathProvider.BannerPath, "10.jpg")));
mocker.GetMock<DiskProvider>()

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

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

@ -39,7 +39,9 @@ namespace NzbDrone.Core
{
BindKernel();
MigrationsHelper.Run(Connection.MainConnectionString, true);
var mainConnectionString = _kernel.Get<Connection>().MainConnectionString;
MigrationsHelper.Run(mainConnectionString, true);
LogConfiguration.RegisterDatabaseLogger(_kernel.Get<DatabaseTarget>());
@ -59,9 +61,11 @@ namespace NzbDrone.Core
Logger.Debug("Binding Ninject's Kernel");
_kernel = new StandardKernel();
_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();
var connection = _kernel.Get<Connection>();
_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();
}

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

@ -7,17 +7,23 @@ using NzbDrone.Core.Providers;
namespace NzbDrone.Core.Instrumentation
{
public static class LogConfiguration
public class LogConfiguration
{
private readonly PathProvider _pathProvider;
public static void Setup()
public LogConfiguration(PathProvider pathProvider)
{
_pathProvider = pathProvider;
}
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");

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

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

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

@ -5,11 +5,9 @@ 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();

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

@ -43,24 +43,23 @@ 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();
var kernel = CentralDispatch.NinjectKernel;
kernel.Get<LogConfiguration>().Setup();
Logger.Info("NZBDrone Starting up.");
CentralDispatch.DedicateToHost();
var kernel = CentralDispatch.NinjectKernel;
CentralDispatch.DedicateToHost();
// kernel.Bind<IRepository>().ToConstant(kernel.Get<IRepository>("LogDb"));
kernel.Load(Assembly.GetExecutingAssembly());
return kernel;
}

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