From aac84516270f0679e678d69b69a654144097c8dc Mon Sep 17 00:00:00 2001 From: Lars-Erik Aabech Date: Sun, 11 Sep 2016 21:36:10 +0200 Subject: [PATCH] Removing HttpContext dependency from GridValueConverter. Adding configuration for IOHelper when testing to remove usage of HttpContext. --- src/Umbraco.Core/IO/IOHelper.cs | 6 +++++- .../PropertyEditors/ValueConverters/GridValueConverter.cs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 286acf0285..ef41c9210b 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -13,7 +13,9 @@ using Umbraco.Core.Logging; namespace Umbraco.Core.IO { public static class IOHelper - { + { + public static bool IAmUnitTestingSoNeverUseHttpContextEver = false; + private static string _rootDir = ""; // static compiled regex for faster performance @@ -97,6 +99,8 @@ namespace Umbraco.Core.IO public static string MapPath(string path, bool useHttpContext) { + useHttpContext = useHttpContext && IAmUnitTestingSoNeverUseHttpContextEver == false; + // Check if the path is already mapped if ((path.Length >= 2 && path[1] == Path.VolumeSeparatorChar) || path.StartsWith(@"\\")) //UNC Paths start with "\\". If the site is running off a network drive mapped paths will look like "\\Whatever\Boo\Bar" diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs index b3db026c89..3ec08b0c22 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs @@ -44,8 +44,8 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters var gridConfig = UmbracoConfig.For.GridConfig( ApplicationContext.Current.ProfilingLogger.Logger, ApplicationContext.Current.ApplicationCache.RuntimeCache, - new DirectoryInfo(HttpContext.Current.Server.MapPath(SystemDirectories.AppPlugins)), - new DirectoryInfo(HttpContext.Current.Server.MapPath(SystemDirectories.Config)), + new DirectoryInfo(IOHelper.MapPath(SystemDirectories.AppPlugins)), + new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config)), HttpContext.Current.IsDebuggingEnabled); var sections = GetArray(obj, "sections");