diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs
index 04d390a3cc..a58d983667 100644
--- a/src/Umbraco.Core/IO/IOHelper.cs
+++ b/src/Umbraco.Core/IO/IOHelper.cs
@@ -13,13 +13,28 @@ using Umbraco.Core.Configuration;
namespace Umbraco.Core.IO
{
public static class IOHelper
- {
- public static bool IAmUnitTestingSoNeverUseHttpContextEver = false;
+ {
+ ///
+ /// Gets or sets a value forcing Umbraco to consider it is non-hosted.
+ ///
+ /// This should always be false, unless unit testing.
+ public static bool ForceNotHosted { get; set; }
private static string _rootDir = "";
// static compiled regex for faster performance
private readonly static Regex ResolveUrlPattern = new Regex("(=[\"\']?)(\\W?\\~(?:.(?![\"\']?\\s+(?:\\S+)=|[>\"\']))+.)[\"\']?", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
+
+ ///
+ /// Gets a value indicating whether Umbraco is hosted.
+ ///
+ public static bool IsHosted
+ {
+ get
+ {
+ return ForceNotHosted == false && (HttpContext.Current != null || HostingEnvironment.IsHosted);
+ }
+ }
public static char DirSepChar
{
@@ -74,14 +89,14 @@ namespace Umbraco.Core.IO
internal static string ResolveUrlsFromTextString(string text)
{
if (UmbracoConfig.For.UmbracoSettings().Content.ResolveUrlsFromTextString)
- {
+ {
using (DisposableTimer.DebugDuration(typeof(IOHelper), "ResolveUrlsFromTextString starting", "ResolveUrlsFromTextString complete"))
{
// find all relative urls (ie. urls that contain ~)
var tags = ResolveUrlPattern.Matches(text);
-
+
foreach (Match tag in tags)
- {
+ {
string url = "";
if (tag.Groups[1].Success)
url = tag.Groups[1].Value;
@@ -100,7 +115,7 @@ namespace Umbraco.Core.IO
public static string MapPath(string path, bool useHttpContext)
{
if (path == null) throw new ArgumentNullException("path");
- useHttpContext = useHttpContext && IAmUnitTestingSoNeverUseHttpContextEver == false;
+ useHttpContext = useHttpContext && IsHosted;
// Check if the path is already mapped
if ((path.Length >= 2 && path[1] == Path.VolumeSeparatorChar)
@@ -306,7 +321,7 @@ namespace Umbraco.Core.IO
var debugFolder = Path.Combine(binFolder, "debug");
if (Directory.Exists(debugFolder))
return debugFolder;
-#endif
+#endif
var releaseFolder = Path.Combine(binFolder, "release");
if (Directory.Exists(releaseFolder))
return releaseFolder;
diff --git a/src/Umbraco.Core/TypeFinder.cs b/src/Umbraco.Core/TypeFinder.cs
index 0f69ee5ba5..043c4aa361 100644
--- a/src/Umbraco.Core/TypeFinder.cs
+++ b/src/Umbraco.Core/TypeFinder.cs
@@ -5,9 +5,7 @@ using System.Linq;
using System.Reflection;
using System.Security;
using System.Text;
-using System.Web;
using System.Web.Compilation;
-using System.Web.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
@@ -19,8 +17,6 @@ namespace Umbraco.Core
///
public static class TypeFinder
{
- public static bool IAmUnitTestingSoNeverUseHttpContextEver = false;
-
private static volatile HashSet _localFilteredAssemblyCache;
private static readonly object LocalFilteredAssemblyCacheLocker = new object();
@@ -47,7 +43,7 @@ namespace Umbraco.Core
HashSet assemblies = null;
try
{
- var isHosted = (HttpContext.Current != null || HostingEnvironment.IsHosted) && IAmUnitTestingSoNeverUseHttpContextEver == false;
+ var isHosted = IOHelper.IsHosted;
try
{