Adds some more error checking to PhysicalFileSystem ctor. Fixing issues with Script/Style repo tests.

This commit is contained in:
Shannon Deminick
2013-01-15 01:15:08 +03:00
parent dfb6953792
commit d0cccb5be6
5 changed files with 13 additions and 6 deletions

View File

@@ -18,7 +18,11 @@ namespace Umbraco.Core.IO
public PhysicalFileSystem(string virtualRoot)
{
RootPath = IOHelper.MapPath(virtualRoot);
if (virtualRoot == null) throw new ArgumentNullException("virtualRoot");
if (!virtualRoot.StartsWith("~/"))
throw new ArgumentException("The virtualRoot argument must be a virtual path and start with '~/'");
RootPath = IOHelper.MapPath(virtualRoot);
_rootUrl = IOHelper.ResolveUrl(virtualRoot);
}
@@ -30,6 +34,9 @@ namespace Umbraco.Core.IO
if (string.IsNullOrEmpty(rootUrl))
throw new ArgumentException("The argument 'rootUrl' cannot be null or empty.");
if (rootPath.StartsWith("~/"))
throw new ArgumentException("The rootPath argument cannot be a virtual path and cannot start with '~/'");
RootPath = rootPath;
_rootUrl = rootUrl;
}

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Core.Persistence.Repositories
/// </summary>
internal class ScriptRepository : FileRepository<string, Script>, IScriptRepository
{
public ScriptRepository(IUnitOfWork work, IFileSystem fileSystem)
internal ScriptRepository(IUnitOfWork work, IFileSystem fileSystem)
: base(work, fileSystem)
{
}

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Core.Persistence.Repositories
/// </summary>
internal class StylesheetRepository : FileRepository<string, Stylesheet>, IStylesheetRepository
{
public StylesheetRepository(IUnitOfWork work, IFileSystem fileSystem)
internal StylesheetRepository(IUnitOfWork work, IFileSystem fileSystem)
: base(work, fileSystem)
{

View File

@@ -17,7 +17,7 @@ namespace Umbraco.Tests.Persistence.Repositories
[SetUp]
public void Initialize()
{
_fileSystem = new PhysicalFileSystem(SystemDirectories.Scripts, "/scripts");
_fileSystem = new PhysicalFileSystem(SystemDirectories.Scripts);
var stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");");
_fileSystem.AddFile("test-script.js", stream);
}
@@ -183,7 +183,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
_fileSystem = null;
//Delete all files
var fs = new PhysicalFileSystem(SystemDirectories.Scripts, "/scripts");
var fs = new PhysicalFileSystem(SystemDirectories.Scripts);
var files = fs.GetFiles("", "*.js");
foreach (var file in files)
{

View File

@@ -17,7 +17,7 @@ namespace Umbraco.Tests.Persistence.Repositories
[SetUp]
public void Initialize()
{
_fileSystem = new PhysicalFileSystem(SystemDirectories.Css, "/css");
_fileSystem = new PhysicalFileSystem(SystemDirectories.Css);
var stream = CreateStream("body {background:#EE7600; color:#FFF;}");
_fileSystem.AddFile("styles.css", stream);
}