2016-12-16 11:23:01 +01:00
|
|
|
|
using System.Linq;
|
2015-09-10 14:10:45 +02:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.Persistence.Repositories;
|
|
|
|
|
|
using Umbraco.Core.Persistence.UnitOfWork;
|
2016-11-05 19:23:55 +01:00
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
|
|
|
|
|
using Umbraco.Core.DI;
|
2016-12-16 11:23:01 +01:00
|
|
|
|
using Umbraco.Tests.Testing;
|
2015-09-10 14:10:45 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.Persistence.Repositories
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestFixture]
|
2016-12-16 11:23:01 +01:00
|
|
|
|
[UmbracoTest(WithApplication = true)]
|
|
|
|
|
|
public class PartialViewRepositoryTests : UmbracoTestBase
|
2015-09-10 14:10:45 +02:00
|
|
|
|
{
|
|
|
|
|
|
private IFileSystem _fileSystem;
|
|
|
|
|
|
|
2016-10-13 21:08:07 +02:00
|
|
|
|
public override void SetUp()
|
2015-09-10 14:10:45 +02:00
|
|
|
|
{
|
2016-10-13 21:08:07 +02:00
|
|
|
|
base.SetUp();
|
2015-09-10 14:10:45 +02:00
|
|
|
|
|
|
|
|
|
|
_fileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews + "/Partials/");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-05 19:23:55 +01:00
|
|
|
|
protected override void Compose()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Compose();
|
|
|
|
|
|
|
|
|
|
|
|
Container.RegisterSingleton(f => new PropertyEditorCollection(Enumerable.Empty<PropertyEditor>()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-09-10 14:10:45 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void PathTests()
|
|
|
|
|
|
{
|
|
|
|
|
|
// unless noted otherwise, no changes / 7.2.8
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-18 09:38:58 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2015-09-10 14:10:45 +02:00
|
|
|
|
{
|
2016-05-18 09:38:58 +02:00
|
|
|
|
var repository = new PartialViewRepository(unitOfWork, _fileSystem);
|
|
|
|
|
|
|
|
|
|
|
|
var partialView = new PartialView("test-path-1.cshtml") { Content = "// partialView" };
|
2015-09-10 14:10:45 +02:00
|
|
|
|
repository.AddOrUpdate(partialView);
|
2016-05-18 09:38:58 +02:00
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
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);
|
2015-09-10 14:10:45 +02:00
|
|
|
|
|
2016-05-18 09:38:58 +02:00
|
|
|
|
partialView = new PartialView("path-2/test-path-2.cshtml") { Content = "// partialView" };
|
|
|
|
|
|
repository.AddOrUpdate(partialView);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.cshtml"));
|
|
|
|
|
|
Assert.AreEqual("path-2\\test-path-2.cshtml", 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);
|
2015-09-10 14:10:45 +02:00
|
|
|
|
|
2016-05-18 09:38:58 +02:00
|
|
|
|
partialView = (PartialView) repository.Get("path-2/test-path-2.cshtml");
|
|
|
|
|
|
Assert.IsNotNull(partialView);
|
|
|
|
|
|
Assert.AreEqual("path-2\\test-path-2.cshtml", partialView.Path);
|
|
|
|
|
|
Assert.AreEqual("/Views/Partials/path-2/test-path-2.cshtml", partialView.VirtualPath);
|
|
|
|
|
|
|
|
|
|
|
|
partialView = new PartialView("path-2\\test-path-3.cshtml") { Content = "// partialView" };
|
|
|
|
|
|
repository.AddOrUpdate(partialView);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.cshtml"));
|
|
|
|
|
|
Assert.AreEqual("path-2\\test-path-3.cshtml", 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", 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", partialView.Path);
|
|
|
|
|
|
Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath);
|
|
|
|
|
|
|
|
|
|
|
|
partialView = new PartialView("\\test-path-4.cshtml") { Content = "// partialView" };
|
|
|
|
|
|
Assert.Throws<FileSecurityException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
|
|
|
|
|
|
{
|
|
|
|
|
|
repository.AddOrUpdate(partialView);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
partialView = (PartialView) repository.Get("missing.cshtml");
|
|
|
|
|
|
Assert.IsNull(partialView);
|
|
|
|
|
|
|
|
|
|
|
|
// fixed in 7.3 - 7.2.8 used to...
|
|
|
|
|
|
Assert.Throws<FileSecurityException>(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
partialView = (PartialView) repository.Get("\\test-path-4.cshtml"); // outside the filesystem, does not exist
|
|
|
|
|
|
});
|
|
|
|
|
|
Assert.Throws<FileSecurityException>(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
partialView = (PartialView) repository.Get("../../packages.config"); // outside the filesystem, exists
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2015-09-10 14:10:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
|
public override void TearDown()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.TearDown();
|
|
|
|
|
|
|
|
|
|
|
|
//Delete all files
|
|
|
|
|
|
Purge((PhysicalFileSystem)_fileSystem, "");
|
|
|
|
|
|
_fileSystem = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Purge(PhysicalFileSystem fs, string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
var files = fs.GetFiles(path, "*.cshtml");
|
|
|
|
|
|
foreach (var file in files)
|
|
|
|
|
|
{
|
|
|
|
|
|
fs.DeleteFile(file);
|
|
|
|
|
|
}
|
|
|
|
|
|
var dirs = fs.GetDirectories(path);
|
|
|
|
|
|
foreach (var dir in dirs)
|
|
|
|
|
|
{
|
|
|
|
|
|
Purge(fs, dir);
|
|
|
|
|
|
fs.DeleteDirectory(dir);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|