public void SetUpFileSystem() { string path = GlobalSettings.UmbracoScriptsPath; _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory.CreateLogger <PhysicalFileSystem>(), HostingEnvironment.MapPathWebRoot(path), HostingEnvironment.ToAbsolute(path)); _fileSystems = FileSystemsCreator.CreateTestFileSystems(LoggerFactory, IOHelper, GetRequiredService <IOptions <GlobalSettings> >(), HostingEnvironment, null, null, null, _fileSystem, null); using (Stream stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");")) { _fileSystem.AddFile("test-script.js", stream); } }
public void SetUpFileSystem() { string path = HostingEnvironment.MapPathWebRoot(GlobalSettings.UmbracoCssPath); _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, GetRequiredService <ILogger <PhysicalFileSystem> >(), path, "/css"); _fileSystems = FileSystemsCreator.CreateTestFileSystems(LoggerFactory, IOHelper, GetRequiredService <IOptions <GlobalSettings> >(), HostingEnvironment, null, null, _fileSystem, null, null); Stream stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); }
public FileSystems GetFileSystemsMock() { var fileSystems = FileSystemsCreator.CreateTestFileSystems( NullLoggerFactory.Instance, Mock.Of <IIOHelper>(), Mock.Of <IOptions <GlobalSettings> >(), Mock.Of <Cms.Core.Hosting.IHostingEnvironment>(), Mock.Of <IFileSystem>(), Mock.Of <IFileSystem>(), Mock.Of <IFileSystem>(), Mock.Of <IFileSystem>(), Mock.Of <IFileSystem>() ); return(fileSystems); }
public void PathTests() { // unless noted otherwise, no changes / 7.2.8 FileSystems fileSystems = FileSystemsCreator.CreateTestFileSystems(LoggerFactory, IOHelper, GetRequiredService <IOptions <GlobalSettings> >(), HostingEnvironment, null, _fileSystem, null, null, null); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { var repository = new PartialViewRepository(fileSystems); var partialView = new PartialView(PartialViewType.PartialView, "test-path-1.cshtml") { Content = "// partialView" }; repository.Save(partialView); Assert.IsTrue(_fileSystem.FileExists("test-path-1.cshtml")); Assert.AreEqual("test-path-1.cshtml", partialView.Path); Assert.AreEqual("/Views/Partials/test-path-1.cshtml", partialView.VirtualPath); partialView = new PartialView(PartialViewType.PartialView, "path-2/test-path-2.cshtml") { Content = "// partialView" }; repository.Save(partialView); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.cshtml")); Assert.AreEqual("path-2\\test-path-2.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path); // fixed in 7.3 - 7.2.8 does not update the path Assert.AreEqual("/Views/Partials/path-2/test-path-2.cshtml", partialView.VirtualPath); partialView = (PartialView)repository.Get("path-2/test-path-2.cshtml"); Assert.IsNotNull(partialView); Assert.AreEqual("path-2\\test-path-2.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path); Assert.AreEqual("/Views/Partials/path-2/test-path-2.cshtml", partialView.VirtualPath); partialView = new PartialView(PartialViewType.PartialView, "path-2\\test-path-3.cshtml") { Content = "// partialView" }; repository.Save(partialView); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.cshtml")); Assert.AreEqual("path-2\\test-path-3.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path); Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath); partialView = (PartialView)repository.Get("path-2/test-path-3.cshtml"); Assert.IsNotNull(partialView); Assert.AreEqual("path-2\\test-path-3.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path); Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath); partialView = (PartialView)repository.Get("path-2\\test-path-3.cshtml"); Assert.IsNotNull(partialView); Assert.AreEqual("path-2\\test-path-3.cshtml".Replace("\\", $"{Path.DirectorySeparatorChar}"), partialView.Path); Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath); partialView = new PartialView(PartialViewType.PartialView, "\\test-path-4.cshtml") { Content = "// partialView" }; Assert.Throws <UnauthorizedAccessException>(() => // fixed in 7.3 - 7.2.8 used to strip the \ repository.Save(partialView)); partialView = (PartialView)repository.Get("missing.cshtml"); Assert.IsNull(partialView); // fixed in 7.3 - 7.2.8 used to... Assert.Throws <UnauthorizedAccessException>(() => partialView = (PartialView)repository.Get("\\test-path-4.cshtml")); Assert.Throws <UnauthorizedAccessException>(() => partialView = (PartialView)repository.Get("../../packages.config")); } }