Handle IFileSystem rename.
This commit is contained in:
parent
7667eba34e
commit
d51dad9560
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Hosting;
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Http.Interfaces;
|
using Microsoft.AspNet.Http.Interfaces;
|
||||||
|
|
@ -73,18 +73,18 @@ namespace Microsoft.AspNet.Mvc
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="IFileSystem"/> used to resolve paths.
|
/// Gets or sets the <see cref="IFileProvider"/> used to resolve paths.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IFileSystem FileSystem { get; set; }
|
public IFileProvider FileProvider { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
|
protected override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
var sendFile = response.HttpContext.GetFeature<IHttpSendFileFeature>();
|
var sendFile = response.HttpContext.GetFeature<IHttpSendFileFeature>();
|
||||||
|
|
||||||
var fileSystem = GetFileSystem(response.HttpContext.RequestServices);
|
var fileProvider = GetFileProvider(response.HttpContext.RequestServices);
|
||||||
|
|
||||||
var filePath = ResolveFilePath(fileSystem);
|
var filePath = ResolveFilePath(fileProvider);
|
||||||
|
|
||||||
if (sendFile != null)
|
if (sendFile != null)
|
||||||
{
|
{
|
||||||
|
|
@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal string ResolveFilePath(IFileSystem fileSystem)
|
internal string ResolveFilePath(IFileProvider fileProvider)
|
||||||
{
|
{
|
||||||
// Let the file system try to get the file and if it can't,
|
// Let the file system try to get the file and if it can't,
|
||||||
// fallback to trying the path directly unless the path starts with '/'.
|
// fallback to trying the path directly unless the path starts with '/'.
|
||||||
|
|
@ -117,10 +117,10 @@ namespace Microsoft.AspNet.Mvc
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileInfo = fileSystem.GetFileInfo(path);
|
var fileInfo = fileProvider.GetFileInfo(path);
|
||||||
if (fileInfo.Exists)
|
if (fileInfo.Exists)
|
||||||
{
|
{
|
||||||
// The path is relative and IFileSystem found the file, so return the full
|
// The path is relative and IFileProvider found the file, so return the full
|
||||||
// path.
|
// path.
|
||||||
return fileInfo.PhysicalPath;
|
return fileInfo.PhysicalPath;
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
if (path.StartsWith("~\\", StringComparison.Ordinal))
|
if (path.StartsWith("~\\", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
// ~\ is not a valid virtual path, and we don't want to replace '\' with '/' as it
|
// ~\ is not a valid virtual path, and we don't want to replace '\' with '/' as it
|
||||||
// ofuscates the error, so just return the original path and throw at a later point
|
// obfuscates the error, so just return the original path and throw at a later point
|
||||||
// when we can't find the file.
|
// when we can't find the file.
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
@ -195,19 +195,17 @@ namespace Microsoft.AspNet.Mvc
|
||||||
path.StartsWith("\\\\", StringComparison.Ordinal);
|
path.StartsWith("\\\\", StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IFileSystem GetFileSystem(IServiceProvider requestServices)
|
private IFileProvider GetFileProvider(IServiceProvider requestServices)
|
||||||
{
|
{
|
||||||
if (FileSystem != null)
|
if (FileProvider != null)
|
||||||
{
|
{
|
||||||
return FileSystem;
|
return FileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For right now until we can use IWebRootFileSystemProvider, see
|
|
||||||
// https://github.com/aspnet/Hosting/issues/86 for details.
|
|
||||||
var hostingEnvironment = requestServices.GetService<IHostingEnvironment>();
|
var hostingEnvironment = requestServices.GetService<IHostingEnvironment>();
|
||||||
FileSystem = new PhysicalFileSystem(hostingEnvironment.WebRoot);
|
FileProvider = hostingEnvironment.WebRootFileProvider;
|
||||||
|
|
||||||
return FileSystem;
|
return FileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task CopyStreamToResponse(
|
private static async Task CopyStreamToResponse(
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
"warningsAsErrors": true
|
"warningsAsErrors": true
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.FileSystems": "1.0.0-*",
|
"Microsoft.AspNet.FileProviders": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Hosting": "1.0.0-*",
|
"Microsoft.AspNet.Hosting": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
|
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
|
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Razor;
|
using Microsoft.AspNet.Razor;
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||||
using Microsoft.AspNet.Razor.Parser;
|
using Microsoft.AspNet.Razor.Parser;
|
||||||
|
|
@ -20,21 +20,21 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, CodeTree> _parsedCodeTrees;
|
private readonly Dictionary<string, CodeTree> _parsedCodeTrees;
|
||||||
private readonly MvcRazorHost _razorHost;
|
private readonly MvcRazorHost _razorHost;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileProvider _fileProvider;
|
||||||
private readonly IReadOnlyList<Chunk> _defaultInheritedChunks;
|
private readonly IReadOnlyList<Chunk> _defaultInheritedChunks;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of <see cref="ChunkInheritanceUtility"/>.
|
/// Initializes a new instance of <see cref="ChunkInheritanceUtility"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="razorHost">The <see cref="MvcRazorHost"/> used to parse _ViewStart pages.</param>
|
/// <param name="razorHost">The <see cref="MvcRazorHost"/> used to parse _ViewStart pages.</param>
|
||||||
/// <param name="fileSystem">The filesystem that represents the application.</param>
|
/// <param name="fileProvider">The fileProvider that represents the application.</param>
|
||||||
/// <param name="defaultInheritedChunks">Sequence of <see cref="Chunk"/>s inherited by default.</param>
|
/// <param name="defaultInheritedChunks">Sequence of <see cref="Chunk"/>s inherited by default.</param>
|
||||||
public ChunkInheritanceUtility([NotNull] MvcRazorHost razorHost,
|
public ChunkInheritanceUtility([NotNull] MvcRazorHost razorHost,
|
||||||
[NotNull] IFileSystem fileSystem,
|
[NotNull] IFileProvider fileProvider,
|
||||||
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks)
|
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks)
|
||||||
{
|
{
|
||||||
_razorHost = razorHost;
|
_razorHost = razorHost;
|
||||||
_fileSystem = fileSystem;
|
_fileProvider = fileProvider;
|
||||||
_defaultInheritedChunks = defaultInheritedChunks;
|
_defaultInheritedChunks = defaultInheritedChunks;
|
||||||
_parsedCodeTrees = new Dictionary<string, CodeTree>(StringComparer.Ordinal);
|
_parsedCodeTrees = new Dictionary<string, CodeTree>(StringComparer.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets an ordered <see cref="IReadOnlyList{T}"/> of parsed <see cref="CodeTree"/> for each _ViewStart that
|
/// Gets an ordered <see cref="IReadOnlyList{T}"/> of parsed <see cref="CodeTree"/> for each _ViewStart that
|
||||||
/// is applicable to the page located at <paramref name="pagePath"/>. The list is ordered so that the
|
/// is applicable to the page located at <paramref name="pagePath"/>. The list is ordered so that the
|
||||||
/// <see cref="CodeTree"/> for the _ViewStart closest to the <paramref name="pagePath"/> in the filesystem
|
/// <see cref="CodeTree"/> for the _ViewStart closest to the <paramref name="pagePath"/> in the fileProvider
|
||||||
/// appears first.
|
/// appears first.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pagePath">The path of the page to locate inherited chunks for.</param>
|
/// <param name="pagePath">The path of the page to locate inherited chunks for.</param>
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var fileInfo = _fileSystem.GetFileInfo(viewStartPath);
|
var fileInfo = _fileProvider.GetFileInfo(viewStartPath);
|
||||||
if (fileInfo.Exists)
|
if (fileInfo.Exists)
|
||||||
{
|
{
|
||||||
// viewStartPath contains the app-relative path of the ViewStart.
|
// viewStartPath contains the app-relative path of the ViewStart.
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Mvc.Razor.Directives;
|
using Microsoft.AspNet.Mvc.Razor.Directives;
|
||||||
using Microsoft.AspNet.Razor;
|
using Microsoft.AspNet.Razor;
|
||||||
using Microsoft.AspNet.Razor.Generator;
|
using Microsoft.AspNet.Razor.Generator;
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
new InjectChunk("Microsoft.AspNet.Mvc.IUrlHelper", "Url"),
|
new InjectChunk("Microsoft.AspNet.Mvc.IUrlHelper", "Url"),
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileProvider _fileProvider;
|
||||||
|
|
||||||
// CodeGenerationContext.DefaultBaseClass is set to MyBaseType<dynamic>.
|
// CodeGenerationContext.DefaultBaseClass is set to MyBaseType<dynamic>.
|
||||||
// This field holds the type name without the generic decoration (MyBaseType)
|
// This field holds the type name without the generic decoration (MyBaseType)
|
||||||
|
|
@ -45,18 +45,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="root">The path to the application base.</param>
|
/// <param name="root">The path to the application base.</param>
|
||||||
public MvcRazorHost(string root) :
|
public MvcRazorHost(string root) :
|
||||||
this(new PhysicalFileSystem(root))
|
this(new PhysicalFileProvider(root))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of <see cref="MvcRazorHost"/> using the specified <paramref name="fileSystem"/>.
|
/// Initializes a new instance of <see cref="MvcRazorHost"/> using the specified <paramref name="fileProvider"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileSystem">A <see cref="IFileSystem"/> rooted at the application base path.</param>
|
/// <param name="fileProvider">A <see cref="IFileProvider"/> rooted at the application base path.</param>
|
||||||
public MvcRazorHost(IFileSystem fileSystem)
|
public MvcRazorHost(IFileProvider fileProvider)
|
||||||
: base(new CSharpRazorCodeLanguage())
|
: base(new CSharpRazorCodeLanguage())
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileProvider = fileProvider;
|
||||||
_baseType = BaseType;
|
_baseType = BaseType;
|
||||||
|
|
||||||
TagHelperDescriptorResolver = new TagHelperDescriptorResolver();
|
TagHelperDescriptorResolver = new TagHelperDescriptorResolver();
|
||||||
|
|
@ -164,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
if (_chunkInheritanceUtility == null)
|
if (_chunkInheritanceUtility == null)
|
||||||
{
|
{
|
||||||
// This needs to be lazily evaluated to support DefaultInheritedChunks being virtual.
|
// This needs to be lazily evaluated to support DefaultInheritedChunks being virtual.
|
||||||
_chunkInheritanceUtility = new ChunkInheritanceUtility(this, _fileSystem, DefaultInheritedChunks);
|
_chunkInheritanceUtility = new ChunkInheritanceUtility(this, _fileProvider, DefaultInheritedChunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _chunkInheritanceUtility;
|
return _chunkInheritanceUtility;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
"warningsAsErrors": true
|
"warningsAsErrors": true
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.FileSystems": "1.0.0-*",
|
"Microsoft.AspNet.FileProviders": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
|
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
|
||||||
"Microsoft.AspNet.Razor.Runtime": "4.0.0-*"
|
"Microsoft.AspNet.Razor.Runtime": "4.0.0-*"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public class CompilerCache : ICompilerCache
|
public class CompilerCache : ICompilerCache
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<string, CompilerCacheEntry> _cache;
|
private readonly ConcurrentDictionary<string, CompilerCacheEntry> _cache;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileProvider _fileProvider;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of <see cref="CompilerCache"/> populated with precompiled views
|
/// Initializes a new instance of <see cref="CompilerCache"/> populated with precompiled views
|
||||||
|
|
@ -24,18 +24,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// An <see cref="IAssemblyProvider"/> representing the assemblies
|
/// An <see cref="IAssemblyProvider"/> representing the assemblies
|
||||||
/// used to search for pre-compiled views.
|
/// used to search for pre-compiled views.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="fileSystem">An <see cref="IRazorFileSystemCache"/> instance that represents the application's
|
/// <param name="fileProvider">An <see cref="IRazorFileProviderCache"/> instance that represents the application's
|
||||||
/// file system.
|
/// file system.
|
||||||
/// </param>
|
/// </param>
|
||||||
public CompilerCache(IAssemblyProvider provider, IRazorFileSystemCache fileSystem)
|
public CompilerCache(IAssemblyProvider provider, IRazorFileProviderCache fileProvider)
|
||||||
: this(GetFileInfos(provider.CandidateAssemblies), fileSystem)
|
: this(GetFileInfos(provider.CandidateAssemblies), fileProvider)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal for unit testing
|
// Internal for unit testing
|
||||||
internal CompilerCache(IEnumerable<RazorFileInfoCollection> viewCollections, IFileSystem fileSystem)
|
internal CompilerCache(IEnumerable<RazorFileInfoCollection> viewCollections, IFileProvider fileProvider)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileProvider = fileProvider;
|
||||||
_cache = new ConcurrentDictionary<string, CompilerCacheEntry>(StringComparer.OrdinalIgnoreCase);
|
_cache = new ConcurrentDictionary<string, CompilerCacheEntry>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
foreach (var viewCollection in viewCollections)
|
foreach (var viewCollection in viewCollections)
|
||||||
|
|
@ -184,7 +184,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var viewStartLocations = ViewStartUtility.GetViewStartLocations(relativePath);
|
var viewStartLocations = ViewStartUtility.GetViewStartLocations(relativePath);
|
||||||
foreach (var viewStartLocation in viewStartLocations)
|
foreach (var viewStartLocation in viewStartLocations)
|
||||||
{
|
{
|
||||||
var viewStartFileInfo = _fileSystem.GetFileInfo(viewStartLocation);
|
var viewStartFileInfo = _fileProvider.GetFileInfo(viewStartLocation);
|
||||||
if (viewStartFileInfo.Exists)
|
if (viewStartFileInfo.Exists)
|
||||||
{
|
{
|
||||||
var relativeFileInfo = new RelativeFileInfo(viewStartFileInfo, viewStartLocation);
|
var relativeFileInfo = new RelativeFileInfo(viewStartFileInfo, viewStartLocation);
|
||||||
|
|
|
||||||
|
|
@ -3,31 +3,31 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.Framework.Expiration.Interfaces;
|
using Microsoft.Framework.Expiration.Interfaces;
|
||||||
using Microsoft.Framework.OptionsModel;
|
using Microsoft.Framework.OptionsModel;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default implementation for the <see cref="IRazorFileSystemCache"/> interface that caches
|
/// Default implementation for the <see cref="IRazorFileProviderCache"/> interface that caches
|
||||||
/// the results of <see cref="RazorViewEngineOptions.FileSystem"/>.
|
/// the results of <see cref="RazorViewEngineOptions.FileProvider"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultRazorFileSystemCache : IRazorFileSystemCache
|
public class DefaultRazorFileProviderCache : IRazorFileProviderCache
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<string, ExpiringFileInfo> _fileInfoCache =
|
private readonly ConcurrentDictionary<string, ExpiringFileInfo> _fileInfoCache =
|
||||||
new ConcurrentDictionary<string, ExpiringFileInfo>(StringComparer.Ordinal);
|
new ConcurrentDictionary<string, ExpiringFileInfo>(StringComparer.Ordinal);
|
||||||
|
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileProvider _fileProvider;
|
||||||
private readonly TimeSpan _offset;
|
private readonly TimeSpan _offset;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of <see cref="DefaultRazorFileSystemCache"/>.
|
/// Initializes a new instance of <see cref="DefaultRazorFileProviderCache"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="optionsAccessor">Accessor to <see cref="RazorViewEngineOptions"/>.</param>
|
/// <param name="optionsAccessor">Accessor to <see cref="RazorViewEngineOptions"/>.</param>
|
||||||
public DefaultRazorFileSystemCache(IOptions<RazorViewEngineOptions> optionsAccessor)
|
public DefaultRazorFileProviderCache(IOptions<RazorViewEngineOptions> optionsAccessor)
|
||||||
{
|
{
|
||||||
_fileSystem = optionsAccessor.Options.FileSystem;
|
_fileProvider = optionsAccessor.Options.FileProvider;
|
||||||
_offset = optionsAccessor.Options.ExpirationBeforeCheckingFilesOnDisk;
|
_offset = optionsAccessor.Options.ExpirationBeforeCheckingFilesOnDisk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IDirectoryContents GetDirectoryContents(string subpath)
|
public IDirectoryContents GetDirectoryContents(string subpath)
|
||||||
{
|
{
|
||||||
return _fileSystem.GetDirectoryContents(subpath);
|
return _fileProvider.GetDirectoryContents(subpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var fileInfo = _fileSystem.GetFileInfo(subpath);
|
var fileInfo = _fileProvider.GetFileInfo(subpath);
|
||||||
|
|
||||||
expiringFileInfo = new ExpiringFileInfo()
|
expiringFileInfo = new ExpiringFileInfo()
|
||||||
{
|
{
|
||||||
|
|
@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IExpirationTrigger Watch(string filter)
|
public IExpirationTrigger Watch(string filter)
|
||||||
{
|
{
|
||||||
return _fileSystem.Watch(filter);
|
return _fileProvider.Watch(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ExpiringFileInfo
|
private class ExpiringFileInfo
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An <see cref="IFileSystem"/> that caches the results of <see cref="IFileSystem.GetFileInfo(string)"/> for a
|
/// An <see cref="IFileProvider"/> that caches the results of <see cref="IFileProvider.GetFileInfo(string)"/> for a
|
||||||
/// duration specified by <see cref="RazorViewEngineOptions.ExpirationBeforeCheckingFilesOnDisk"/>.
|
/// duration specified by <see cref="RazorViewEngineOptions.ExpirationBeforeCheckingFilesOnDisk"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IRazorFileSystemCache : IFileSystem
|
public interface IRazorFileProviderCache : IFileProvider
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Reflection.PortableExecutable;
|
using System.Reflection.PortableExecutable;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
using Microsoft.CodeAnalysis.Emit;
|
using Microsoft.CodeAnalysis.Emit;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Mvc.Razor.OptionDescriptors;
|
using Microsoft.AspNet.Mvc.Razor.OptionDescriptors;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
|
|
@ -14,12 +14,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public class RazorViewEngineOptions
|
public class RazorViewEngineOptions
|
||||||
{
|
{
|
||||||
private TimeSpan _expirationBeforeCheckingFilesOnDisk = TimeSpan.FromSeconds(2);
|
private TimeSpan _expirationBeforeCheckingFilesOnDisk = TimeSpan.FromSeconds(2);
|
||||||
private IFileSystem _fileSystem;
|
private IFileProvider _fileProvider;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="TimeSpan"/> that specifies the duration for which results of
|
/// Gets or sets the <see cref="TimeSpan"/> that specifies the duration for which results of
|
||||||
/// <see cref="FileSystem"/> are cached by <see cref="DefaultRazorFileSystemCache"/>.
|
/// <see cref="FileProvider"/> are cached by <see cref="DefaultRazorFileProviderCache"/>.
|
||||||
/// <see cref="DefaultRazorFileSystemCache"/> is used to query for file changes during Razor compilation.
|
/// <see cref="DefaultRazorFileProviderCache"/> is used to query for file changes during Razor compilation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <see cref="TimeSpan"/> of <see cref="TimeSpan.Zero"/> or less, means no caching.
|
/// <see cref="TimeSpan"/> of <see cref="TimeSpan.Zero"/> or less, means no caching.
|
||||||
|
|
@ -53,16 +53,16 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
= new List<ViewLocationExpanderDescriptor>();
|
= new List<ViewLocationExpanderDescriptor>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="IFileSystem" /> used by <see cref="RazorViewEngine"/> to locate Razor files on
|
/// Gets or sets the <see cref="IFileProvider" /> used by <see cref="RazorViewEngine"/> to locate Razor files on
|
||||||
/// disk.
|
/// disk.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// At startup, this is initialized to an instance of <see cref="PhysicalFileSystem"/> that is rooted at the
|
/// At startup, this is initialized to an instance of <see cref="PhysicalFileProvider"/> that is rooted at the
|
||||||
/// application root.
|
/// application root.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public IFileSystem FileSystem
|
public IFileProvider FileProvider
|
||||||
{
|
{
|
||||||
get { return _fileSystem; }
|
get { return _fileProvider; }
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
|
@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
throw new ArgumentNullException(nameof(value));
|
throw new ArgumentNullException(nameof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
_fileSystem = value;
|
_fileProvider = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.Framework.Cache.Memory;
|
using Microsoft.Framework.Cache.Memory;
|
||||||
using Microsoft.Framework.DependencyInjection;
|
using Microsoft.Framework.DependencyInjection;
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public class RazorPreCompiler
|
public class RazorPreCompiler
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileProvider _fileProvider;
|
||||||
|
|
||||||
public RazorPreCompiler([NotNull] IServiceProvider designTimeServiceProvider,
|
public RazorPreCompiler([NotNull] IServiceProvider designTimeServiceProvider,
|
||||||
[NotNull] IMemoryCache precompilationCache,
|
[NotNull] IMemoryCache precompilationCache,
|
||||||
|
|
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
[NotNull] CompilationSettings compilationSettings)
|
[NotNull] CompilationSettings compilationSettings)
|
||||||
{
|
{
|
||||||
_serviceProvider = designTimeServiceProvider;
|
_serviceProvider = designTimeServiceProvider;
|
||||||
_fileSystem = optionsAccessor.Options.FileSystem;
|
_fileProvider = optionsAccessor.Options.FileProvider;
|
||||||
CompilationSettings = compilationSettings;
|
CompilationSettings = compilationSettings;
|
||||||
PreCompilationCache = precompilationCache;
|
PreCompilationCache = precompilationCache;
|
||||||
}
|
}
|
||||||
|
|
@ -120,10 +120,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
|
|
||||||
if (entry != null)
|
if (entry != null)
|
||||||
{
|
{
|
||||||
cacheSetContext.AddExpirationTrigger(_fileSystem.Watch(fileInfo.RelativePath));
|
cacheSetContext.AddExpirationTrigger(_fileProvider.Watch(fileInfo.RelativePath));
|
||||||
foreach (var viewStartPath in ViewStartUtility.GetViewStartLocations(fileInfo.RelativePath))
|
foreach (var viewStartPath in ViewStartUtility.GetViewStartLocations(fileInfo.RelativePath))
|
||||||
{
|
{
|
||||||
cacheSetContext.AddExpirationTrigger(_fileSystem.Watch(viewStartPath));
|
cacheSetContext.AddExpirationTrigger(_fileProvider.Watch(viewStartPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
|
|
||||||
private void GetFileInfosRecursive(string root, List<RelativeFileInfo> razorFiles)
|
private void GetFileInfosRecursive(string root, List<RelativeFileInfo> razorFiles)
|
||||||
{
|
{
|
||||||
var fileInfos = _fileSystem.GetDirectoryContents(root);
|
var fileInfos = _fileProvider.GetDirectoryContents(root);
|
||||||
|
|
||||||
foreach (var fileInfo in fileInfos)
|
foreach (var fileInfo in fileInfos)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.PageExecutionInstrumentation;
|
using Microsoft.AspNet.PageExecutionInstrumentation;
|
||||||
using Microsoft.Framework.DependencyInjection;
|
using Microsoft.Framework.DependencyInjection;
|
||||||
|
|
@ -17,19 +17,19 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
private readonly ITypeActivator _activator;
|
private readonly ITypeActivator _activator;
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly IRazorFileSystemCache _fileSystemCache;
|
private readonly IRazorFileProviderCache _fileProviderCache;
|
||||||
private readonly ICompilerCache _compilerCache;
|
private readonly ICompilerCache _compilerCache;
|
||||||
private IRazorCompilationService _razorcompilationService;
|
private IRazorCompilationService _razorcompilationService;
|
||||||
|
|
||||||
public VirtualPathRazorPageFactory(ITypeActivator typeActivator,
|
public VirtualPathRazorPageFactory(ITypeActivator typeActivator,
|
||||||
IServiceProvider serviceProvider,
|
IServiceProvider serviceProvider,
|
||||||
ICompilerCache compilerCache,
|
ICompilerCache compilerCache,
|
||||||
IRazorFileSystemCache fileSystemCache)
|
IRazorFileProviderCache fileProviderCache)
|
||||||
{
|
{
|
||||||
_activator = typeActivator;
|
_activator = typeActivator;
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_compilerCache = compilerCache;
|
_compilerCache = compilerCache;
|
||||||
_fileSystemCache = fileSystemCache;
|
_fileProviderCache = fileProviderCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRazorCompilationService RazorCompilationService
|
private IRazorCompilationService RazorCompilationService
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
// it is ok to use the cached service provider because both this, and the
|
// it is ok to use the cached service provider because both this, and the
|
||||||
// resolved service are in a lifetime of Scoped.
|
// resolved service are in a lifetime of Scoped.
|
||||||
// We don't want to get it upgront because it will force Roslyn to load.
|
// We don't want to get it upfront because it will force Roslyn to load.
|
||||||
_razorcompilationService = _serviceProvider.GetRequiredService<IRazorCompilationService>();
|
_razorcompilationService = _serviceProvider.GetRequiredService<IRazorCompilationService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,11 +53,11 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
if (relativePath.StartsWith("~/", StringComparison.Ordinal))
|
if (relativePath.StartsWith("~/", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
// For tilde slash paths, drop the leading ~ to make it work with the underlying IFileSystem.
|
// For tilde slash paths, drop the leading ~ to make it work with the underlying IFileProvider.
|
||||||
relativePath = relativePath.Substring(1);
|
relativePath = relativePath.Substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileInfo = _fileSystemCache.GetFileInfo(relativePath);
|
var fileInfo = _fileProviderCache.GetFileInfo(relativePath);
|
||||||
|
|
||||||
if (fileInfo.Exists)
|
if (fileInfo.Exists)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -102,13 +102,13 @@ namespace Microsoft.AspNet.Mvc
|
||||||
yield return describe.Transient<IViewLocationExpanderProvider, DefaultViewLocationExpanderProvider>();
|
yield return describe.Transient<IViewLocationExpanderProvider, DefaultViewLocationExpanderProvider>();
|
||||||
// Caches view locations that are valid for the lifetime of the application.
|
// Caches view locations that are valid for the lifetime of the application.
|
||||||
yield return describe.Singleton<IViewLocationCache, DefaultViewLocationCache>();
|
yield return describe.Singleton<IViewLocationCache, DefaultViewLocationCache>();
|
||||||
yield return describe.Singleton<IRazorFileSystemCache, DefaultRazorFileSystemCache>();
|
yield return describe.Singleton<IRazorFileProviderCache, DefaultRazorFileProviderCache>();
|
||||||
|
|
||||||
// The host is designed to be discarded after consumption and is very inexpensive to initialize.
|
// The host is designed to be discarded after consumption and is very inexpensive to initialize.
|
||||||
yield return describe.Transient<IMvcRazorHost>(serviceProvider =>
|
yield return describe.Transient<IMvcRazorHost>(serviceProvider =>
|
||||||
{
|
{
|
||||||
var cachedFileSystem = serviceProvider.GetRequiredService<IRazorFileSystemCache>();
|
var cachedFileProvider = serviceProvider.GetRequiredService<IRazorFileProviderCache>();
|
||||||
return new MvcRazorHost(cachedFileSystem);
|
return new MvcRazorHost(cachedFileProvider);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Caches compilation artifacts across the lifetime of the application.
|
// Caches compilation artifacts across the lifetime of the application.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Mvc.Razor;
|
using Microsoft.AspNet.Mvc.Razor;
|
||||||
using Microsoft.Framework.OptionsModel;
|
using Microsoft.Framework.OptionsModel;
|
||||||
using Microsoft.Framework.Runtime;
|
using Microsoft.Framework.Runtime;
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
private static void ConfigureRazor(RazorViewEngineOptions razorOptions,
|
private static void ConfigureRazor(RazorViewEngineOptions razorOptions,
|
||||||
IApplicationEnvironment applicationEnvironment)
|
IApplicationEnvironment applicationEnvironment)
|
||||||
{
|
{
|
||||||
razorOptions.FileSystem = new PhysicalFileSystem(applicationEnvironment.ApplicationBasePath);
|
razorOptions.FileProvider = new PhysicalFileProvider(applicationEnvironment.ApplicationBasePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Hosting;
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.AspNet.Http.Core;
|
using Microsoft.AspNet.Http.Core;
|
||||||
using Microsoft.AspNet.Http.Interfaces;
|
using Microsoft.AspNet.Http.Interfaces;
|
||||||
|
|
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
var result = new FilePathResult(path, "text/plain")
|
var result = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = new PhysicalFileSystem(Path.GetFullPath(".")),
|
FileProvider = new PhysicalFileProvider(Path.GetFullPath(".")),
|
||||||
};
|
};
|
||||||
|
|
||||||
var httpContext = new DefaultHttpContext();
|
var httpContext = new DefaultHttpContext();
|
||||||
|
|
@ -56,15 +56,15 @@ namespace Microsoft.AspNet.Mvc
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ExecuteResultAsync_FallsBackToThePhysicalFileSystem_IfNoFileSystemIsPresent()
|
public async Task ExecuteResultAsync_FallsBackToThePhysicalFileProvider_IfNoFileProviderIsPresent()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt");
|
var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt");
|
||||||
var result = new FilePathResult(path, "text/plain");
|
var result = new FilePathResult(path, "text/plain");
|
||||||
|
|
||||||
var appEnvironment = new Mock<IHostingEnvironment>();
|
var appEnvironment = new Mock<IHostingEnvironment>();
|
||||||
appEnvironment.Setup(app => app.WebRoot)
|
appEnvironment.Setup(app => app.WebRootFileProvider)
|
||||||
.Returns(Directory.GetCurrentDirectory());
|
.Returns(new PhysicalFileProvider(Directory.GetCurrentDirectory()));
|
||||||
|
|
||||||
var httpContext = new DefaultHttpContext();
|
var httpContext = new DefaultHttpContext();
|
||||||
httpContext.Response.Body = new MemoryStream();
|
httpContext.Response.Body = new MemoryStream();
|
||||||
|
|
@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
var result = new FilePathResult(path, "text/plain")
|
var result = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = new PhysicalFileSystem(Path.GetFullPath(".")),
|
FileProvider = new PhysicalFileProvider(Path.GetFullPath(".")),
|
||||||
};
|
};
|
||||||
|
|
||||||
var sendFileMock = new Mock<IHttpSendFileFeature>();
|
var sendFileMock = new Mock<IHttpSendFileFeature>();
|
||||||
|
|
@ -122,10 +122,10 @@ namespace Microsoft.AspNet.Mvc
|
||||||
// forward slashes.
|
// forward slashes.
|
||||||
path = path.Replace('/', '\\');
|
path = path.Replace('/', '\\');
|
||||||
|
|
||||||
// Point the FileSystemRoot to a subfolder
|
// Point the FileProviderRoot to a subfolder
|
||||||
var result = new FilePathResult(path, "text/plain")
|
var result = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = new PhysicalFileSystem(Path.GetFullPath("Utils")),
|
FileProvider = new PhysicalFileProvider(Path.GetFullPath("Utils")),
|
||||||
};
|
};
|
||||||
|
|
||||||
var httpContext = new DefaultHttpContext();
|
var httpContext = new DefaultHttpContext();
|
||||||
|
|
@ -151,10 +151,10 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var path = Path.GetFullPath(Path.Combine(".", "TestFiles", "FilePathResultTestFile.txt"));
|
var path = Path.GetFullPath(Path.Combine(".", "TestFiles", "FilePathResultTestFile.txt"));
|
||||||
path = path.Replace(@"\", "/");
|
path = path.Replace(@"\", "/");
|
||||||
|
|
||||||
// Point the FileSystemRoot to a subfolder
|
// Point the FileProviderRoot to a subfolder
|
||||||
var result = new FilePathResult(path, "text/plain")
|
var result = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = new PhysicalFileSystem(Path.GetFullPath("Utils")),
|
FileProvider = new PhysicalFileProvider(Path.GetFullPath("Utils")),
|
||||||
};
|
};
|
||||||
|
|
||||||
var httpContext = new DefaultHttpContext();
|
var httpContext = new DefaultHttpContext();
|
||||||
|
|
@ -203,15 +203,15 @@ namespace Microsoft.AspNet.Mvc
|
||||||
public void GetFilePath_Resolves_RelativePaths(string path, string relativePathToFile)
|
public void GetFilePath_Resolves_RelativePaths(string path, string relativePathToFile)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileSystem = new PhysicalFileSystem(Path.GetFullPath("./TestFiles"));
|
var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./TestFiles"));
|
||||||
var expectedPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePathToFile));
|
var expectedPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePathToFile));
|
||||||
var filePathResult = new FilePathResult(path, "text/plain")
|
var filePathResult = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = fileSystem,
|
FileProvider = fileProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = filePathResult.ResolveFilePath(fileSystem);
|
var result = filePathResult.ResolveFilePath(fileProvider);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedPath, result);
|
Assert.Equal(expectedPath, result);
|
||||||
|
|
@ -224,15 +224,15 @@ namespace Microsoft.AspNet.Mvc
|
||||||
public void GetFilePath_FailsToResolve_InvalidVirtualPaths(string path, string relativePathToFile)
|
public void GetFilePath_FailsToResolve_InvalidVirtualPaths(string path, string relativePathToFile)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileSystem = new PhysicalFileSystem(Path.GetFullPath("./TestFiles"));
|
var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./TestFiles"));
|
||||||
var expectedPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePathToFile));
|
var expectedPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePathToFile));
|
||||||
var filePathResult = new FilePathResult(path, "text/plain")
|
var filePathResult = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = fileSystem,
|
FileProvider = fileProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var ex = Assert.Throws<FileNotFoundException>(() => filePathResult.ResolveFilePath(fileSystem));
|
var ex = Assert.Throws<FileNotFoundException>(() => filePathResult.ResolveFilePath(fileProvider));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("Could not find file: " + path, ex.Message);
|
Assert.Equal("Could not find file: " + path, ex.Message);
|
||||||
|
|
@ -271,18 +271,18 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
// Point the IFileSystem root to a different subfolder
|
// Point the IFileProvider root to a different subfolder
|
||||||
var fileSystem = new PhysicalFileSystem(Path.GetFullPath("./Utils"));
|
var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./Utils"));
|
||||||
var filePathResult = new FilePathResult(path, "text/plain")
|
var filePathResult = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = fileSystem,
|
FileProvider = fileProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
var expectedFileName = path.TrimStart('~').Replace('\\', '/');
|
var expectedFileName = path.TrimStart('~').Replace('\\', '/');
|
||||||
var expectedMessage = "Could not find file: " + expectedFileName;
|
var expectedMessage = "Could not find file: " + expectedFileName;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var ex = Assert.Throws<FileNotFoundException>(() => filePathResult.ResolveFilePath(fileSystem));
|
var ex = Assert.Throws<FileNotFoundException>(() => filePathResult.ResolveFilePath(fileProvider));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedMessage, ex.Message);
|
Assert.Equal(expectedMessage, ex.Message);
|
||||||
|
|
@ -322,7 +322,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileResult = new FilePathResult(path, "text/plain")
|
var fileResult = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = Mock.Of<IFileSystem>(),
|
FileProvider = Mock.Of<IFileProvider>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -342,7 +342,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileResult = new FilePathResult(path, "text/plain")
|
var fileResult = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = Mock.Of<IFileSystem>(),
|
FileProvider = Mock.Of<IFileProvider>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -362,7 +362,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileResult = new FilePathResult(path, "text/plain")
|
var fileResult = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = Mock.Of<IFileSystem>(),
|
FileProvider = Mock.Of<IFileProvider>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -382,7 +382,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileResult = new FilePathResult(path, "text/plain")
|
var fileResult = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = Mock.Of<IFileSystem>(),
|
FileProvider = Mock.Of<IFileProvider>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -427,7 +427,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileResult = new FilePathResult(path, "text/plain")
|
var fileResult = new FilePathResult(path, "text/plain")
|
||||||
{
|
{
|
||||||
FileSystem = Mock.Of<IFileSystem>(),
|
FileProvider = Mock.Of<IFileProvider>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||||
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
|
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RazorViewEngine_UsesFileSystemOnViewEngineOptionsToLocateViews()
|
public async Task RazorViewEngine_UsesFileProviderOnViewEngineOptionsToLocateViews()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var expectedMessage = "Hello test-user, this is /RazorViewEngineOptions_Home";
|
var expectedMessage = "Hello test-user, this is /RazorViewEngineOptions_Home";
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RazorViewEngine_UsesFileSystemOnViewEngineOptionsToLocateAreaViews()
|
public async Task RazorViewEngine_UsesFileProviderOnViewEngineOptionsToLocateAreaViews()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var expectedMessage = "Hello admin-user, this is /Restricted/RazorViewEngineOptions_Admin/Login";
|
var expectedMessage = "Hello admin-user, this is /Restricted/RazorViewEngineOptions_Admin/Login";
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
public void GetInheritedChunks_ReadsChunksFromViewStartsInPath()
|
public void GetInheritedChunks_ReadsChunksFromViewStartsInPath()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
fileSystem.AddFile(@"Views\accounts\_ViewStart.cshtml", "@using AccountModels");
|
fileProvider.AddFile(@"Views\accounts\_ViewStart.cshtml", "@using AccountModels");
|
||||||
fileSystem.AddFile(@"Views\Shared\_ViewStart.cshtml", "@inject SharedHelper Shared");
|
fileProvider.AddFile(@"Views\Shared\_ViewStart.cshtml", "@inject SharedHelper Shared");
|
||||||
fileSystem.AddFile(@"Views\home\_ViewStart.cshtml", "@using MyNamespace");
|
fileProvider.AddFile(@"Views\home\_ViewStart.cshtml", "@using MyNamespace");
|
||||||
fileSystem.AddFile(@"Views\_ViewStart.cshtml",
|
fileProvider.AddFile(@"Views\_ViewStart.cshtml",
|
||||||
@"@inject MyHelper<TModel> Helper
|
@"@inject MyHelper<TModel> Helper
|
||||||
@inherits MyBaseType
|
@inherits MyBaseType
|
||||||
|
|
||||||
|
|
@ -30,8 +30,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
new InjectChunk("MyTestHtmlHelper", "Html"),
|
new InjectChunk("MyTestHtmlHelper", "Html"),
|
||||||
new UsingChunk { Namespace = "AppNamespace.Model" },
|
new UsingChunk { Namespace = "AppNamespace.Model" },
|
||||||
};
|
};
|
||||||
var host = new MvcRazorHost(fileSystem);
|
var host = new MvcRazorHost(fileProvider);
|
||||||
var utility = new ChunkInheritanceUtility(host, fileSystem, defaultChunks);
|
var utility = new ChunkInheritanceUtility(host, fileProvider, defaultChunks);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml");
|
var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml");
|
||||||
|
|
@ -66,17 +66,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
public void GetInheritedChunks_ReturnsEmptySequenceIfNoViewStartsArePresent()
|
public void GetInheritedChunks_ReturnsEmptySequenceIfNoViewStartsArePresent()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
fileSystem.AddFile(@"_ViewStart.cs", string.Empty);
|
fileProvider.AddFile(@"_ViewStart.cs", string.Empty);
|
||||||
fileSystem.AddFile(@"Views\_Layout.cshtml", string.Empty);
|
fileProvider.AddFile(@"Views\_Layout.cshtml", string.Empty);
|
||||||
fileSystem.AddFile(@"Views\home\_not-viewstart.cshtml", string.Empty);
|
fileProvider.AddFile(@"Views\home\_not-viewstart.cshtml", string.Empty);
|
||||||
var host = new MvcRazorHost(fileSystem);
|
var host = new MvcRazorHost(fileProvider);
|
||||||
var defaultChunks = new Chunk[]
|
var defaultChunks = new Chunk[]
|
||||||
{
|
{
|
||||||
new InjectChunk("MyTestHtmlHelper", "Html"),
|
new InjectChunk("MyTestHtmlHelper", "Html"),
|
||||||
new UsingChunk { Namespace = "AppNamespace.Model" },
|
new UsingChunk { Namespace = "AppNamespace.Model" },
|
||||||
};
|
};
|
||||||
var utility = new ChunkInheritanceUtility(host, fileSystem, defaultChunks);
|
var utility = new ChunkInheritanceUtility(host, fileProvider, defaultChunks);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml");
|
var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml");
|
||||||
|
|
@ -89,10 +89,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
public void MergeInheritedChunks_MergesDefaultInheritedChunks()
|
public void MergeInheritedChunks_MergesDefaultInheritedChunks()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
fileSystem.AddFile(@"Views\_ViewStart.cshtml",
|
fileProvider.AddFile(@"Views\_ViewStart.cshtml",
|
||||||
"@inject DifferentHelper<TModel> Html");
|
"@inject DifferentHelper<TModel> Html");
|
||||||
var host = new MvcRazorHost(fileSystem);
|
var host = new MvcRazorHost(fileProvider);
|
||||||
var defaultChunks = new Chunk[]
|
var defaultChunks = new Chunk[]
|
||||||
{
|
{
|
||||||
new InjectChunk("MyTestHtmlHelper", "Html"),
|
new InjectChunk("MyTestHtmlHelper", "Html"),
|
||||||
|
|
@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var utility = new ChunkInheritanceUtility(host, fileSystem, defaultChunks);
|
var utility = new ChunkInheritanceUtility(host, fileProvider, defaultChunks);
|
||||||
var codeTree = new CodeTree();
|
var codeTree = new CodeTree();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ MyType1
|
||||||
private static CodeBuilderContext CreateContext()
|
private static CodeBuilderContext CreateContext()
|
||||||
{
|
{
|
||||||
return new CodeBuilderContext(
|
return new CodeBuilderContext(
|
||||||
new CodeGeneratorContext(new MvcRazorHost(new TestFileSystem()),
|
new CodeGeneratorContext(new MvcRazorHost(new TestFileProvider()),
|
||||||
"MyClass",
|
"MyClass",
|
||||||
"MyNamespace",
|
"MyNamespace",
|
||||||
string.Empty,
|
string.Empty,
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ Environment.NewLine +
|
||||||
private static CodeBuilderContext CreateContext()
|
private static CodeBuilderContext CreateContext()
|
||||||
{
|
{
|
||||||
return new CodeBuilderContext(
|
return new CodeBuilderContext(
|
||||||
new CodeGeneratorContext(new MvcRazorHost(new TestFileSystem()),
|
new CodeGeneratorContext(new MvcRazorHost(new TestFileProvider()),
|
||||||
"MyClass",
|
"MyClass",
|
||||||
"MyNamespace",
|
"MyNamespace",
|
||||||
string.Empty,
|
string.Empty,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Razor;
|
using Microsoft.AspNet.Razor;
|
||||||
using Microsoft.AspNet.Razor.Generator;
|
using Microsoft.AspNet.Razor.Generator;
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public void MvcRazorHost_EnablesInstrumentationByDefault()
|
public void MvcRazorHost_EnablesInstrumentationByDefault()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var host = new MvcRazorHost(new TestFileSystem());
|
var host = new MvcRazorHost(new TestFileProvider());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var instrumented = host.EnableInstrumentation;
|
var instrumented = host.EnableInstrumentation;
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public void MvcRazorHost_GeneratesTagHelperModelExpressionCode_DesignTime()
|
public void MvcRazorHost_GeneratesTagHelperModelExpressionCode_DesignTime()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var host = new MvcRazorHost(new TestFileSystem())
|
var host = new MvcRazorHost(new TestFileProvider())
|
||||||
{
|
{
|
||||||
DesignTimeMode = true
|
DesignTimeMode = true
|
||||||
};
|
};
|
||||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public void MvcRazorHost_ParsesAndGeneratesCodeForBasicScenarios(string scenarioName)
|
public void MvcRazorHost_ParsesAndGeneratesCodeForBasicScenarios(string scenarioName)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var host = new TestMvcRazorHost(new TestFileSystem());
|
var host = new TestMvcRazorHost(new TestFileProvider());
|
||||||
|
|
||||||
// Act and Assert
|
// Act and Assert
|
||||||
RunRuntimeTest(host, scenarioName);
|
RunRuntimeTest(host, scenarioName);
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public void InjectVisitor_GeneratesCorrectLineMappings()
|
public void InjectVisitor_GeneratesCorrectLineMappings()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var host = new MvcRazorHost(new TestFileSystem())
|
var host = new MvcRazorHost(new TestFileProvider())
|
||||||
{
|
{
|
||||||
DesignTimeMode = true
|
DesignTimeMode = true
|
||||||
};
|
};
|
||||||
|
|
@ -113,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public void InjectVisitorWithModel_GeneratesCorrectLineMappings()
|
public void InjectVisitorWithModel_GeneratesCorrectLineMappings()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var host = new MvcRazorHost(new TestFileSystem())
|
var host = new MvcRazorHost(new TestFileProvider())
|
||||||
{
|
{
|
||||||
DesignTimeMode = true
|
DesignTimeMode = true
|
||||||
};
|
};
|
||||||
|
|
@ -133,7 +133,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public void ModelVisitor_GeneratesCorrectLineMappings()
|
public void ModelVisitor_GeneratesCorrectLineMappings()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var host = new MvcRazorHost(new TestFileSystem())
|
var host = new MvcRazorHost(new TestFileProvider())
|
||||||
{
|
{
|
||||||
DesignTimeMode = true
|
DesignTimeMode = true
|
||||||
};
|
};
|
||||||
|
|
@ -229,8 +229,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private class TestMvcRazorHost : MvcRazorHost
|
private class TestMvcRazorHost : MvcRazorHost
|
||||||
{
|
{
|
||||||
public TestMvcRazorHost(IFileSystem fileSystem)
|
public TestMvcRazorHost(IFileProvider fileProvider)
|
||||||
: base(fileSystem)
|
: base(fileProvider)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public override CodeBuilder DecorateCodeBuilder(CodeBuilder incomingBuilder, CodeBuilderContext context)
|
public override CodeBuilder DecorateCodeBuilder(CodeBuilder incomingBuilder, CodeBuilderContext context)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.Framework.Expiration.Interfaces;
|
using Microsoft.Framework.Expiration.Interfaces;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
public class TestFileSystem : IFileSystem
|
public class TestFileProvider : IFileProvider
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, IFileInfo> _lookup =
|
private readonly Dictionary<string, IFileInfo> _lookup =
|
||||||
new Dictionary<string, IFileInfo>(StringComparer.Ordinal);
|
new Dictionary<string, IFileInfo>(StringComparer.Ordinal);
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.Framework.Runtime;
|
using Microsoft.Framework.Runtime;
|
||||||
using Microsoft.Framework.Runtime.Infrastructure;
|
using Microsoft.Framework.Runtime.Infrastructure;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
@"Views\_ViewStart.cshtml",
|
@"Views\_ViewStart.cshtml",
|
||||||
@"_ViewStart.cshtml"
|
@"_ViewStart.cshtml"
|
||||||
};
|
};
|
||||||
var fileSystem = new PhysicalFileSystem(GetTestFileSystemBase());
|
var fileProvider = new PhysicalFileProvider(GetTestFileProviderBase());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = ViewStartUtility.GetViewStartLocations(inputPath);
|
var result = ViewStartUtility.GetViewStartLocations(inputPath);
|
||||||
|
|
@ -116,7 +116,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public void GetViewStartLocations_ReturnsEmptySequence_IfViewStartIsAtRoot()
|
public void GetViewStartLocations_ReturnsEmptySequence_IfViewStartIsAtRoot()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var appBase = GetTestFileSystemBase();
|
var appBase = GetTestFileProviderBase();
|
||||||
var viewPath = "_ViewStart.cshtml";
|
var viewPath = "_ViewStart.cshtml";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public void GetViewStartLocations_ReturnsEmptySequence_IfPathIsRooted()
|
public void GetViewStartLocations_ReturnsEmptySequence_IfPathIsRooted()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var appBase = GetTestFileSystemBase();
|
var appBase = GetTestFileProviderBase();
|
||||||
var absolutePath = Path.Combine(Directory.GetCurrentDirectory(), "Index.cshtml");
|
var absolutePath = Path.Combine(Directory.GetCurrentDirectory(), "Index.cshtml");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -140,7 +140,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
Assert.Empty(result);
|
Assert.Empty(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetTestFileSystemBase()
|
private static string GetTestFileProviderBase()
|
||||||
{
|
{
|
||||||
var serviceProvider = CallContextServiceLocator.Locator.ServiceProvider;
|
var serviceProvider = CallContextServiceLocator.Locator.ServiceProvider;
|
||||||
var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment));
|
var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment));
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public void GetOrAdd_ReturnsCompilationResultFromFactory()
|
public void GetOrAdd_ReturnsCompilationResultFromFactory()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
var cache = new CompilerCache(Enumerable.Empty<RazorFileInfoCollection>(), fileSystem);
|
var cache = new CompilerCache(Enumerable.Empty<RazorFileInfoCollection>(), fileProvider);
|
||||||
var fileInfo = new TestFileInfo
|
var fileInfo = new TestFileInfo
|
||||||
{
|
{
|
||||||
LastModified = DateTime.FromFileTimeUtc(10000)
|
LastModified = DateTime.FromFileTimeUtc(10000)
|
||||||
|
|
@ -111,8 +111,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var instance = new RuntimeCompileIdentical();
|
var instance = new RuntimeCompileIdentical();
|
||||||
var length = Encoding.UTF8.GetByteCount(instance.Content);
|
var length = Encoding.UTF8.GetByteCount(instance.Content);
|
||||||
var collection = new ViewCollection();
|
var collection = new ViewCollection();
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
var cache = new CompilerCache(new[] { new ViewCollection() }, fileSystem);
|
var cache = new CompilerCache(new[] { new ViewCollection() }, fileProvider);
|
||||||
|
|
||||||
var fileInfo = new TestFileInfo
|
var fileInfo = new TestFileInfo
|
||||||
{
|
{
|
||||||
|
|
@ -153,8 +153,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var instance = (View)Activator.CreateInstance(resultViewType);
|
var instance = (View)Activator.CreateInstance(resultViewType);
|
||||||
var length = Encoding.UTF8.GetByteCount(instance.Content);
|
var length = Encoding.UTF8.GetByteCount(instance.Content);
|
||||||
var collection = new ViewCollection();
|
var collection = new ViewCollection();
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
var cache = new CompilerCache(new[] { new ViewCollection() }, fileSystem);
|
var cache = new CompilerCache(new[] { new ViewCollection() }, fileProvider);
|
||||||
|
|
||||||
var fileInfo = new TestFileInfo
|
var fileInfo = new TestFileInfo
|
||||||
{
|
{
|
||||||
|
|
@ -189,7 +189,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
// Arrange
|
// Arrange
|
||||||
var instance = (View)Activator.CreateInstance(typeof(PreCompile));
|
var instance = (View)Activator.CreateInstance(typeof(PreCompile));
|
||||||
var length = Encoding.UTF8.GetByteCount(instance.Content);
|
var length = Encoding.UTF8.GetByteCount(instance.Content);
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
|
|
||||||
var lastModified = DateTime.UtcNow;
|
var lastModified = DateTime.UtcNow;
|
||||||
|
|
||||||
|
|
@ -207,7 +207,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
Content = viewStartContent,
|
Content = viewStartContent,
|
||||||
LastModified = DateTime.UtcNow
|
LastModified = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
fileSystem.AddFile("_ViewStart.cshtml", viewStartFileInfo);
|
fileProvider.AddFile("_ViewStart.cshtml", viewStartFileInfo);
|
||||||
var viewStartRazorFileInfo = new RazorFileInfo
|
var viewStartRazorFileInfo = new RazorFileInfo
|
||||||
{
|
{
|
||||||
Hash = RazorFileHash.GetHash(GetMemoryStream(viewStartContent)),
|
Hash = RazorFileHash.GetHash(GetMemoryStream(viewStartContent)),
|
||||||
|
|
@ -219,7 +219,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
|
|
||||||
var precompiledViews = new ViewCollection();
|
var precompiledViews = new ViewCollection();
|
||||||
precompiledViews.Add(viewStartRazorFileInfo);
|
precompiledViews.Add(viewStartRazorFileInfo);
|
||||||
var cache = new CompilerCache(new[] { precompiledViews }, fileSystem);
|
var cache = new CompilerCache(new[] { precompiledViews }, fileProvider);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = cache.GetOrAdd(runtimeFileInfo,
|
var actual = cache.GetOrAdd(runtimeFileInfo,
|
||||||
|
|
@ -235,18 +235,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
// Arrange
|
// Arrange
|
||||||
var expectedType = typeof(RuntimeCompileDifferent);
|
var expectedType = typeof(RuntimeCompileDifferent);
|
||||||
var lastModified = DateTime.UtcNow;
|
var lastModified = DateTime.UtcNow;
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
var collection = new ViewCollection();
|
var collection = new ViewCollection();
|
||||||
var precompiledFile = collection.FileInfos[0];
|
var precompiledFile = collection.FileInfos[0];
|
||||||
precompiledFile.RelativePath = "Views\\home\\index.cshtml";
|
precompiledFile.RelativePath = "Views\\home\\index.cshtml";
|
||||||
var cache = new CompilerCache(new[] { collection }, fileSystem);
|
var cache = new CompilerCache(new[] { collection }, fileProvider);
|
||||||
var testFile = new TestFileInfo
|
var testFile = new TestFileInfo
|
||||||
{
|
{
|
||||||
Content = new PreCompile().Content,
|
Content = new PreCompile().Content,
|
||||||
LastModified = precompiledFile.LastModified,
|
LastModified = precompiledFile.LastModified,
|
||||||
PhysicalPath = precompiledFile.RelativePath
|
PhysicalPath = precompiledFile.RelativePath
|
||||||
};
|
};
|
||||||
fileSystem.AddFile(precompiledFile.RelativePath, testFile);
|
fileProvider.AddFile(precompiledFile.RelativePath, testFile);
|
||||||
var relativeFile = new RelativeFileInfo(testFile, testFile.PhysicalPath);
|
var relativeFile = new RelativeFileInfo(testFile, testFile.PhysicalPath);
|
||||||
|
|
||||||
// Act 1
|
// Act 1
|
||||||
|
|
@ -257,7 +257,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
Assert.Equal(typeof(PreCompile), actual1.CompiledType);
|
Assert.Equal(typeof(PreCompile), actual1.CompiledType);
|
||||||
|
|
||||||
// Act 2
|
// Act 2
|
||||||
fileSystem.AddFile("Views\\_ViewStart.cshtml", "");
|
fileProvider.AddFile("Views\\_ViewStart.cshtml", "");
|
||||||
var actual2 = cache.GetOrAdd(relativeFile,
|
var actual2 = cache.GetOrAdd(relativeFile,
|
||||||
compile: _ => CompilationResult.Successful(expectedType));
|
compile: _ => CompilationResult.Successful(expectedType));
|
||||||
|
|
||||||
|
|
@ -271,7 +271,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
// Arrange
|
// Arrange
|
||||||
var expectedType = typeof(RuntimeCompileDifferent);
|
var expectedType = typeof(RuntimeCompileDifferent);
|
||||||
var lastModified = DateTime.UtcNow;
|
var lastModified = DateTime.UtcNow;
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
|
|
||||||
var viewCollection = new ViewCollection();
|
var viewCollection = new ViewCollection();
|
||||||
var precompiledView = viewCollection.FileInfos[0];
|
var precompiledView = viewCollection.FileInfos[0];
|
||||||
|
|
@ -282,7 +282,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
LastModified = precompiledView.LastModified,
|
LastModified = precompiledView.LastModified,
|
||||||
PhysicalPath = precompiledView.RelativePath
|
PhysicalPath = precompiledView.RelativePath
|
||||||
};
|
};
|
||||||
fileSystem.AddFile(viewFileInfo.PhysicalPath, viewFileInfo);
|
fileProvider.AddFile(viewFileInfo.PhysicalPath, viewFileInfo);
|
||||||
|
|
||||||
var viewStartFileInfo = new TestFileInfo
|
var viewStartFileInfo = new TestFileInfo
|
||||||
{
|
{
|
||||||
|
|
@ -298,10 +298,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
Hash = RazorFileHash.GetHash(viewStartFileInfo),
|
Hash = RazorFileHash.GetHash(viewStartFileInfo),
|
||||||
Length = viewStartFileInfo.Length
|
Length = viewStartFileInfo.Length
|
||||||
};
|
};
|
||||||
fileSystem.AddFile(viewStartFileInfo.PhysicalPath, viewStartFileInfo);
|
fileProvider.AddFile(viewStartFileInfo.PhysicalPath, viewStartFileInfo);
|
||||||
|
|
||||||
viewCollection.Add(viewStart);
|
viewCollection.Add(viewStart);
|
||||||
var cache = new CompilerCache(new[] { viewCollection }, fileSystem);
|
var cache = new CompilerCache(new[] { viewCollection }, fileProvider);
|
||||||
var fileInfo = new RelativeFileInfo(viewFileInfo, viewFileInfo.PhysicalPath);
|
var fileInfo = new RelativeFileInfo(viewFileInfo, viewFileInfo.PhysicalPath);
|
||||||
|
|
||||||
// Act 1
|
// Act 1
|
||||||
|
|
@ -312,7 +312,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
Assert.Equal(typeof(PreCompile), actual1.CompiledType);
|
Assert.Equal(typeof(PreCompile), actual1.CompiledType);
|
||||||
|
|
||||||
// Act 2
|
// Act 2
|
||||||
fileSystem.DeleteFile(viewStartFileInfo.PhysicalPath);
|
fileProvider.DeleteFile(viewStartFileInfo.PhysicalPath);
|
||||||
var actual2 = cache.GetOrAdd(fileInfo,
|
var actual2 = cache.GetOrAdd(fileInfo,
|
||||||
compile: _ => CompilationResult.Successful(expectedType));
|
compile: _ => CompilationResult.Successful(expectedType));
|
||||||
|
|
||||||
|
|
@ -387,10 +387,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
RelativePath = fileInfo.PhysicalPath,
|
RelativePath = fileInfo.PhysicalPath,
|
||||||
};
|
};
|
||||||
|
|
||||||
var fileSystem = new TestFileSystem();
|
var fileProvider = new TestFileProvider();
|
||||||
fileSystem.AddFile(viewStartRazorFileInfo.RelativePath, viewStartFileInfo);
|
fileProvider.AddFile(viewStartRazorFileInfo.RelativePath, viewStartFileInfo);
|
||||||
var viewCollection = new ViewCollection();
|
var viewCollection = new ViewCollection();
|
||||||
var cache = new CompilerCache(new[] { viewCollection }, fileSystem);
|
var cache = new CompilerCache(new[] { viewCollection }, fileProvider);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = cache.GetOrAdd(runtimeFileInfo,
|
var actual = cache.GetOrAdd(runtimeFileInfo,
|
||||||
|
|
@ -405,7 +405,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var lastModified = DateTime.UtcNow;
|
var lastModified = DateTime.UtcNow;
|
||||||
var cache = new CompilerCache(Enumerable.Empty<RazorFileInfoCollection>(), new TestFileSystem());
|
var cache = new CompilerCache(Enumerable.Empty<RazorFileInfoCollection>(), new TestFileProvider());
|
||||||
var fileInfo = new TestFileInfo
|
var fileInfo = new TestFileInfo
|
||||||
{
|
{
|
||||||
PhysicalPath = "test",
|
PhysicalPath = "test",
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.Framework.OptionsModel;
|
using Microsoft.Framework.OptionsModel;
|
||||||
using Microsoft.Framework.Expiration.Interfaces;
|
using Microsoft.Framework.Expiration.Interfaces;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
@ -11,11 +11,11 @@ using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
public class DefaultRazorFileSystemCacheTest
|
public class DefaultRazorFileProviderCacheTest
|
||||||
{
|
{
|
||||||
private const string FileName = "myView.cshtml";
|
private const string FileName = "myView.cshtml";
|
||||||
|
|
||||||
public DummyFileSystem TestFileSystem { get; } = new DummyFileSystem();
|
public DummyFileProvider TestFileProvider { get; } = new DummyFileProvider();
|
||||||
|
|
||||||
public IOptions<RazorViewEngineOptions> OptionsAccessor
|
public IOptions<RazorViewEngineOptions> OptionsAccessor
|
||||||
{
|
{
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
{
|
{
|
||||||
var options = new RazorViewEngineOptions
|
var options = new RazorViewEngineOptions
|
||||||
{
|
{
|
||||||
FileSystem = TestFileSystem
|
FileProvider = TestFileProvider
|
||||||
};
|
};
|
||||||
|
|
||||||
var mock = new Mock<IOptions<RazorViewEngineOptions>>(MockBehavior.Strict);
|
var mock = new Mock<IOptions<RazorViewEngineOptions>>(MockBehavior.Strict);
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
LastModified = DateTime.Now,
|
LastModified = DateTime.Now,
|
||||||
};
|
};
|
||||||
|
|
||||||
TestFileSystem.AddFile(fileInfo);
|
TestFileProvider.AddFile(fileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Sleep(ControllableExpiringFileInfoCache cache, int offsetMilliseconds)
|
public void Sleep(ControllableExpiringFileInfoCache cache, int offsetMilliseconds)
|
||||||
|
|
@ -309,33 +309,33 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetDirectoryInfo_PassesThroughToUnderlyingFileSystem()
|
public void GetDirectoryInfo_PassesThroughToUnderlyingFileProvider()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var fileSystem = new Mock<IFileSystem>();
|
var fileProvider = new Mock<IFileProvider>();
|
||||||
var expected = Mock.Of<IDirectoryContents>();
|
var expected = Mock.Of<IDirectoryContents>();
|
||||||
fileSystem.Setup(f => f.GetDirectoryContents("/test-path"))
|
fileProvider.Setup(f => f.GetDirectoryContents("/test-path"))
|
||||||
.Returns(expected)
|
.Returns(expected)
|
||||||
.Verifiable();
|
.Verifiable();
|
||||||
var options = new RazorViewEngineOptions
|
var options = new RazorViewEngineOptions
|
||||||
{
|
{
|
||||||
FileSystem = fileSystem.Object
|
FileProvider = fileProvider.Object
|
||||||
};
|
};
|
||||||
var accessor = new Mock<IOptions<RazorViewEngineOptions>>();
|
var accessor = new Mock<IOptions<RazorViewEngineOptions>>();
|
||||||
accessor.SetupGet(a => a.Options)
|
accessor.SetupGet(a => a.Options)
|
||||||
.Returns(options);
|
.Returns(options);
|
||||||
|
|
||||||
var cachedFileSystem = new DefaultRazorFileSystemCache(accessor.Object);
|
var cachedFileProvider = new DefaultRazorFileProviderCache(accessor.Object);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = cachedFileSystem.GetDirectoryContents("/test-path");
|
var result = cachedFileProvider.GetDirectoryContents("/test-path");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Same(expected, result);
|
Assert.Same(expected, result);
|
||||||
fileSystem.Verify();
|
fileProvider.Verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ControllableExpiringFileInfoCache : DefaultRazorFileSystemCache
|
public class ControllableExpiringFileInfoCache : DefaultRazorFileProviderCache
|
||||||
{
|
{
|
||||||
public ControllableExpiringFileInfoCache(IOptions<RazorViewEngineOptions> optionsAccessor)
|
public ControllableExpiringFileInfoCache(IOptions<RazorViewEngineOptions> optionsAccessor)
|
||||||
: base(optionsAccessor)
|
: base(optionsAccessor)
|
||||||
|
|
@ -367,7 +367,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
_internalUtcNow = UtcNow.AddMilliseconds(milliSeconds);
|
_internalUtcNow = UtcNow.AddMilliseconds(milliSeconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class DummyFileSystem : IFileSystem
|
public class DummyFileProvider : IFileProvider
|
||||||
{
|
{
|
||||||
private Dictionary<string, IFileInfo> _fileInfos = new Dictionary<string, IFileInfo>(StringComparer.OrdinalIgnoreCase);
|
private Dictionary<string, IFileInfo> _fileInfos = new Dictionary<string, IFileInfo>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Razor;
|
using Microsoft.AspNet.Razor;
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||||
using Microsoft.AspNet.Razor.Parser;
|
using Microsoft.AspNet.Razor.Parser;
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
public class RazorViewEngineOptionsTest
|
public class RazorViewEngineOptionsTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void FileSystemThrows_IfNullIsAsseigned()
|
public void FileProviderThrows_IfNullIsAsseigned()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var options = new RazorViewEngineOptions();
|
var options = new RazorViewEngineOptions();
|
||||||
|
|
||||||
// Act and Assert
|
// Act and Assert
|
||||||
var ex = Assert.Throws<ArgumentNullException>(() => options.FileSystem = null);
|
var ex = Assert.Throws<ArgumentNullException>(() => options.FileProvider = null);
|
||||||
Assert.Equal("value", ex.ParamName);
|
Assert.Equal("value", ex.ParamName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"code": [
|
"code": [
|
||||||
"**/*.cs",
|
"**/*.cs",
|
||||||
"../Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileSystem.cs",
|
"../Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileProvider.cs",
|
||||||
"../Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileInfo.cs"
|
"../Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileInfo.cs"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Mvc.Razor;
|
using Microsoft.AspNet.Mvc.Razor;
|
||||||
using Microsoft.Framework.Runtime;
|
using Microsoft.Framework.Runtime;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
public class RazorViewEngineOptionsSetupTest
|
public class RazorViewEngineOptionsSetupTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RazorViewEngineOptionsSetup_SetsUpFileSystem()
|
public void RazorViewEngineOptionsSetup_SetsUpFileProvider()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var options = new RazorViewEngineOptions();
|
var options = new RazorViewEngineOptions();
|
||||||
|
|
@ -26,8 +26,8 @@ namespace Microsoft.AspNet.Mvc
|
||||||
optionsSetup.Configure(options);
|
optionsSetup.Configure(options);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(options.FileSystem);
|
Assert.NotNull(options.FileProvider);
|
||||||
Assert.IsType<PhysicalFileSystem>(options.FileSystem);
|
Assert.IsType<PhysicalFileProvider>(options.FileProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.FileSystems;
|
using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Mvc.Razor;
|
using Microsoft.AspNet.Mvc.Razor;
|
||||||
using Microsoft.Framework.DependencyInjection;
|
using Microsoft.Framework.DependencyInjection;
|
||||||
using Microsoft.AspNet.Routing;
|
using Microsoft.AspNet.Routing;
|
||||||
|
|
@ -23,7 +23,7 @@ namespace RazorViewEngineOptionsWebsite
|
||||||
|
|
||||||
services.Configure<RazorViewEngineOptions>(options =>
|
services.Configure<RazorViewEngineOptions>(options =>
|
||||||
{
|
{
|
||||||
options.FileSystem = new EmbeddedResourceFileSystem(GetType().GetTypeInfo().Assembly, "EmbeddedResources");
|
options.FileProvider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, "EmbeddedResources");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
RazorViewEngineOptionsWebSite
|
RazorViewEngineOptionsWebSite
|
||||||
===
|
===
|
||||||
|
|
||||||
This web site illustrates use cases for `RazorViewEngineOptions.FileSystem`.
|
This web site illustrates use cases for `RazorViewEngineOptions.FileProvider`.
|
||||||
Loading…
Reference in New Issue