2012-08-13 10:04:31 -01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
using Umbraco.Core.IO;
|
2014-03-18 11:40:20 +11:00
|
|
|
|
|
2012-08-13 10:04:31 -01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.IO
|
|
|
|
|
|
{
|
2013-02-21 23:07:37 +06:00
|
|
|
|
[TestFixture, RequiresSTA]
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
|
public class PhysicalFileSystemTests : AbstractFileSystemTests
|
2012-08-13 10:04:31 -01:00
|
|
|
|
{
|
|
|
|
|
|
public PhysicalFileSystemTests()
|
2013-02-21 23:07:37 +06:00
|
|
|
|
: base(new PhysicalFileSystem(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests"),
|
2012-08-13 10:04:31 -01:00
|
|
|
|
"/Media/"))
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
2013-02-21 23:07:37 +06:00
|
|
|
|
[SetUp]
|
|
|
|
|
|
public void Setup()
|
|
|
|
|
|
{
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
2013-02-21 23:07:37 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
|
public void TearDown()
|
|
|
|
|
|
{
|
2013-02-21 23:47:16 +06:00
|
|
|
|
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests");
|
2015-09-03 15:11:49 +02:00
|
|
|
|
if (Directory.Exists(path) == false) return;
|
|
|
|
|
|
|
2013-02-21 23:47:16 +06:00
|
|
|
|
var files = Directory.GetFiles(path);
|
|
|
|
|
|
foreach (var f in files)
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(f);
|
|
|
|
|
|
}
|
|
|
|
|
|
Directory.Delete(path, true);
|
2013-02-21 23:07:37 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-08-13 10:04:31 -01:00
|
|
|
|
protected override string ConstructUrl(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "/Media/" + path;
|
|
|
|
|
|
}
|
2015-09-03 15:11:49 +02:00
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void GetFullPathTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
// outside of tests, one initializes the PhysicalFileSystem with eg ~/Dir
|
|
|
|
|
|
// and then, rootPath = /path/to/Dir and rootUrl = /Dir/
|
|
|
|
|
|
// here we initialize the PhysicalFileSystem with
|
|
|
|
|
|
// rootPath = /path/to/FileSysTests
|
|
|
|
|
|
// rootUrl = /Media/
|
|
|
|
|
|
|
|
|
|
|
|
var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests");
|
|
|
|
|
|
|
|
|
|
|
|
// ensure that GetFullPath
|
|
|
|
|
|
// - does return the proper full path
|
|
|
|
|
|
// - does properly normalize separators
|
|
|
|
|
|
// - does throw on invalid paths
|
|
|
|
|
|
|
|
|
|
|
|
var path = _fileSystem.GetFullPath("foo.tmp");
|
|
|
|
|
|
Assert.AreEqual(Path.Combine(basePath, @"foo.tmp"), path);
|
|
|
|
|
|
|
|
|
|
|
|
path = _fileSystem.GetFullPath("foo/bar.tmp");
|
|
|
|
|
|
Assert.AreEqual(Path.Combine(basePath, @"foo\bar.tmp"), path);
|
|
|
|
|
|
|
|
|
|
|
|
// that path is invalid as it would be outside the root directory
|
|
|
|
|
|
Assert.Throws<FileSecurityException>(() => _fileSystem.GetFullPath("../../foo.tmp"));
|
|
|
|
|
|
}
|
2012-08-13 10:04:31 -01:00
|
|
|
|
}
|
|
|
|
|
|
}
|