Files
Umbraco-CMS/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs

74 lines
2.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
2018-03-30 19:31:42 +02:00
using System.Threading;
using NUnit.Framework;
using Umbraco.Core.IO;
namespace Umbraco.Tests.IO
{
2018-03-30 19:31:42 +02:00
[TestFixture]
[Apartment(ApartmentState.STA)]
public class PhysicalFileSystemTests : AbstractFileSystemTests
{
public PhysicalFileSystemTests()
2013-02-21 23:07:37 +06:00
: base(new PhysicalFileSystem(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests"),
"/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");
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
}
protected override string ConstructUrl(string path)
{
return "/Media/" + path;
}
[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"));
}
}
}