diff --git a/.gitignore b/.gitignore
index 5390da67dd..2ed26621df 100644
--- a/.gitignore
+++ b/.gitignore
@@ -167,3 +167,4 @@ build/temp/
/src/Umbraco.Web.UI.NetCore/wwwroot/Media/*
/src/Umbraco.Web.UI.NetCore/wwwroot/is-cache/*
/src/Umbraco.Tests.Integration/App_Data/*
+/src/Umbraco.Tests.Integration/TEMP/*
diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs
index 3df80ded5d..b14bd5fd5d 100644
--- a/src/Umbraco.Tests.Common/TestHelperBase.cs
+++ b/src/Umbraco.Tests.Common/TestHelperBase.cs
@@ -30,6 +30,7 @@ namespace Umbraco.Tests.Common
private readonly ITypeFinder _typeFinder;
private UriUtility _uriUtility;
private IIOHelper _ioHelper;
+ private string _workingDir;
protected TestHelperBase(Assembly entryAssembly)
{
@@ -63,14 +64,18 @@ namespace Umbraco.Tests.Common
///
/// Gets the working directory of the test project.
///
- public string WorkingDirectory
+ public virtual string WorkingDirectory
{
get
{
- var dir = Path.Combine(IOHelper.MapPath("~"), "TEMP");
+ if (_workingDir != null) return _workingDir;
+
+ var dir = Path.Combine(Assembly.GetExecutingAssembly().GetRootDirectorySafe(), "TEMP");
+
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
- return dir;
+ _workingDir = dir;
+ return _workingDir;
}
}
diff --git a/src/Umbraco.Tests.Integration/Extensions/ServiceCollectionExtensions.cs b/src/Umbraco.Tests.Integration/Extensions/ServiceCollectionExtensions.cs
index 9dde20036b..dc58d3e9e6 100644
--- a/src/Umbraco.Tests.Integration/Extensions/ServiceCollectionExtensions.cs
+++ b/src/Umbraco.Tests.Integration/Extensions/ServiceCollectionExtensions.cs
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
using Umbraco.Tests.Integration.Implementations;
namespace Umbraco.Tests.Integration.Extensions
@@ -18,6 +19,8 @@ namespace Umbraco.Tests.Integration.Extensions
services.AddSingleton(x => testHelper.GetHttpContextAccessor());
// the generic host does add IHostEnvironment but not this one because we are not actually in a web context
services.AddSingleton(x => webHostEnvironment);
+ // replace the IHostEnvironment that generic host created too
+ services.AddSingleton(x => webHostEnvironment);
}
}
}
diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs
index 50f0614291..e473950d7c 100644
--- a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs
+++ b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs
@@ -1,9 +1,11 @@
+using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
using Moq;
using System.Data.Common;
+using System.IO;
using System.Net;
using Umbraco.Core;
using Umbraco.Core.Cache;
@@ -28,6 +30,7 @@ namespace Umbraco.Tests.Integration.Implementations
private readonly IIpResolver _ipResolver;
private readonly IWebHostEnvironment _hostEnvironment;
private readonly IHttpContextAccessor _httpContextAccessor;
+ private string _tempWorkingDir;
public TestHelper() : base(typeof(TestHelper).Assembly)
{
@@ -36,10 +39,6 @@ namespace Umbraco.Tests.Integration.Implementations
_httpContextAccessor = Mock.Of(x => x.HttpContext == httpContext);
_ipResolver = new AspNetIpResolver(_httpContextAccessor);
- // For Azure Devops we can only store a database in certain locations so we will need to detect if we are running
- // on a build server and if so we'll use the %temp% path.
- //var siteTemp = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoData", hash);
-
var hostEnvironment = new Mock();
hostEnvironment.Setup(x => x.ApplicationName).Returns("UmbracoIntegrationTests");
hostEnvironment.Setup(x => x.ContentRootPath).Returns(() => WorkingDirectory);
@@ -51,6 +50,33 @@ namespace Umbraco.Tests.Integration.Implementations
Logger = new ProfilingLogger(new ConsoleLogger(new MessageTemplates()), Profiler);
}
+
+ public override string WorkingDirectory
+ {
+ get
+ {
+ // For Azure Devops we can only store a database in certain locations so we will need to detect if we are running
+ // on a build server and if so we'll use the %temp% path.
+
+ if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("System.DefaultWorkingDirectory")))
+ {
+ // we are using Azure Devops!
+
+ if (_tempWorkingDir != null) return _tempWorkingDir;
+
+ var temp = Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoTemp");
+ Directory.CreateDirectory(temp);
+ _tempWorkingDir = temp;
+ return _tempWorkingDir;
+
+ }
+ else
+ {
+ return base.WorkingDirectory;
+ }
+ }
+ }
+
public IUmbracoBootPermissionChecker UmbracoBootPermissionChecker { get; } = new TestUmbracoBootPermissionChecker();
public AppCaches AppCaches { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(type => NoAppCache.Instance));