Changes integration tests working folder, hopefully this works on azure devops

This commit is contained in:
Shannon
2020-03-31 18:01:27 +11:00
parent 8535d0fbe3
commit 4ee3cf02d9
4 changed files with 42 additions and 7 deletions

1
.gitignore vendored
View File

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

View File

@@ -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
/// <summary>
/// Gets the working directory of the test project.
/// </summary>
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;
}
}

View File

@@ -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<IHttpContextAccessor>(x => testHelper.GetHttpContextAccessor());
// the generic host does add IHostEnvironment but not this one because we are not actually in a web context
services.AddSingleton<IWebHostEnvironment>(x => webHostEnvironment);
// replace the IHostEnvironment that generic host created too
services.AddSingleton<IHostEnvironment>(x => webHostEnvironment);
}
}
}

View File

@@ -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<IHttpContextAccessor>(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<IWebHostEnvironment>();
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));