From 064dbd2f67bd2e1dd58db7051a3948e8c543c154 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 26 Nov 2020 14:16:24 +0100 Subject: [PATCH] Fixed tests Signed-off-by: Bjarke Berg --- src/Umbraco.Core/IO/FileSystems.cs | 12 ++++++----- src/Umbraco.Core/IO/IOHelper.cs | 2 +- src/Umbraco.Core/IO/PhysicalFileSystem.cs | 1 + src/Umbraco.Core/IO/ShadowWrapper.cs | 4 ++-- .../Repositories/StylesheetRepositoryTest.cs | 3 ++- .../Controllers/BackOfficeAssetsController.cs | 3 ++- .../Runtime/BackOfficeComposer.cs | 12 ++++++++--- .../AspNetCoreHostingEnvironment.cs | 2 +- .../Builder/UmbracoBuilderExtensions.cs | 21 +++++++++++++++++-- src/Umbraco.Web.UI.NetCore/appsettings.json | 4 ++-- 10 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Core/IO/FileSystems.cs b/src/Umbraco.Core/IO/FileSystems.cs index 198e64f4cd..b078172213 100644 --- a/src/Umbraco.Core/IO/FileSystems.cs +++ b/src/Umbraco.Core/IO/FileSystems.cs @@ -129,11 +129,13 @@ namespace Umbraco.Core.IO private object CreateWellKnownFileSystems() { var logger = _loggerFactory.CreateLogger(); - 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); diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 10732f00ee..4ec7cac670 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -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; diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs index 6ed866754d..138b89eb5d 100644 --- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs +++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs @@ -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 logger, string virtualRoot) { _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); diff --git a/src/Umbraco.Core/IO/ShadowWrapper.cs b/src/Umbraco.Core/IO/ShadowWrapper.cs index 59eb8e896e..a395938050 100644 --- a/src/Umbraco.Core/IO/ShadowWrapper.cs +++ b/src/Umbraco.Core/IO/ShadowWrapper.cs @@ -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(), virt); + var tempfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _loggerFactory.CreateLogger(), _shadowDir, _hostingEnvironment.ToAbsolute(virt)); _shadowFileSystem = new ShadowFileSystem(_innerFileSystem, tempfs); } diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/StylesheetRepositoryTest.cs index 58f3d7ad95..da3da3704d 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -32,7 +32,8 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositor public void SetUpFileSystem() { _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory.CreateLogger(), new GlobalSettings().UmbracoCssPath); + var path = HostingEnvironment.MapPathWebRoot(GlobalSettings.UmbracoCssPath); + _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory.CreateLogger(), path, "/css"); Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs index bbb8195aa0..720a0f154d 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeAssetsController.cs @@ -21,7 +21,8 @@ namespace Umbraco.Web.BackOffice.Controllers public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory, IOptions globalSettings) { - _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, loggerFactory.CreateLogger(), globalSettings.Value.UmbracoPath + Path.DirectorySeparatorChar + "lib"); + var path = globalSettings.Value.UmbracoPath + Path.DirectorySeparatorChar + "lib"; + _jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, loggerFactory.CreateLogger(), hostingEnvironment.MapPathWebRoot(path), hostingEnvironment.ToAbsolute(path)); } [HttpGet] diff --git a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs index d11dffb1ac..2f1b42aed5 100644 --- a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs +++ b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs @@ -45,11 +45,17 @@ namespace Umbraco.Web.BackOffice.Runtime builder.ComposeWebMappingProfiles(); builder.Services.AddUnique(factory => - new PhysicalFileSystem( + { + var path = "~/"; + var hostingEnvironment = factory.GetRequiredService(); + return new PhysicalFileSystem( factory.GetRequiredService(), - factory.GetRequiredService(), + hostingEnvironment, factory.GetRequiredService>(), - "~/")); + hostingEnvironment.MapPathContentRoot(path), + hostingEnvironment.ToAbsolute(path) + ); + }); builder.Services.AddUnique(); builder.Services.AddUnique(); diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index ea2efc5b1b..f67e062847 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -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) diff --git a/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs index 4c464ad989..1fae03ba75 100644 --- a/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs @@ -109,7 +109,24 @@ namespace Umbraco.Web.Common.Builder : new MainDomSemaphoreLock(loggerFactory.CreateLogger(), hostingEnvironment); }); - builder.Services.AddUnique(); + builder.Services.AddUnique(factory => + { + var hostingEnvironment = factory.GetRequiredService(); + + 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(factory => factory.GetRequiredService().RuntimeCache); builder.Services.AddUnique(factory => factory.GetRequiredService().RequestCache); builder.Services.AddUnique(); @@ -124,7 +141,7 @@ namespace Umbraco.Web.Common.Builder builder.Services.AddUnique(); builder.AddComposers(); - + return builder; } diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index 00bd04c0b4..aada9919a7 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "umbracoDbDSN": "" + "umbracoDbDSN": "Server=(LocalDB)\\Umbraco;Database=NetCore;Integrated Security=true" }, "Serilog": { "MinimumLevel": { @@ -71,4 +71,4 @@ } } } -} +} \ No newline at end of file