diff --git a/src/Umbraco.Tests.Integration/Views/template1.cshtml b/src/Umbraco.Tests.Integration/Views/template1.cshtml deleted file mode 100644 index 64a9c8d55f..0000000000 --- a/src/Umbraco.Tests.Integration/Views/template1.cshtml +++ /dev/null @@ -1,5 +0,0 @@ -@using Umbraco.Web.PublishedModels; -@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage -@{ - Layout = null; -} \ No newline at end of file diff --git a/src/Umbraco.Tests.Integration/Views/template2.cshtml b/src/Umbraco.Tests.Integration/Views/template2.cshtml deleted file mode 100644 index 64a9c8d55f..0000000000 --- a/src/Umbraco.Tests.Integration/Views/template2.cshtml +++ /dev/null @@ -1,5 +0,0 @@ -@using Umbraco.Web.PublishedModels; -@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage -@{ - Layout = null; -} \ No newline at end of file diff --git a/src/Umbraco.Tests.Integration/Views/test.cshtml b/src/Umbraco.Tests.Integration/Views/test.cshtml deleted file mode 100644 index 64a9c8d55f..0000000000 --- a/src/Umbraco.Tests.Integration/Views/test.cshtml +++ /dev/null @@ -1,5 +0,0 @@ -@using Umbraco.Web.PublishedModels; -@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage -@{ - Layout = null; -} \ No newline at end of file diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/TestHelper.cs index a95f13562c..9c619e05de 100644 --- a/src/Umbraco.Tests.UnitTests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests.UnitTests/TestHelpers/TestHelper.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Threading; +using Microsoft.AspNetCore.Hosting; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -30,6 +31,8 @@ using Umbraco.Web.Routing; using File = System.IO.File; using Microsoft.Extensions.Options; using Umbraco.Core.Configuration.Models; +using Umbraco.Web.Common.AspNetCore; +using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; namespace Umbraco.Tests.TestHelpers { @@ -58,7 +61,11 @@ namespace Umbraco.Tests.TestHelpers => Mock.Of(); public override IHostingEnvironment GetHostingEnvironment() - => Mock.Of(); + { + return new AspNetCoreHostingEnvironment( + Mock.Of>(x=>x.CurrentValue == new HostingSettings()), + Mock.Of(x=>x.WebRootPath == "/")); + } public override IApplicationShutdownRegistry GetHostingEnvironmentLifetime() => Mock.Of(); @@ -308,7 +315,7 @@ namespace Umbraco.Tests.TestHelpers public static IIpResolver GetIpResolver() => _testHelperInternal.GetIpResolver(); public static IRequestCache GetRequestCache() => _testHelperInternal.GetRequestCache(); - + public static IPublishedUrlProvider GetPublishedUrlProvider() => _testHelperInternal.GetPublishedUrlProvider(); } } diff --git a/src/Umbraco.Tests/Manifest/ManifestContentAppTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestContentAppTests.cs similarity index 100% rename from src/Umbraco.Tests/Manifest/ManifestContentAppTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestContentAppTests.cs diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs similarity index 91% rename from src/Umbraco.Tests/Manifest/ManifestParserTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs index 661c9cff0e..f62bcd0ced 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs @@ -12,6 +12,7 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; using Umbraco.Core.Services; using Umbraco.Core.Dashboards; +using Umbraco.Core.IO; using Umbraco.Core.Serialization; using Umbraco.Core.Strings; using Umbraco.Tests.TestHelpers; @@ -22,6 +23,7 @@ namespace Umbraco.Tests.Manifest public class ManifestParserTests { private ManifestParser _parser; + private IIOHelper _ioHelper; [SetUp] public void Setup() @@ -32,7 +34,8 @@ namespace Umbraco.Tests.Manifest new RegexValidator(Mock.Of(), null), new DelimitedValueValidator(), }; - _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), Mock.Of(), TestHelper.IOHelper, Mock.Of(), Mock.Of(), new JsonNetSerializer(), Mock.Of(), Mock.Of()); + _ioHelper = TestHelper.IOHelper; + _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), Mock.Of(), _ioHelper, Mock.Of(), Mock.Of(), new JsonNetSerializer(), Mock.Of(), Mock.Of()); } [Test] @@ -125,8 +128,8 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 manifest = _parser.ParseManifest(json); Assert.AreEqual(2, manifest.Scripts.Length); - Assert.AreEqual("/test.js", manifest.Scripts[0]); - Assert.AreEqual("/test2.js", manifest.Scripts[1]); + Assert.AreEqual(_ioHelper.ResolveUrl("/test.js"), manifest.Scripts[0]); + Assert.AreEqual(_ioHelper.ResolveUrl("/test2.js"), manifest.Scripts[1]); // kludge is gone - must filter before parsing json = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()) + "{propertyEditors: [], javascript: ['~/test.js', '~/test2.js']}"; @@ -218,7 +221,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 Assert.IsFalse((editor.Type & EditorType.MacroParameter) > 0); var valueEditor = editor.GetValueEditor(); - Assert.AreEqual("/App_Plugins/MyPackage/PropertyEditors/MyEditor.html", valueEditor.View); + Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/MyEditor.html"), valueEditor.View); Assert.AreEqual("int", valueEditor.ValueType); Assert.IsTrue(valueEditor.HideLabel); @@ -250,7 +253,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 var f = preValueEditor.Fields[0]; Assert.AreEqual("key1", f.Key); Assert.AreEqual("Some config 1", f.Name); - Assert.AreEqual("/App_Plugins/MyPackage/PropertyEditors/Views/pre-val1.html", f.View); + Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/Views/pre-val1.html"), f.View); var fvalidators = f.Validators; Assert.IsNotNull(fvalidators); Assert.AreEqual(1, fvalidators.Count); @@ -261,7 +264,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 f = preValueEditor.Fields[1]; Assert.AreEqual("key2", f.Key); Assert.AreEqual("Some config 2", f.Name); - Assert.AreEqual("/App_Plugins/MyPackage/PropertyEditors/Views/pre-val2.html", f.View); + Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/Views/pre-val2.html"), f.View); fvalidators = f.Validators; Assert.IsNotNull(fvalidators); Assert.AreEqual(0, fvalidators.Count); @@ -303,7 +306,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 Assert.AreEqual("some config val", config["key1"]); var valueEditor = editor.GetValueEditor(); - Assert.AreEqual("/App_Plugins/MyPackage/PropertyEditors/CsvEditor.html", valueEditor.View); + Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/CsvEditor.html"), valueEditor.View); editor = manifest.ParameterEditors[2]; Assert.Throws(() => @@ -353,8 +356,8 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 var editor = manifest.GridEditors[0]; Assert.AreEqual("small-hero", editor.Alias); Assert.AreEqual("Small Hero", editor.Name); - Assert.AreEqual("/App_Plugins/MyPlugin/small-hero/editortemplate.html", editor.View); - Assert.AreEqual("/Views/Partials/Grid/Editors/SmallHero.cshtml", editor.Render); + Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPlugin/small-hero/editortemplate.html"), editor.View); + Assert.AreEqual(_ioHelper.ResolveUrl("/Views/Partials/Grid/Editors/SmallHero.cshtml"), editor.Render); Assert.AreEqual("icon-presentation", editor.Icon); var config = editor.Config; @@ -396,14 +399,14 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 Assert.AreEqual("myPackageApp1", app0.Alias); Assert.AreEqual("My App1", app0.Name); Assert.AreEqual("icon-foo", app0.Icon); - Assert.AreEqual("/App_Plugins/MyPackage/ContentApps/MyApp1.html", app0.View); + Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/ContentApps/MyApp1.html"), app0.View); Assert.IsInstanceOf(manifest.ContentApps[1]); var app1 = (ManifestContentAppDefinition)manifest.ContentApps[1]; Assert.AreEqual("myPackageApp2", app1.Alias); Assert.AreEqual("My App2", app1.Name); Assert.AreEqual("icon-bar", app1.Icon); - Assert.AreEqual("/App_Plugins/MyPackage/ContentApps/MyApp2.html", app1.View); + Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/ContentApps/MyApp2.html"), app1.View); } [Test] @@ -432,7 +435,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 var db0 = manifest.Dashboards[0]; Assert.AreEqual("something", db0.Alias); Assert.AreEqual(100, db0.Weight); - Assert.AreEqual("/App_Plugins/MyPackage/Dashboards/one.html", db0.View); + Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/Dashboards/one.html"), db0.View); Assert.AreEqual(1, db0.Sections.Length); Assert.AreEqual("content", db0.Sections[0]); Assert.AreEqual(2, db0.AccessRules.Length); @@ -445,7 +448,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 var db1 = manifest.Dashboards[1]; Assert.AreEqual("something.else", db1.Alias); Assert.AreEqual(-1, db1.Weight); - Assert.AreEqual("/App_Plugins/MyPackage/Dashboards/two.html", db1.View); + Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/Dashboards/two.html"), db1.View); Assert.AreEqual(1, db1.Sections.Length); Assert.AreEqual("forms", db1.Sections[0]); } diff --git a/src/Umbraco.Tests/IO/IoHelperTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/AspNetCoreHostingEnvironmentTests.cs similarity index 61% rename from src/Umbraco.Tests/IO/IoHelperTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/AspNetCoreHostingEnvironmentTests.cs index 6e876c4705..1d6e619640 100644 --- a/src/Umbraco.Tests/IO/IoHelperTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/AspNetCoreHostingEnvironmentTests.cs @@ -1,29 +1,34 @@ using System; +using AutoFixture.NUnit3; +using Moq; using NUnit.Framework; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Strings; using Umbraco.Tests.TestHelpers; +using Umbraco.Tests.UnitTests.AutoFixture; +using Umbraco.Web.Common.AspNetCore; namespace Umbraco.Tests.IO { [TestFixture] - public class IoHelperTests + public class AspNetCoreHostingEnvironmentTests { - private IIOHelper _ioHelper => TestHelper.IOHelper; - [TestCase("~/Scripts", "/Scripts", null)] - [TestCase("/Scripts", "/Scripts", null)] - [TestCase("../Scripts", "/Scripts", typeof(ArgumentException))] - public void IOHelper_ResolveUrl(string input, string expected, Type expectedExceptionType) + [InlineAutoMoqData("~/Scripts", "/Scripts", null)] + [InlineAutoMoqData("/Scripts", "/Scripts", null)] + [InlineAutoMoqData("../Scripts", "/Scripts", typeof(InvalidOperationException))] + public void IOHelper_ResolveUrl(string input, string expected, Type expectedExceptionType, AspNetCoreHostingEnvironment sut) { if (expectedExceptionType != null) { - Assert.Throws(expectedExceptionType, () =>_ioHelper.ResolveUrl(input)); + Assert.Throws(expectedExceptionType, () =>sut.ToAbsolute(input)); } else { - var result = _ioHelper.ResolveUrl(input); + + var result = sut.ToAbsolute(input); Assert.AreEqual(expected, result); } } diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 67e92bd123..6f7af8e605 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -13,7 +13,6 @@ using Umbraco.Core.IO.MediaPathSchemes; using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Tests.TestHelpers; -using Current = Umbraco.Web.Composing.Current; using FileSystems = Umbraco.Core.IO.FileSystems; namespace Umbraco.Tests.IO @@ -46,9 +45,6 @@ namespace Umbraco.Tests.IO _factory = composition.CreateFactory(); - Current.Reset(); - Current.Factory = _factory; - // make sure we start clean // because some tests will create corrupt or weird filesystems FileSystems.Reset(); @@ -60,7 +56,6 @@ namespace Umbraco.Tests.IO // stay clean (see note in Setup) FileSystems.Reset(); - Current.Reset(); _register.DisposeIfDisposable(); } @@ -115,7 +110,7 @@ namespace Umbraco.Tests.IO fs.DeleteMediaFiles(new[] { virtPath }); Assert.IsFalse(File.Exists(physPath)); - var scheme = Current.Factory.GetInstance(); + var scheme = _factory.GetInstance(); if (scheme is UniqueMediaPathScheme) { // ~/media/1234 is *not* gone diff --git a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs index 472714ba0e..dfd061b3ac 100644 --- a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -11,9 +10,8 @@ using Umbraco.Core.Composing; using Umbraco.Core.Configuration.Models; using Umbraco.Core.IO; using Umbraco.Core.Logging; -using Umbraco.Core.Scoping; -using Umbraco.Tests.Common.Builders; using Umbraco.Tests.TestHelpers; +using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; namespace Umbraco.Tests.IO { @@ -25,11 +23,15 @@ namespace Umbraco.Tests.IO // SetUp and TearDown run before/after each test // SetUp does not start before the previous TearDown returns + private readonly ILogger _logger = Mock.Of(); + private readonly IHostingEnvironment _hostingEnvironment = TestHelper.GetHostingEnvironment(); + private readonly IIOHelper _ioHelper = TestHelper.IOHelper; + [SetUp] public void SetUp() { SafeCallContext.Clear(); - ClearFiles(TestHelper.IOHelper); + ClearFiles(_ioHelper); FileSystems.ResetShadowId(); } @@ -41,10 +43,10 @@ namespace Umbraco.Tests.IO FileSystems.ResetShadowId(); } - private static void ClearFiles(IIOHelper ioHelper) + private static void ClearFiles(IIOHelper _ioHelper) { - TestHelper.DeleteDirectory(ioHelper.MapPath("FileSysTests")); - TestHelper.DeleteDirectory(ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); + TestHelper.DeleteDirectory(_ioHelper.MapPath("FileSysTests")); + TestHelper.DeleteDirectory(_ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); } private static string NormPath(string path) @@ -55,17 +57,13 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteDirectory() { - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Directory.CreateDirectory(path + "/ShadowTests/d1"); @@ -93,17 +91,13 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteDirectoryInDir() { - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Directory.CreateDirectory(path + "/ShadowTests/sub"); @@ -146,17 +140,13 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteFile() { - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); File.WriteAllText(path + "/ShadowTests/f1.txt", "foo"); @@ -189,18 +179,14 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteFileInDir() { - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Directory.CreateDirectory(path + "/ShadowTests/sub"); @@ -249,17 +235,13 @@ namespace Umbraco.Tests.IO [Test] public void ShadowCantCreateFile() { - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Assert.Throws(() => @@ -272,17 +254,13 @@ namespace Umbraco.Tests.IO [Test] public void ShadowCreateFile() { - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper,hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper,_hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); File.WriteAllText(path + "/ShadowTests/f2.txt", "foo"); @@ -315,17 +293,13 @@ namespace Umbraco.Tests.IO [Test] public void ShadowCreateFileInDir() { - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) @@ -359,17 +333,13 @@ namespace Umbraco.Tests.IO [Test] public void ShadowAbort() { - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) @@ -385,17 +355,13 @@ namespace Umbraco.Tests.IO [Test] public void ShadowComplete() { - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); Directory.CreateDirectory(path + "/ShadowTests/sub/sub"); @@ -425,22 +391,18 @@ namespace Umbraco.Tests.IO [Test] public void ShadowScopeComplete() { - var logger = Mock.Of(); - var ioHelper = TestHelper.IOHelper; - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); - var shadowfs = ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var path = _ioHelper.MapPath("FileSysTests"); + var shadowfs = _ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); Directory.CreateDirectory(shadowfs); var scopedFileSystems = false; - var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path, "ignore"); + var phy = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path, "ignore"); var container = Mock.Of(); var globalSettings = Options.Create(new GlobalSettings()); - var fileSystems = new FileSystems(container, logger, ioHelper, globalSettings, TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; + var fileSystems = new FileSystems(container, _logger, _ioHelper, globalSettings, _hostingEnvironment) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem(phy); var sw = (ShadowWrapper) fs.InnerFileSystem; @@ -451,7 +413,7 @@ namespace Umbraco.Tests.IO string id; // explicit shadow without scope does not work - sw.Shadow(id = ShadowWrapper.CreateShadowId(ioHelper)); + sw.Shadow(id = ShadowWrapper.CreateShadowId(_ioHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); @@ -462,7 +424,7 @@ namespace Umbraco.Tests.IO // shadow with scope but no complete does not complete scopedFileSystems = true; // pretend we have a scope - var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(ioHelper)); + var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_ioHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f3.txt", ms); @@ -484,7 +446,7 @@ namespace Umbraco.Tests.IO // shadow with scope and complete does complete scopedFileSystems = true; // pretend we have a scope - scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(ioHelper)); + scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_ioHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f4.txt", ms); @@ -500,7 +462,7 @@ namespace Umbraco.Tests.IO // test scope for "another thread" scopedFileSystems = true; // pretend we have a scope - scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(ioHelper)); + scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_ioHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f5.txt", ms); @@ -523,21 +485,17 @@ namespace Umbraco.Tests.IO [Test] public void ShadowScopeCompleteWithFileConflict() { - var logger = Mock.Of(); - var ioHelper = TestHelper.IOHelper; - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); - var shadowfs = ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var path = _ioHelper.MapPath("FileSysTests"); + var shadowfs = _ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); var scopedFileSystems = false; - var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path, "ignore"); + var phy = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path, "ignore"); var container = Mock.Of(); var globalSettings = Options.Create(new GlobalSettings()); - var fileSystems = new FileSystems(container, logger, ioHelper, globalSettings, TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; + var fileSystems = new FileSystems(container, _logger, _ioHelper, globalSettings, _hostingEnvironment) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem( phy); var sw = (ShadowWrapper) fs.InnerFileSystem; @@ -548,7 +506,7 @@ namespace Umbraco.Tests.IO string id; scopedFileSystems = true; // pretend we have a scope - var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(ioHelper)); + var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_ioHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); @@ -579,21 +537,17 @@ namespace Umbraco.Tests.IO [Test] public void ShadowScopeCompleteWithDirectoryConflict() { - var logger = Mock.Of(); - var ioHelper = TestHelper.IOHelper; - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); - var shadowfs = ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var path = _ioHelper.MapPath("FileSysTests"); + var shadowfs = _ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); var scopedFileSystems = false; - var phy = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path, "ignore"); + var phy = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path, "ignore"); var container = Mock.Of(); var globalSettings = Options.Create(new GlobalSettings()); - var fileSystems = new FileSystems(container, logger, ioHelper, globalSettings, TestHelper.GetHostingEnvironment()) { IsScoped = () => scopedFileSystems }; + var fileSystems = new FileSystems(container, _logger, _ioHelper, globalSettings, _hostingEnvironment) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem( phy); var sw = (ShadowWrapper)fs.InnerFileSystem; @@ -604,7 +558,7 @@ namespace Umbraco.Tests.IO string id; scopedFileSystems = true; // pretend we have a scope - var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(ioHelper)); + var scope = new ShadowFileSystems(fileSystems, id = ShadowWrapper.CreateShadowId(_ioHelper)); Assert.IsTrue(Directory.Exists(shadowfs + "/" + id)); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f2.txt", ms); @@ -652,9 +606,7 @@ namespace Umbraco.Tests.IO [Test] public void GetFilesReturnsChildrenOnly() { - var ioHelper = TestHelper.IOHelper; - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); File.WriteAllText(path + "/f1.txt", "foo"); Directory.CreateDirectory(path + "/test"); @@ -676,9 +628,7 @@ namespace Umbraco.Tests.IO [Test] public void DeleteDirectoryAndFiles() { - var ioHelper = TestHelper.IOHelper; - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); File.WriteAllText(path + "/f1.txt", "foo"); Directory.CreateDirectory(path + "/test"); @@ -699,17 +649,13 @@ namespace Umbraco.Tests.IO public void ShadowGetFiles() { // Arrange - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -735,17 +681,13 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingEmptyFilter() { // Arrange - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -774,17 +716,13 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingNullFilter() { // Arrange - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -810,17 +748,13 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingWildcardFilter() { // Arrange - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -849,17 +783,13 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingSingleCharacterFilter() { // Arrange - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -900,17 +830,13 @@ namespace Umbraco.Tests.IO public void ShadowGetFullPath() { // Arrange - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -938,17 +864,13 @@ namespace Umbraco.Tests.IO public void ShadowGetRelativePath() { // Arrange - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "ignore"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "ignore"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "ignore"); var ss = new ShadowFileSystem(fs, sfs); // Act @@ -981,17 +903,13 @@ namespace Umbraco.Tests.IO public void ShadowGetUrl() { // Arrange - var ioHelper = TestHelper.IOHelper; - var logger = Mock.Of(); - var hostingEnvironment = TestHelper.GetHostingEnvironment(); - - var path = ioHelper.MapPath("FileSysTests"); + var path = _ioHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); - var fs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowTests/", "rootUrl"); - var sfs = new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, path + "/ShadowSystem/", "rootUrl"); + var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowTests/", "rootUrl"); + var sfs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, path + "/ShadowSystem/", "rootUrl"); var ss = new ShadowFileSystem(fs, sfs); // Act diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 70720a588a..fe5e334a93 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -118,10 +118,13 @@ + + + + - @@ -164,7 +167,6 @@ - @@ -277,7 +279,6 @@ - @@ -303,7 +304,6 @@ - @@ -372,9 +372,6 @@ - - - diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index ede121a9f7..ad168114e0 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -100,7 +100,7 @@ namespace Umbraco.Web.Common.AspNetCore if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute)) return virtualPath; - var fullPath = ApplicationVirtualPath.EnsureEndsWith('/') + virtualPath.TrimStart("~/"); + var fullPath = ApplicationVirtualPath.EnsureEndsWith('/') + virtualPath.TrimStart("~/").TrimStart("/"); return fullPath; }