mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Create a stub for IVirtualPathProvider (Unit Tests)
--HG-- branch : dev
This commit is contained in:
@@ -209,6 +209,7 @@
|
|||||||
<Compile Include="Mvc\Html\HtmlHelperExtensionsTests.cs" />
|
<Compile Include="Mvc\Html\HtmlHelperExtensionsTests.cs" />
|
||||||
<Compile Include="Mvc\Routes\ShellRouteTests.cs" />
|
<Compile Include="Mvc\Routes\ShellRouteTests.cs" />
|
||||||
<Compile Include="Mvc\Routes\UrlPrefixTests.cs" />
|
<Compile Include="Mvc\Routes\UrlPrefixTests.cs" />
|
||||||
|
<Compile Include="Stubs\StubVirtualPathProvider.cs" />
|
||||||
<Compile Include="Stubs\StubFileSystem.cs" />
|
<Compile Include="Stubs\StubFileSystem.cs" />
|
||||||
<Compile Include="Stubs\StubAppDataFolder.cs" />
|
<Compile Include="Stubs\StubAppDataFolder.cs" />
|
||||||
<Compile Include="Stubs\StubVirtualPathMonitor.cs" />
|
<Compile Include="Stubs\StubVirtualPathMonitor.cs" />
|
||||||
|
@@ -22,6 +22,18 @@ namespace Orchard.Tests.Stubs {
|
|||||||
|
|
||||||
public IList<Entry> Entries { get; private set; }
|
public IList<Entry> Entries { get; private set; }
|
||||||
|
|
||||||
|
public IEnumerable<FileEntry> Files {
|
||||||
|
get {
|
||||||
|
return Entries.OfType<FileEntry>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<DirectoryEntry> Directories {
|
||||||
|
get {
|
||||||
|
return Entries.OfType<DirectoryEntry>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Entry GetEntry(string name) {
|
public Entry GetEntry(string name) {
|
||||||
if (string.IsNullOrEmpty(name))
|
if (string.IsNullOrEmpty(name))
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
|
80
src/Orchard.Tests/Stubs/StubVirtualPathProvider.cs
Normal file
80
src/Orchard.Tests/Stubs/StubVirtualPathProvider.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.FileSystems.VirtualPath;
|
||||||
|
using Orchard.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Tests.Stubs {
|
||||||
|
public class StubVirtualPathProvider : IVirtualPathProvider {
|
||||||
|
private readonly StubFileSystem _fileSystem;
|
||||||
|
|
||||||
|
public StubVirtualPathProvider(StubFileSystem fileSystem) {
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StubFileSystem FileSystem {
|
||||||
|
get { return _fileSystem; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ToFileSystemPath(string path) {
|
||||||
|
if (path.StartsWith("~/"))
|
||||||
|
return path.Substring(2);
|
||||||
|
if (path.StartsWith("/"))
|
||||||
|
return path.Substring(1);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Combine(params string[] paths) {
|
||||||
|
return Path.Combine(paths).Replace(Path.DirectorySeparatorChar, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public string MapPath(string virtualPath) {
|
||||||
|
throw new NotImplementedException("Mapping to a physical file is not supported in Unit Test with this stub.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FileExists(string virtualPath) {
|
||||||
|
return _fileSystem.GetFileEntry(ToFileSystemPath(virtualPath)) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream OpenFile(string virtualPath) {
|
||||||
|
return _fileSystem.OpenFile(ToFileSystemPath(virtualPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
public StreamWriter CreateText(string virtualPath) {
|
||||||
|
return new StreamWriter(_fileSystem.CreateFile(ToFileSystemPath(virtualPath)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream CreateFile(string virtualPath) {
|
||||||
|
return _fileSystem.CreateFile(ToFileSystemPath(virtualPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTime GetFileLastWriteTimeUtc(string virtualPath) {
|
||||||
|
return _fileSystem.GetFileEntry(ToFileSystemPath(virtualPath)).LastWriteTimeUtc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DirectoryExists(string virtualPath) {
|
||||||
|
return _fileSystem.GetDirectoryEntry(ToFileSystemPath(virtualPath)) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateDirectory(string virtualPath) {
|
||||||
|
_fileSystem.CreateDirectoryEntry(ToFileSystemPath(virtualPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetDirectoryName(string virtualPath) {
|
||||||
|
return Path.GetDirectoryName(virtualPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> ListFiles(string path) {
|
||||||
|
return _fileSystem.GetDirectoryEntry(ToFileSystemPath(path))
|
||||||
|
.Files
|
||||||
|
.Select(f => Combine(path, f.Name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> ListDirectories(string path) {
|
||||||
|
return _fileSystem.GetDirectoryEntry(ToFileSystemPath(path))
|
||||||
|
.Directories
|
||||||
|
.Select(f => Combine(path, f.Name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -107,7 +107,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
|
|
||||||
return new ExtensionProbeEntry {
|
return new ExtensionProbeEntry {
|
||||||
Descriptor = descriptor,
|
Descriptor = descriptor,
|
||||||
LastModificationTimeUtc = File.GetLastWriteTimeUtc(_virtualPathProvider.MapPath(projectPath)),
|
LastModificationTimeUtc = _virtualPathProvider.GetFileLastWriteTimeUtc(projectPath),
|
||||||
Loader = this,
|
Loader = this,
|
||||||
VirtualPath = projectPath
|
VirtualPath = projectPath
|
||||||
};
|
};
|
||||||
|
@@ -30,6 +30,10 @@ namespace Orchard.FileSystems.VirtualPath {
|
|||||||
return File.CreateText(MapPath(virtualPath));
|
return File.CreateText(MapPath(virtualPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stream CreateFile(string virtualPath) {
|
||||||
|
return File.Create(MapPath(virtualPath));
|
||||||
|
}
|
||||||
|
|
||||||
public DateTime GetFileLastWriteTimeUtc(string virtualPath) {
|
public DateTime GetFileLastWriteTimeUtc(string virtualPath) {
|
||||||
return File.GetLastWriteTimeUtc(MapPath(virtualPath));
|
return File.GetLastWriteTimeUtc(MapPath(virtualPath));
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@ namespace Orchard.FileSystems.VirtualPath {
|
|||||||
bool FileExists(string virtualPath);
|
bool FileExists(string virtualPath);
|
||||||
Stream OpenFile(string virtualPath);
|
Stream OpenFile(string virtualPath);
|
||||||
StreamWriter CreateText(string virtualPath);
|
StreamWriter CreateText(string virtualPath);
|
||||||
|
Stream CreateFile(string virtualPath);
|
||||||
DateTime GetFileLastWriteTimeUtc(string virtualPath);
|
DateTime GetFileLastWriteTimeUtc(string virtualPath);
|
||||||
|
|
||||||
bool DirectoryExists(string virtualPath);
|
bool DirectoryExists(string virtualPath);
|
||||||
|
Reference in New Issue
Block a user