Fixed tests

Signed-off-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Bjarke Berg
2020-11-26 14:16:24 +01:00
parent f249553549
commit 064dbd2f67
10 changed files with 46 additions and 18 deletions

View File

@@ -129,11 +129,13 @@ namespace Umbraco.Core.IO
private object CreateWellKnownFileSystems()
{
var logger = _loggerFactory.CreateLogger<PhysicalFileSystem>();
var macroPartialFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, Constants.SystemDirectories.MacroPartials);
var partialViewsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, Constants.SystemDirectories.PartialViews);
var stylesheetsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _globalSettings.UmbracoCssPath);
var scriptsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _globalSettings.UmbracoScriptsPath);
var mvcViewsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, Constants.SystemDirectories.MvcViews);
//TODO this is fucked, why do PhysicalFileSystem has a root url? Mvc views cannot be accessed by url!
var macroPartialFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.MacroPartials), _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.MacroPartials));
var partialViewsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.PartialViews), _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.PartialViews));
var stylesheetsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _hostingEnvironment.MapPathWebRoot(_globalSettings.UmbracoCssPath), _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoCssPath));
var scriptsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _hostingEnvironment.MapPathWebRoot(_globalSettings.UmbracoScriptsPath), _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoScriptsPath));
var mvcViewsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.MvcViews), _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.MvcViews));
_macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory, "macro-partials", IsScoped);
_partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory, "partials", IsScoped);

View File

@@ -137,7 +137,7 @@ namespace Umbraco.Core.IO
{
var validDir = dir;
if (!PathStartsWith(validDir, mappedRoot))
validDir = _hostingEnvironment.MapPathContentRoot(validDir);
validDir = _hostingEnvironment.MapPathWebRoot(validDir);
if (PathStartsWith(filePath, validDir))
return true;

View File

@@ -31,6 +31,7 @@ namespace Umbraco.Core.IO
// virtualRoot should be "~/path/to/root" eg "~/Views"
// the "~/" is mandatory.
[Obsolete]
public PhysicalFileSystem(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger<PhysicalFileSystem> logger, string virtualRoot)
{
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));

View File

@@ -62,10 +62,10 @@ namespace Umbraco.Core.IO
// on ShadowFileSystemsScope.None - and if None is false then we should be running
// in a single thread anyways
var virt = ShadowFsPath + "/" + id + "/" + _shadowPath;
var virt = Path.Combine(ShadowFsPath , id , _shadowPath);
_shadowDir = _hostingEnvironment.MapPathContentRoot(virt);
Directory.CreateDirectory(_shadowDir);
var tempfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _loggerFactory.CreateLogger<PhysicalFileSystem>(), virt);
var tempfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _loggerFactory.CreateLogger<PhysicalFileSystem>(), _shadowDir, _hostingEnvironment.ToAbsolute(virt));
_shadowFileSystem = new ShadowFileSystem(_innerFileSystem, tempfs);
}

View File

@@ -32,7 +32,8 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositor
public void SetUpFileSystem()
{
_fileSystems = Mock.Of<IFileSystems>();
_fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory.CreateLogger<PhysicalFileSystem>(), new GlobalSettings().UmbracoCssPath);
var path = HostingEnvironment.MapPathWebRoot(GlobalSettings.UmbracoCssPath);
_fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory.CreateLogger<PhysicalFileSystem>(), path, "/css");
Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem);
var stream = CreateStream("body {background:#EE7600; color:#FFF;}");
_fileSystem.AddFile("styles.css", stream);

View File

@@ -21,7 +21,8 @@ namespace Umbraco.Web.BackOffice.Controllers
public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory, IOptions<GlobalSettings> globalSettings)
{
_jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, loggerFactory.CreateLogger<PhysicalFileSystem>(), globalSettings.Value.UmbracoPath + Path.DirectorySeparatorChar + "lib");
var path = globalSettings.Value.UmbracoPath + Path.DirectorySeparatorChar + "lib";
_jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, loggerFactory.CreateLogger<PhysicalFileSystem>(), hostingEnvironment.MapPathWebRoot(path), hostingEnvironment.ToAbsolute(path));
}
[HttpGet]

View File

@@ -45,11 +45,17 @@ namespace Umbraco.Web.BackOffice.Runtime
builder.ComposeWebMappingProfiles();
builder.Services.AddUnique<IPhysicalFileSystem>(factory =>
new PhysicalFileSystem(
{
var path = "~/";
var hostingEnvironment = factory.GetRequiredService<IHostingEnvironment>();
return new PhysicalFileSystem(
factory.GetRequiredService<IIOHelper>(),
factory.GetRequiredService<IHostingEnvironment>(),
hostingEnvironment,
factory.GetRequiredService<ILogger<PhysicalFileSystem>>(),
"~/"));
hostingEnvironment.MapPathContentRoot(path),
hostingEnvironment.ToAbsolute(path)
);
});
builder.Services.AddUnique<IIconService, IconService>();
builder.Services.AddUnique<UnhandledExceptionLoggerMiddleware>();

View File

@@ -93,7 +93,7 @@ namespace Umbraco.Web.Common.AspNetCore
// all those uses have been found and fixed
if (newPath.StartsWith(root)) throw new ArgumentException("The path appears to already be fully qualified. Please remove the call to MapPath");
return Path.Combine(root, newPath.TrimStart('~', '/'));
return Path.Combine(root, newPath.TrimStart('~', '/', '\\'));
}
public string ToAbsolute(string virtualPath)

View File

@@ -109,7 +109,24 @@ namespace Umbraco.Web.Common.Builder
: new MainDomSemaphoreLock(loggerFactory.CreateLogger<MainDomSemaphoreLock>(), hostingEnvironment);
});
builder.Services.AddUnique<IIOHelper, IOHelper>();
builder.Services.AddUnique<IIOHelper>(factory =>
{
var hostingEnvironment = factory.GetRequiredService<IHostingEnvironment>();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return new IOHelperLinux(hostingEnvironment);
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return new IOHelperOSX(hostingEnvironment);
}
return new IOHelperWindows(hostingEnvironment);
}
);
builder.Services.AddUnique<IAppPolicyCache>(factory => factory.GetRequiredService<AppCaches>().RuntimeCache);
builder.Services.AddUnique<IRequestCache>(factory => factory.GetRequiredService<AppCaches>().RequestCache);
builder.Services.AddUnique<IProfilingLogger, ProfilingLogger>();
@@ -124,7 +141,7 @@ namespace Umbraco.Web.Common.Builder
builder.Services.AddUnique<IMainDom, MainDom>();
builder.AddComposers();
return builder;
}

View File

@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"umbracoDbDSN": ""
"umbracoDbDSN": "Server=(LocalDB)\\Umbraco;Database=NetCore;Integrated Security=true"
},
"Serilog": {
"MinimumLevel": {
@@ -71,4 +71,4 @@
}
}
}
}
}