From b2b297ac8afec86c9f36490fddb2579c03183650 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 23 Oct 2020 13:58:30 +0200 Subject: [PATCH] Cleanup tests + Fixed issue in IOHelper related to contentroot vs webroot Signed-off-by: Bjarke Berg --- src/Umbraco.Core/IO/IOHelper.cs | 4 ++-- .../Repositories/PublicAccessRepositoryTest.cs | 5 +---- .../Persistence/Repositories/StylesheetRepositoryTest.cs | 9 ++++++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 118b528869..b3ca956733 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -122,7 +122,7 @@ namespace Umbraco.Core.IO var mappedRoot = MapPath(_hostingEnvironment.ApplicationVirtualPath); if (filePath.StartsWith(mappedRoot) == false) - filePath = MapPath(filePath); + filePath = _hostingEnvironment.MapPathContentRoot(filePath); // yes we can (see above) //// don't trust what we get, it may contain relative segments @@ -132,7 +132,7 @@ namespace Umbraco.Core.IO { var validDir = dir; if (validDir.StartsWith(mappedRoot) == false) - validDir = MapPath(validDir); + validDir = _hostingEnvironment.MapPathContentRoot(validDir); if (PathStartsWith(filePath, validDir, Path.DirectorySeparatorChar)) return true; diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs index 542959ef98..a02889c6ae 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs @@ -133,13 +133,10 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositor Assert.IsTrue(found[0].HasIdentity); Assert.AreNotEqual(default(DateTime), found[0].CreateDate); Assert.AreNotEqual(default(DateTime), found[0].UpdateDate); - Assert.AreEqual(2, found[0].Rules.Count()); - Assert.AreEqual("test", found[0].Rules.First().RuleValue); - Assert.AreEqual("RoleName", found[0].Rules.First().RuleType); + CollectionAssert.AreEquivalent(found[0].Rules, entry.Rules); Assert.AreNotEqual(default(DateTime), found[0].Rules.First().CreateDate); Assert.AreNotEqual(default(DateTime), found[0].Rules.First().UpdateDate); Assert.IsTrue(found[0].Rules.First().HasIdentity); - Assert.AreEqual("test2", found[0].Rules.Skip(1).First().RuleValue); } } 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 9eff12a646..58f3d7ad95 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories; @@ -23,13 +24,15 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositor { private IFileSystems _fileSystems; private IFileSystem _fileSystem; - private readonly TestHelper _testHelper = new TestHelper(); + + private IIOHelper IOHelper => GetRequiredService(); + private IHostingEnvironment HostingEnvironment => GetRequiredService(); [SetUp] public void SetUpFileSystem() { _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(_testHelper.IOHelper, _testHelper.GetHostingEnvironment(), LoggerFactory.CreateLogger(), new GlobalSettings().UmbracoCssPath); + _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory.CreateLogger(), new GlobalSettings().UmbracoCssPath); Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); @@ -46,7 +49,7 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositor private IStylesheetRepository CreateRepository() { var globalSettings = new GlobalSettings(); - return new StylesheetRepository(_fileSystems, _testHelper.IOHelper, Microsoft.Extensions.Options.Options.Create(globalSettings)); + return new StylesheetRepository(_fileSystems, IOHelper, Microsoft.Extensions.Options.Options.Create(globalSettings)); } [Test]