From d51dad95604690f7a4059afa16398a666fa1bbcd Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 20 Jan 2015 12:16:30 -0800 Subject: [PATCH] Handle IFileSystem rename. --- .../ActionResults/FilePathResult.cs | 30 ++++++----- src/Microsoft.AspNet.Mvc.Core/project.json | 2 +- .../Directives/ChunkInheritanceUtility.cs | 14 +++--- .../MvcRazorHost.cs | 16 +++--- .../project.json | 2 +- .../Compilation/CompilationResult.cs | 2 +- .../Compilation/CompilerCache.cs | 16 +++--- ...he.cs => DefaultRazorFileProviderCache.cs} | 22 ++++---- .../Compilation/ICompilationService.cs | 2 +- ...temCache.cs => IRazorFileProviderCache.cs} | 6 +-- .../Compilation/RoslynCompilationService.cs | 2 +- .../RazorViewEngineOptions.cs | 18 +++---- .../Razor/PreCompileViews/RazorPreCompiler.cs | 12 ++--- .../Razor/PreCompileViews/RelativeFileInfo.cs | 2 +- .../Razor/RazorFileHash.cs | 2 +- .../VirtualPathRazorPageFactory.cs | 14 +++--- src/Microsoft.AspNet.Mvc/MvcServices.cs | 6 +-- .../RazorViewEngineOptionsSetup.cs | 4 +- .../ActionResults/FilePathResultTest.cs | 50 +++++++++---------- .../RazorViewEngineOptionsTest.cs | 4 +- .../Directives/ChunkInheritanceUtilityTest.cs | 34 ++++++------- .../InjectChunkVisitorTest.cs | 2 +- .../ModelChunkVisitorTest.cs | 2 +- .../MvcRazorHostTest.cs | 18 +++---- .../TestFileInfo.cs | 2 +- ...{TestFileSystem.cs => TestFileProvider.cs} | 4 +- .../ViewStartUtilityTest.cs | 10 ++-- .../Compilation/CompilationResultTest.cs | 2 +- .../Compilation/CompilerCacheTest.cs | 44 ++++++++-------- ...s => DefaultRazorFileProviderCacheTest.cs} | 28 +++++------ .../RazorCompilationServiceTest.cs | 2 +- .../RazorViewEngineOptionsTest.cs | 4 +- .../project.json | 2 +- .../RazorViewEngineOptionsSetupTest.cs | 8 +-- .../RazorViewEngineOptionsWebsite/Startup.cs | 4 +- .../wwwroot/readme.md | 2 +- 36 files changed, 196 insertions(+), 198 deletions(-) rename src/Microsoft.AspNet.Mvc.Razor/Compilation/{DefaultRazorFileSystemCache.cs => DefaultRazorFileProviderCache.cs} (76%) rename src/Microsoft.AspNet.Mvc.Razor/Compilation/{IRazorFileSystemCache.cs => IRazorFileProviderCache.cs} (63%) rename test/Microsoft.AspNet.Mvc.Razor.Host.Test/{TestFileSystem.cs => TestFileProvider.cs} (94%) rename test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/{DefaultRazorFileSystemCacheTest.cs => DefaultRazorFileProviderCacheTest.cs} (93%) diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/FilePathResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/FilePathResult.cs index 4a5e1baabb..4bbf14a121 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/FilePathResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/FilePathResult.cs @@ -5,7 +5,7 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Interfaces; @@ -73,18 +73,18 @@ namespace Microsoft.AspNet.Mvc } /// - /// Gets or sets the used to resolve paths. + /// Gets or sets the used to resolve paths. /// - public IFileSystem FileSystem { get; set; } + public IFileProvider FileProvider { get; set; } /// protected override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation) { var sendFile = response.HttpContext.GetFeature(); - var fileSystem = GetFileSystem(response.HttpContext.RequestServices); + var fileProvider = GetFileProvider(response.HttpContext.RequestServices); - var filePath = ResolveFilePath(fileSystem); + var filePath = ResolveFilePath(fileProvider); 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, // fallback to trying the path directly unless the path starts with '/'. @@ -117,10 +117,10 @@ namespace Microsoft.AspNet.Mvc return path; } - var fileInfo = fileSystem.GetFileInfo(path); + var fileInfo = fileProvider.GetFileInfo(path); 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. return fileInfo.PhysicalPath; } @@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Mvc if (path.StartsWith("~\\", StringComparison.Ordinal)) { // ~\ 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. return path; } @@ -195,19 +195,17 @@ namespace Microsoft.AspNet.Mvc 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(); - FileSystem = new PhysicalFileSystem(hostingEnvironment.WebRoot); + FileProvider = hostingEnvironment.WebRootFileProvider; - return FileSystem; + return FileProvider; } private static async Task CopyStreamToResponse( diff --git a/src/Microsoft.AspNet.Mvc.Core/project.json b/src/Microsoft.AspNet.Mvc.Core/project.json index b63ef2f66c..4f5944b3cc 100644 --- a/src/Microsoft.AspNet.Mvc.Core/project.json +++ b/src/Microsoft.AspNet.Mvc.Core/project.json @@ -5,7 +5,7 @@ "warningsAsErrors": true }, "dependencies": { - "Microsoft.AspNet.FileSystems": "1.0.0-*", + "Microsoft.AspNet.FileProviders": "1.0.0-*", "Microsoft.AspNet.Hosting": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" }, diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs index f2ac93f7e9..3cd5b7bd6b 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkInheritanceUtility.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Parser; @@ -20,21 +20,21 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives { private readonly Dictionary _parsedCodeTrees; private readonly MvcRazorHost _razorHost; - private readonly IFileSystem _fileSystem; + private readonly IFileProvider _fileProvider; private readonly IReadOnlyList _defaultInheritedChunks; /// /// Initializes a new instance of . /// /// The used to parse _ViewStart pages. - /// The filesystem that represents the application. + /// The fileProvider that represents the application. /// Sequence of s inherited by default. public ChunkInheritanceUtility([NotNull] MvcRazorHost razorHost, - [NotNull] IFileSystem fileSystem, + [NotNull] IFileProvider fileProvider, [NotNull] IReadOnlyList defaultInheritedChunks) { _razorHost = razorHost; - _fileSystem = fileSystem; + _fileProvider = fileProvider; _defaultInheritedChunks = defaultInheritedChunks; _parsedCodeTrees = new Dictionary(StringComparer.Ordinal); } @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives /// /// Gets an ordered of parsed for each _ViewStart that /// is applicable to the page located at . The list is ordered so that the - /// for the _ViewStart closest to the in the filesystem + /// for the _ViewStart closest to the in the fileProvider /// appears first. /// /// The path of the page to locate inherited chunks for. @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives } else { - var fileInfo = _fileSystem.GetFileInfo(viewStartPath); + var fileInfo = _fileProvider.GetFileInfo(viewStartPath); if (fileInfo.Exists) { // viewStartPath contains the app-relative path of the ViewStart. diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs index be3b1a43d0..1dc32bdad4 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor.Generator; @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.Razor new InjectChunk("Microsoft.AspNet.Mvc.IUrlHelper", "Url"), }; - private readonly IFileSystem _fileSystem; + private readonly IFileProvider _fileProvider; // CodeGenerationContext.DefaultBaseClass is set to MyBaseType. // This field holds the type name without the generic decoration (MyBaseType) @@ -45,18 +45,18 @@ namespace Microsoft.AspNet.Mvc.Razor /// /// The path to the application base. public MvcRazorHost(string root) : - this(new PhysicalFileSystem(root)) + this(new PhysicalFileProvider(root)) { } #endif /// - /// Initializes a new instance of using the specified . + /// Initializes a new instance of using the specified . /// - /// A rooted at the application base path. - public MvcRazorHost(IFileSystem fileSystem) + /// A rooted at the application base path. + public MvcRazorHost(IFileProvider fileProvider) : base(new CSharpRazorCodeLanguage()) { - _fileSystem = fileSystem; + _fileProvider = fileProvider; _baseType = BaseType; TagHelperDescriptorResolver = new TagHelperDescriptorResolver(); @@ -164,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.Razor if (_chunkInheritanceUtility == null) { // 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; diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/project.json b/src/Microsoft.AspNet.Mvc.Razor.Host/project.json index 0b7ef3cc78..43986a8885 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/project.json +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/project.json @@ -5,7 +5,7 @@ "warningsAsErrors": true }, "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.Razor.Runtime": "4.0.0-*" }, diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilationResult.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilationResult.cs index 85dab4a29b..08b6f00b9e 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilationResult.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilationResult.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs index c4a269d1bc..0035ec8a48 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs @@ -6,7 +6,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; namespace Microsoft.AspNet.Mvc.Razor { @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Razor public class CompilerCache : ICompilerCache { private readonly ConcurrentDictionary _cache; - private readonly IFileSystem _fileSystem; + private readonly IFileProvider _fileProvider; /// /// Initializes a new instance of populated with precompiled views @@ -24,18 +24,18 @@ namespace Microsoft.AspNet.Mvc.Razor /// An representing the assemblies /// used to search for pre-compiled views. /// - /// An instance that represents the application's + /// An instance that represents the application's /// file system. /// - public CompilerCache(IAssemblyProvider provider, IRazorFileSystemCache fileSystem) - : this(GetFileInfos(provider.CandidateAssemblies), fileSystem) + public CompilerCache(IAssemblyProvider provider, IRazorFileProviderCache fileProvider) + : this(GetFileInfos(provider.CandidateAssemblies), fileProvider) { } // Internal for unit testing - internal CompilerCache(IEnumerable viewCollections, IFileSystem fileSystem) + internal CompilerCache(IEnumerable viewCollections, IFileProvider fileProvider) { - _fileSystem = fileSystem; + _fileProvider = fileProvider; _cache = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); foreach (var viewCollection in viewCollections) @@ -184,7 +184,7 @@ namespace Microsoft.AspNet.Mvc.Razor var viewStartLocations = ViewStartUtility.GetViewStartLocations(relativePath); foreach (var viewStartLocation in viewStartLocations) { - var viewStartFileInfo = _fileSystem.GetFileInfo(viewStartLocation); + var viewStartFileInfo = _fileProvider.GetFileInfo(viewStartLocation); if (viewStartFileInfo.Exists) { var relativeFileInfo = new RelativeFileInfo(viewStartFileInfo, viewStartLocation); diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/DefaultRazorFileSystemCache.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/DefaultRazorFileProviderCache.cs similarity index 76% rename from src/Microsoft.AspNet.Mvc.Razor/Compilation/DefaultRazorFileSystemCache.cs rename to src/Microsoft.AspNet.Mvc.Razor/Compilation/DefaultRazorFileProviderCache.cs index d03d66def9..3801f4fec7 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/DefaultRazorFileSystemCache.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/DefaultRazorFileProviderCache.cs @@ -3,31 +3,31 @@ using System; using System.Collections.Concurrent; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.Framework.Expiration.Interfaces; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Mvc.Razor { /// - /// Default implementation for the interface that caches - /// the results of . + /// Default implementation for the interface that caches + /// the results of . /// - public class DefaultRazorFileSystemCache : IRazorFileSystemCache + public class DefaultRazorFileProviderCache : IRazorFileProviderCache { private readonly ConcurrentDictionary _fileInfoCache = new ConcurrentDictionary(StringComparer.Ordinal); - private readonly IFileSystem _fileSystem; + private readonly IFileProvider _fileProvider; private readonly TimeSpan _offset; /// - /// Initializes a new instance of . + /// Initializes a new instance of . /// /// Accessor to . - public DefaultRazorFileSystemCache(IOptions optionsAccessor) + public DefaultRazorFileProviderCache(IOptions optionsAccessor) { - _fileSystem = optionsAccessor.Options.FileSystem; + _fileProvider = optionsAccessor.Options.FileProvider; _offset = optionsAccessor.Options.ExpirationBeforeCheckingFilesOnDisk; } @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.Razor /// public IDirectoryContents GetDirectoryContents(string subpath) { - return _fileSystem.GetDirectoryContents(subpath); + return _fileProvider.GetDirectoryContents(subpath); } /// @@ -58,7 +58,7 @@ namespace Microsoft.AspNet.Mvc.Razor } else { - var fileInfo = _fileSystem.GetFileInfo(subpath); + var fileInfo = _fileProvider.GetFileInfo(subpath); expiringFileInfo = new ExpiringFileInfo() { @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.Razor /// public IExpirationTrigger Watch(string filter) { - return _fileSystem.Watch(filter); + return _fileProvider.Watch(filter); } private class ExpiringFileInfo diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/ICompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/ICompilationService.cs index 730ca831a5..24ea983e3d 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/ICompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/ICompilationService.cs @@ -1,7 +1,7 @@ // 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. -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/IRazorFileSystemCache.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/IRazorFileProviderCache.cs similarity index 63% rename from src/Microsoft.AspNet.Mvc.Razor/Compilation/IRazorFileSystemCache.cs rename to src/Microsoft.AspNet.Mvc.Razor/Compilation/IRazorFileProviderCache.cs index 333dfe668c..718f7cf567 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/IRazorFileSystemCache.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/IRazorFileProviderCache.cs @@ -1,15 +1,15 @@ // 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. -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; namespace Microsoft.AspNet.Mvc.Razor { /// - /// An that caches the results of for a + /// An that caches the results of for a /// duration specified by . /// - public interface IRazorFileSystemCache : IFileSystem + public interface IRazorFileProviderCache : IFileProvider { } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs index 943ac3fcda..9dd1acb69b 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs @@ -10,7 +10,7 @@ using System.Linq; using System.Reflection; using System.Reflection.PortableExecutable; using System.Runtime.InteropServices; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Emit; diff --git a/src/Microsoft.AspNet.Mvc.Razor/OptionDescriptors/RazorViewEngineOptions.cs b/src/Microsoft.AspNet.Mvc.Razor/OptionDescriptors/RazorViewEngineOptions.cs index 828390e275..f49f45ecb4 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/OptionDescriptors/RazorViewEngineOptions.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/OptionDescriptors/RazorViewEngineOptions.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Mvc.Razor.OptionDescriptors; namespace Microsoft.AspNet.Mvc.Razor @@ -14,12 +14,12 @@ namespace Microsoft.AspNet.Mvc.Razor public class RazorViewEngineOptions { private TimeSpan _expirationBeforeCheckingFilesOnDisk = TimeSpan.FromSeconds(2); - private IFileSystem _fileSystem; + private IFileProvider _fileProvider; /// /// Gets or sets the that specifies the duration for which results of - /// are cached by . - /// is used to query for file changes during Razor compilation. + /// are cached by . + /// is used to query for file changes during Razor compilation. /// /// /// of or less, means no caching. @@ -53,16 +53,16 @@ namespace Microsoft.AspNet.Mvc.Razor = new List(); /// - /// Gets or sets the used by to locate Razor files on + /// Gets or sets the used by to locate Razor files on /// disk. /// /// - /// At startup, this is initialized to an instance of that is rooted at the + /// At startup, this is initialized to an instance of that is rooted at the /// application root. /// - public IFileSystem FileSystem + public IFileProvider FileProvider { - get { return _fileSystem; } + get { return _fileProvider; } set { @@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Mvc.Razor throw new ArgumentNullException(nameof(value)); } - _fileSystem = value; + _fileProvider = value; } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RazorPreCompiler.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RazorPreCompiler.cs index 4bbe5b90a5..df11e09345 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RazorPreCompiler.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RazorPreCompiler.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.CodeAnalysis; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.DependencyInjection; @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.Razor public class RazorPreCompiler { private readonly IServiceProvider _serviceProvider; - private readonly IFileSystem _fileSystem; + private readonly IFileProvider _fileProvider; public RazorPreCompiler([NotNull] IServiceProvider designTimeServiceProvider, [NotNull] IMemoryCache precompilationCache, @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.Razor [NotNull] CompilationSettings compilationSettings) { _serviceProvider = designTimeServiceProvider; - _fileSystem = optionsAccessor.Options.FileSystem; + _fileProvider = optionsAccessor.Options.FileProvider; CompilationSettings = compilationSettings; PreCompilationCache = precompilationCache; } @@ -120,10 +120,10 @@ namespace Microsoft.AspNet.Mvc.Razor if (entry != null) { - cacheSetContext.AddExpirationTrigger(_fileSystem.Watch(fileInfo.RelativePath)); + cacheSetContext.AddExpirationTrigger(_fileProvider.Watch(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 razorFiles) { - var fileInfos = _fileSystem.GetDirectoryContents(root); + var fileInfos = _fileProvider.GetDirectoryContents(root); foreach (var fileInfo in fileInfos) { diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RelativeFileInfo.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RelativeFileInfo.cs index d0100620da..b0bb2b2b4a 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RelativeFileInfo.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/PreCompileViews/RelativeFileInfo.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorFileHash.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorFileHash.cs index bb752cbb97..9f2176414d 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorFileHash.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorFileHash.cs @@ -4,7 +4,7 @@ using System; using System.IO; using System.Security.Cryptography; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/src/Microsoft.AspNet.Mvc.Razor/VirtualPathRazorPageFactory.cs b/src/Microsoft.AspNet.Mvc.Razor/VirtualPathRazorPageFactory.cs index befa9540ed..a2ba401b34 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/VirtualPathRazorPageFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/VirtualPathRazorPageFactory.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Http; using Microsoft.AspNet.PageExecutionInstrumentation; using Microsoft.Framework.DependencyInjection; @@ -17,19 +17,19 @@ namespace Microsoft.AspNet.Mvc.Razor { private readonly ITypeActivator _activator; private readonly IServiceProvider _serviceProvider; - private readonly IRazorFileSystemCache _fileSystemCache; + private readonly IRazorFileProviderCache _fileProviderCache; private readonly ICompilerCache _compilerCache; private IRazorCompilationService _razorcompilationService; public VirtualPathRazorPageFactory(ITypeActivator typeActivator, IServiceProvider serviceProvider, ICompilerCache compilerCache, - IRazorFileSystemCache fileSystemCache) + IRazorFileProviderCache fileProviderCache) { _activator = typeActivator; _serviceProvider = serviceProvider; _compilerCache = compilerCache; - _fileSystemCache = fileSystemCache; + _fileProviderCache = fileProviderCache; } 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 // 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(); } @@ -53,11 +53,11 @@ namespace Microsoft.AspNet.Mvc.Razor { 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); } - var fileInfo = _fileSystemCache.GetFileInfo(relativePath); + var fileInfo = _fileProviderCache.GetFileInfo(relativePath); if (fileInfo.Exists) { diff --git a/src/Microsoft.AspNet.Mvc/MvcServices.cs b/src/Microsoft.AspNet.Mvc/MvcServices.cs index 1e2b5aa84f..745481bd5b 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServices.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServices.cs @@ -102,13 +102,13 @@ namespace Microsoft.AspNet.Mvc yield return describe.Transient(); // Caches view locations that are valid for the lifetime of the application. yield return describe.Singleton(); - yield return describe.Singleton(); + yield return describe.Singleton(); // The host is designed to be discarded after consumption and is very inexpensive to initialize. yield return describe.Transient(serviceProvider => { - var cachedFileSystem = serviceProvider.GetRequiredService(); - return new MvcRazorHost(cachedFileSystem); + var cachedFileProvider = serviceProvider.GetRequiredService(); + return new MvcRazorHost(cachedFileProvider); }); // Caches compilation artifacts across the lifetime of the application. diff --git a/src/Microsoft.AspNet.Mvc/RazorViewEngineOptionsSetup.cs b/src/Microsoft.AspNet.Mvc/RazorViewEngineOptionsSetup.cs index 281d458406..16b931392e 100644 --- a/src/Microsoft.AspNet.Mvc/RazorViewEngineOptionsSetup.cs +++ b/src/Microsoft.AspNet.Mvc/RazorViewEngineOptionsSetup.cs @@ -1,7 +1,7 @@ // 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. -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Mvc.Razor; using Microsoft.Framework.OptionsModel; using Microsoft.Framework.Runtime; @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc private static void ConfigureRazor(RazorViewEngineOptions razorOptions, IApplicationEnvironment applicationEnvironment) { - razorOptions.FileSystem = new PhysicalFileSystem(applicationEnvironment.ApplicationBasePath); + razorOptions.FileProvider = new PhysicalFileProvider(applicationEnvironment.ApplicationBasePath); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/FilePathResultTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/FilePathResultTest.cs index b84bedfe56..995d8c4a1d 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/FilePathResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/FilePathResultTest.cs @@ -4,7 +4,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.Http.Interfaces; @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc var result = new FilePathResult(path, "text/plain") { - FileSystem = new PhysicalFileSystem(Path.GetFullPath(".")), + FileProvider = new PhysicalFileProvider(Path.GetFullPath(".")), }; var httpContext = new DefaultHttpContext(); @@ -56,15 +56,15 @@ namespace Microsoft.AspNet.Mvc } [Fact] - public async Task ExecuteResultAsync_FallsBackToThePhysicalFileSystem_IfNoFileSystemIsPresent() + public async Task ExecuteResultAsync_FallsBackToThePhysicalFileProvider_IfNoFileProviderIsPresent() { // Arrange var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt"); var result = new FilePathResult(path, "text/plain"); var appEnvironment = new Mock(); - appEnvironment.Setup(app => app.WebRoot) - .Returns(Directory.GetCurrentDirectory()); + appEnvironment.Setup(app => app.WebRootFileProvider) + .Returns(new PhysicalFileProvider(Directory.GetCurrentDirectory())); var httpContext = new DefaultHttpContext(); httpContext.Response.Body = new MemoryStream(); @@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Mvc var result = new FilePathResult(path, "text/plain") { - FileSystem = new PhysicalFileSystem(Path.GetFullPath(".")), + FileProvider = new PhysicalFileProvider(Path.GetFullPath(".")), }; var sendFileMock = new Mock(); @@ -122,10 +122,10 @@ namespace Microsoft.AspNet.Mvc // forward slashes. path = path.Replace('/', '\\'); - // Point the FileSystemRoot to a subfolder + // Point the FileProviderRoot to a subfolder var result = new FilePathResult(path, "text/plain") { - FileSystem = new PhysicalFileSystem(Path.GetFullPath("Utils")), + FileProvider = new PhysicalFileProvider(Path.GetFullPath("Utils")), }; var httpContext = new DefaultHttpContext(); @@ -151,10 +151,10 @@ namespace Microsoft.AspNet.Mvc var path = Path.GetFullPath(Path.Combine(".", "TestFiles", "FilePathResultTestFile.txt")); path = path.Replace(@"\", "/"); - // Point the FileSystemRoot to a subfolder + // Point the FileProviderRoot to a subfolder var result = new FilePathResult(path, "text/plain") { - FileSystem = new PhysicalFileSystem(Path.GetFullPath("Utils")), + FileProvider = new PhysicalFileProvider(Path.GetFullPath("Utils")), }; var httpContext = new DefaultHttpContext(); @@ -203,15 +203,15 @@ namespace Microsoft.AspNet.Mvc public void GetFilePath_Resolves_RelativePaths(string path, string relativePathToFile) { // 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 filePathResult = new FilePathResult(path, "text/plain") { - FileSystem = fileSystem, + FileProvider = fileProvider, }; // Act - var result = filePathResult.ResolveFilePath(fileSystem); + var result = filePathResult.ResolveFilePath(fileProvider); // Assert Assert.Equal(expectedPath, result); @@ -224,15 +224,15 @@ namespace Microsoft.AspNet.Mvc public void GetFilePath_FailsToResolve_InvalidVirtualPaths(string path, string relativePathToFile) { // 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 filePathResult = new FilePathResult(path, "text/plain") { - FileSystem = fileSystem, + FileProvider = fileProvider, }; // Act - var ex = Assert.Throws(() => filePathResult.ResolveFilePath(fileSystem)); + var ex = Assert.Throws(() => filePathResult.ResolveFilePath(fileProvider)); // Assert Assert.Equal("Could not find file: " + path, ex.Message); @@ -271,18 +271,18 @@ namespace Microsoft.AspNet.Mvc { // Arrange - // Point the IFileSystem root to a different subfolder - var fileSystem = new PhysicalFileSystem(Path.GetFullPath("./Utils")); + // Point the IFileProvider root to a different subfolder + var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./Utils")); var filePathResult = new FilePathResult(path, "text/plain") { - FileSystem = fileSystem, + FileProvider = fileProvider, }; var expectedFileName = path.TrimStart('~').Replace('\\', '/'); var expectedMessage = "Could not find file: " + expectedFileName; // Act - var ex = Assert.Throws(() => filePathResult.ResolveFilePath(fileSystem)); + var ex = Assert.Throws(() => filePathResult.ResolveFilePath(fileProvider)); // Assert Assert.Equal(expectedMessage, ex.Message); @@ -322,7 +322,7 @@ namespace Microsoft.AspNet.Mvc // Arrange var fileResult = new FilePathResult(path, "text/plain") { - FileSystem = Mock.Of(), + FileProvider = Mock.Of(), }; // Act @@ -342,7 +342,7 @@ namespace Microsoft.AspNet.Mvc // Arrange var fileResult = new FilePathResult(path, "text/plain") { - FileSystem = Mock.Of(), + FileProvider = Mock.Of(), }; // Act @@ -362,7 +362,7 @@ namespace Microsoft.AspNet.Mvc // Arrange var fileResult = new FilePathResult(path, "text/plain") { - FileSystem = Mock.Of(), + FileProvider = Mock.Of(), }; // Act @@ -382,7 +382,7 @@ namespace Microsoft.AspNet.Mvc // Arrange var fileResult = new FilePathResult(path, "text/plain") { - FileSystem = Mock.Of(), + FileProvider = Mock.Of(), }; // Act @@ -427,7 +427,7 @@ namespace Microsoft.AspNet.Mvc // Arrange var fileResult = new FilePathResult(path, "text/plain") { - FileSystem = Mock.Of(), + FileProvider = Mock.Of(), }; // Act diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewEngineOptionsTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewEngineOptionsTest.cs index 8358e3ce2a..e792016413 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewEngineOptionsTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RazorViewEngineOptionsTest.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests private readonly Action _app = new Startup().Configure; [Fact] - public async Task RazorViewEngine_UsesFileSystemOnViewEngineOptionsToLocateViews() + public async Task RazorViewEngine_UsesFileProviderOnViewEngineOptionsToLocateViews() { // Arrange var expectedMessage = "Hello test-user, this is /RazorViewEngineOptions_Home"; @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests } [Fact] - public async Task RazorViewEngine_UsesFileSystemOnViewEngineOptionsToLocateAreaViews() + public async Task RazorViewEngine_UsesFileProviderOnViewEngineOptionsToLocateAreaViews() { // Arrange var expectedMessage = "Hello admin-user, this is /Restricted/RazorViewEngineOptions_Admin/Login"; diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs index 48ccaa0e84..565918861c 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/ChunkInheritanceUtilityTest.cs @@ -12,11 +12,11 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives public void GetInheritedChunks_ReadsChunksFromViewStartsInPath() { // Arrange - var fileSystem = new TestFileSystem(); - fileSystem.AddFile(@"Views\accounts\_ViewStart.cshtml", "@using AccountModels"); - fileSystem.AddFile(@"Views\Shared\_ViewStart.cshtml", "@inject SharedHelper Shared"); - fileSystem.AddFile(@"Views\home\_ViewStart.cshtml", "@using MyNamespace"); - fileSystem.AddFile(@"Views\_ViewStart.cshtml", + var fileProvider = new TestFileProvider(); + fileProvider.AddFile(@"Views\accounts\_ViewStart.cshtml", "@using AccountModels"); + fileProvider.AddFile(@"Views\Shared\_ViewStart.cshtml", "@inject SharedHelper Shared"); + fileProvider.AddFile(@"Views\home\_ViewStart.cshtml", "@using MyNamespace"); + fileProvider.AddFile(@"Views\_ViewStart.cshtml", @"@inject MyHelper Helper @inherits MyBaseType @@ -30,8 +30,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives new InjectChunk("MyTestHtmlHelper", "Html"), new UsingChunk { Namespace = "AppNamespace.Model" }, }; - var host = new MvcRazorHost(fileSystem); - var utility = new ChunkInheritanceUtility(host, fileSystem, defaultChunks); + var host = new MvcRazorHost(fileProvider); + var utility = new ChunkInheritanceUtility(host, fileProvider, defaultChunks); // Act var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml"); @@ -66,17 +66,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives public void GetInheritedChunks_ReturnsEmptySequenceIfNoViewStartsArePresent() { // Arrange - var fileSystem = new TestFileSystem(); - fileSystem.AddFile(@"_ViewStart.cs", string.Empty); - fileSystem.AddFile(@"Views\_Layout.cshtml", string.Empty); - fileSystem.AddFile(@"Views\home\_not-viewstart.cshtml", string.Empty); - var host = new MvcRazorHost(fileSystem); + var fileProvider = new TestFileProvider(); + fileProvider.AddFile(@"_ViewStart.cs", string.Empty); + fileProvider.AddFile(@"Views\_Layout.cshtml", string.Empty); + fileProvider.AddFile(@"Views\home\_not-viewstart.cshtml", string.Empty); + var host = new MvcRazorHost(fileProvider); var defaultChunks = new Chunk[] { new InjectChunk("MyTestHtmlHelper", "Html"), new UsingChunk { Namespace = "AppNamespace.Model" }, }; - var utility = new ChunkInheritanceUtility(host, fileSystem, defaultChunks); + var utility = new ChunkInheritanceUtility(host, fileProvider, defaultChunks); // Act var codeTrees = utility.GetInheritedCodeTrees(@"Views\home\Index.cshtml"); @@ -89,10 +89,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives public void MergeInheritedChunks_MergesDefaultInheritedChunks() { // Arrange - var fileSystem = new TestFileSystem(); - fileSystem.AddFile(@"Views\_ViewStart.cshtml", + var fileProvider = new TestFileProvider(); + fileProvider.AddFile(@"Views\_ViewStart.cshtml", "@inject DifferentHelper Html"); - var host = new MvcRazorHost(fileSystem); + var host = new MvcRazorHost(fileProvider); var defaultChunks = new Chunk[] { 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(); // Act diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/InjectChunkVisitorTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/InjectChunkVisitorTest.cs index fdc73a475b..61031fa017 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/InjectChunkVisitorTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/InjectChunkVisitorTest.cs @@ -146,7 +146,7 @@ MyType1 private static CodeBuilderContext CreateContext() { return new CodeBuilderContext( - new CodeGeneratorContext(new MvcRazorHost(new TestFileSystem()), + new CodeGeneratorContext(new MvcRazorHost(new TestFileProvider()), "MyClass", "MyNamespace", string.Empty, diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ModelChunkVisitorTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ModelChunkVisitorTest.cs index f19d22ce36..d26bbc74b6 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ModelChunkVisitorTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ModelChunkVisitorTest.cs @@ -102,7 +102,7 @@ Environment.NewLine + private static CodeBuilderContext CreateContext() { return new CodeBuilderContext( - new CodeGeneratorContext(new MvcRazorHost(new TestFileSystem()), + new CodeGeneratorContext(new MvcRazorHost(new TestFileProvider()), "MyClass", "MyNamespace", string.Empty, diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorHostTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorHostTest.cs index 9b17b11561..792c50083e 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorHostTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/MvcRazorHostTest.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Generator.Compiler; @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.Razor public void MvcRazorHost_EnablesInstrumentationByDefault() { // Arrange - var host = new MvcRazorHost(new TestFileSystem()); + var host = new MvcRazorHost(new TestFileProvider()); // Act var instrumented = host.EnableInstrumentation; @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.Razor public void MvcRazorHost_GeneratesTagHelperModelExpressionCode_DesignTime() { // Arrange - var host = new MvcRazorHost(new TestFileSystem()) + var host = new MvcRazorHost(new TestFileProvider()) { DesignTimeMode = true }; @@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.Razor public void MvcRazorHost_ParsesAndGeneratesCodeForBasicScenarios(string scenarioName) { // Arrange - var host = new TestMvcRazorHost(new TestFileSystem()); + var host = new TestMvcRazorHost(new TestFileProvider()); // Act and Assert RunRuntimeTest(host, scenarioName); @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.Razor public void InjectVisitor_GeneratesCorrectLineMappings() { // Arrange - var host = new MvcRazorHost(new TestFileSystem()) + var host = new MvcRazorHost(new TestFileProvider()) { DesignTimeMode = true }; @@ -113,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.Razor public void InjectVisitorWithModel_GeneratesCorrectLineMappings() { // Arrange - var host = new MvcRazorHost(new TestFileSystem()) + var host = new MvcRazorHost(new TestFileProvider()) { DesignTimeMode = true }; @@ -133,7 +133,7 @@ namespace Microsoft.AspNet.Mvc.Razor public void ModelVisitor_GeneratesCorrectLineMappings() { // Arrange - var host = new MvcRazorHost(new TestFileSystem()) + var host = new MvcRazorHost(new TestFileProvider()) { DesignTimeMode = true }; @@ -229,8 +229,8 @@ namespace Microsoft.AspNet.Mvc.Razor /// private class TestMvcRazorHost : MvcRazorHost { - public TestMvcRazorHost(IFileSystem fileSystem) - : base(fileSystem) + public TestMvcRazorHost(IFileProvider fileProvider) + : base(fileProvider) { } public override CodeBuilder DecorateCodeBuilder(CodeBuilder incomingBuilder, CodeBuilderContext context) diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileInfo.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileInfo.cs index b561494fef..c56cb96ed6 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileInfo.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileInfo.cs @@ -4,7 +4,7 @@ using System; using System.IO; using System.Text; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileSystem.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileProvider.cs similarity index 94% rename from test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileSystem.cs rename to test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileProvider.cs index 84dfc25b80..319be33af5 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileSystem.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/TestFileProvider.cs @@ -4,12 +4,12 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.Framework.Expiration.Interfaces; namespace Microsoft.AspNet.Mvc.Razor { - public class TestFileSystem : IFileSystem + public class TestFileProvider : IFileProvider { private readonly Dictionary _lookup = new Dictionary(StringComparer.Ordinal); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ViewStartUtilityTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ViewStartUtilityTest.cs index be00bf8065..ed589da934 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ViewStartUtilityTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/ViewStartUtilityTest.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime.Infrastructure; using Xunit; @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.Razor @"Views\_ViewStart.cshtml", @"_ViewStart.cshtml" }; - var fileSystem = new PhysicalFileSystem(GetTestFileSystemBase()); + var fileProvider = new PhysicalFileProvider(GetTestFileProviderBase()); // Act var result = ViewStartUtility.GetViewStartLocations(inputPath); @@ -116,7 +116,7 @@ namespace Microsoft.AspNet.Mvc.Razor public void GetViewStartLocations_ReturnsEmptySequence_IfViewStartIsAtRoot() { // Arrange - var appBase = GetTestFileSystemBase(); + var appBase = GetTestFileProviderBase(); var viewPath = "_ViewStart.cshtml"; // Act @@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.Razor public void GetViewStartLocations_ReturnsEmptySequence_IfPathIsRooted() { // Arrange - var appBase = GetTestFileSystemBase(); + var appBase = GetTestFileProviderBase(); var absolutePath = Path.Combine(Directory.GetCurrentDirectory(), "Index.cshtml"); // Act @@ -140,7 +140,7 @@ namespace Microsoft.AspNet.Mvc.Razor Assert.Empty(result); } - private static string GetTestFileSystemBase() + private static string GetTestFileProviderBase() { var serviceProvider = CallContextServiceLocator.Locator.ServiceProvider; var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment)); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilationResultTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilationResultTest.cs index 5334f46726..c3e36d28e2 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilationResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilationResultTest.cs @@ -3,7 +3,7 @@ using System.IO; using System.Text; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Moq; using Xunit; diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilerCacheTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilerCacheTest.cs index 5c7e22ddc8..1b3f501d9d 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilerCacheTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilerCacheTest.cs @@ -16,8 +16,8 @@ namespace Microsoft.AspNet.Mvc.Razor public void GetOrAdd_ReturnsCompilationResultFromFactory() { // Arrange - var fileSystem = new TestFileSystem(); - var cache = new CompilerCache(Enumerable.Empty(), fileSystem); + var fileProvider = new TestFileProvider(); + var cache = new CompilerCache(Enumerable.Empty(), fileProvider); var fileInfo = new TestFileInfo { LastModified = DateTime.FromFileTimeUtc(10000) @@ -111,8 +111,8 @@ namespace Microsoft.AspNet.Mvc.Razor var instance = new RuntimeCompileIdentical(); var length = Encoding.UTF8.GetByteCount(instance.Content); var collection = new ViewCollection(); - var fileSystem = new TestFileSystem(); - var cache = new CompilerCache(new[] { new ViewCollection() }, fileSystem); + var fileProvider = new TestFileProvider(); + var cache = new CompilerCache(new[] { new ViewCollection() }, fileProvider); var fileInfo = new TestFileInfo { @@ -153,8 +153,8 @@ namespace Microsoft.AspNet.Mvc.Razor var instance = (View)Activator.CreateInstance(resultViewType); var length = Encoding.UTF8.GetByteCount(instance.Content); var collection = new ViewCollection(); - var fileSystem = new TestFileSystem(); - var cache = new CompilerCache(new[] { new ViewCollection() }, fileSystem); + var fileProvider = new TestFileProvider(); + var cache = new CompilerCache(new[] { new ViewCollection() }, fileProvider); var fileInfo = new TestFileInfo { @@ -189,7 +189,7 @@ namespace Microsoft.AspNet.Mvc.Razor // Arrange var instance = (View)Activator.CreateInstance(typeof(PreCompile)); var length = Encoding.UTF8.GetByteCount(instance.Content); - var fileSystem = new TestFileSystem(); + var fileProvider = new TestFileProvider(); var lastModified = DateTime.UtcNow; @@ -207,7 +207,7 @@ namespace Microsoft.AspNet.Mvc.Razor Content = viewStartContent, LastModified = DateTime.UtcNow }; - fileSystem.AddFile("_ViewStart.cshtml", viewStartFileInfo); + fileProvider.AddFile("_ViewStart.cshtml", viewStartFileInfo); var viewStartRazorFileInfo = new RazorFileInfo { Hash = RazorFileHash.GetHash(GetMemoryStream(viewStartContent)), @@ -219,7 +219,7 @@ namespace Microsoft.AspNet.Mvc.Razor var precompiledViews = new ViewCollection(); precompiledViews.Add(viewStartRazorFileInfo); - var cache = new CompilerCache(new[] { precompiledViews }, fileSystem); + var cache = new CompilerCache(new[] { precompiledViews }, fileProvider); // Act var actual = cache.GetOrAdd(runtimeFileInfo, @@ -235,18 +235,18 @@ namespace Microsoft.AspNet.Mvc.Razor // Arrange var expectedType = typeof(RuntimeCompileDifferent); var lastModified = DateTime.UtcNow; - var fileSystem = new TestFileSystem(); + var fileProvider = new TestFileProvider(); var collection = new ViewCollection(); var precompiledFile = collection.FileInfos[0]; precompiledFile.RelativePath = "Views\\home\\index.cshtml"; - var cache = new CompilerCache(new[] { collection }, fileSystem); + var cache = new CompilerCache(new[] { collection }, fileProvider); var testFile = new TestFileInfo { Content = new PreCompile().Content, LastModified = precompiledFile.LastModified, PhysicalPath = precompiledFile.RelativePath }; - fileSystem.AddFile(precompiledFile.RelativePath, testFile); + fileProvider.AddFile(precompiledFile.RelativePath, testFile); var relativeFile = new RelativeFileInfo(testFile, testFile.PhysicalPath); // Act 1 @@ -257,7 +257,7 @@ namespace Microsoft.AspNet.Mvc.Razor Assert.Equal(typeof(PreCompile), actual1.CompiledType); // Act 2 - fileSystem.AddFile("Views\\_ViewStart.cshtml", ""); + fileProvider.AddFile("Views\\_ViewStart.cshtml", ""); var actual2 = cache.GetOrAdd(relativeFile, compile: _ => CompilationResult.Successful(expectedType)); @@ -271,7 +271,7 @@ namespace Microsoft.AspNet.Mvc.Razor // Arrange var expectedType = typeof(RuntimeCompileDifferent); var lastModified = DateTime.UtcNow; - var fileSystem = new TestFileSystem(); + var fileProvider = new TestFileProvider(); var viewCollection = new ViewCollection(); var precompiledView = viewCollection.FileInfos[0]; @@ -282,7 +282,7 @@ namespace Microsoft.AspNet.Mvc.Razor LastModified = precompiledView.LastModified, PhysicalPath = precompiledView.RelativePath }; - fileSystem.AddFile(viewFileInfo.PhysicalPath, viewFileInfo); + fileProvider.AddFile(viewFileInfo.PhysicalPath, viewFileInfo); var viewStartFileInfo = new TestFileInfo { @@ -298,10 +298,10 @@ namespace Microsoft.AspNet.Mvc.Razor Hash = RazorFileHash.GetHash(viewStartFileInfo), Length = viewStartFileInfo.Length }; - fileSystem.AddFile(viewStartFileInfo.PhysicalPath, viewStartFileInfo); + fileProvider.AddFile(viewStartFileInfo.PhysicalPath, viewStartFileInfo); viewCollection.Add(viewStart); - var cache = new CompilerCache(new[] { viewCollection }, fileSystem); + var cache = new CompilerCache(new[] { viewCollection }, fileProvider); var fileInfo = new RelativeFileInfo(viewFileInfo, viewFileInfo.PhysicalPath); // Act 1 @@ -312,7 +312,7 @@ namespace Microsoft.AspNet.Mvc.Razor Assert.Equal(typeof(PreCompile), actual1.CompiledType); // Act 2 - fileSystem.DeleteFile(viewStartFileInfo.PhysicalPath); + fileProvider.DeleteFile(viewStartFileInfo.PhysicalPath); var actual2 = cache.GetOrAdd(fileInfo, compile: _ => CompilationResult.Successful(expectedType)); @@ -387,10 +387,10 @@ namespace Microsoft.AspNet.Mvc.Razor RelativePath = fileInfo.PhysicalPath, }; - var fileSystem = new TestFileSystem(); - fileSystem.AddFile(viewStartRazorFileInfo.RelativePath, viewStartFileInfo); + var fileProvider = new TestFileProvider(); + fileProvider.AddFile(viewStartRazorFileInfo.RelativePath, viewStartFileInfo); var viewCollection = new ViewCollection(); - var cache = new CompilerCache(new[] { viewCollection }, fileSystem); + var cache = new CompilerCache(new[] { viewCollection }, fileProvider); // Act var actual = cache.GetOrAdd(runtimeFileInfo, @@ -405,7 +405,7 @@ namespace Microsoft.AspNet.Mvc.Razor { // Arrange var lastModified = DateTime.UtcNow; - var cache = new CompilerCache(Enumerable.Empty(), new TestFileSystem()); + var cache = new CompilerCache(Enumerable.Empty(), new TestFileProvider()); var fileInfo = new TestFileInfo { PhysicalPath = "test", diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/DefaultRazorFileSystemCacheTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/DefaultRazorFileProviderCacheTest.cs similarity index 93% rename from test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/DefaultRazorFileSystemCacheTest.cs rename to test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/DefaultRazorFileProviderCacheTest.cs index 3ff4f5ed29..668fc76a50 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/DefaultRazorFileSystemCacheTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/DefaultRazorFileProviderCacheTest.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.Framework.OptionsModel; using Microsoft.Framework.Expiration.Interfaces; using Moq; @@ -11,11 +11,11 @@ using Xunit; namespace Microsoft.AspNet.Mvc.Razor { - public class DefaultRazorFileSystemCacheTest + public class DefaultRazorFileProviderCacheTest { private const string FileName = "myView.cshtml"; - public DummyFileSystem TestFileSystem { get; } = new DummyFileSystem(); + public DummyFileProvider TestFileProvider { get; } = new DummyFileProvider(); public IOptions OptionsAccessor { @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.Razor { var options = new RazorViewEngineOptions { - FileSystem = TestFileSystem + FileProvider = TestFileProvider }; var mock = new Mock>(MockBehavior.Strict); @@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.Razor LastModified = DateTime.Now, }; - TestFileSystem.AddFile(fileInfo); + TestFileProvider.AddFile(fileInfo); } public void Sleep(ControllableExpiringFileInfoCache cache, int offsetMilliseconds) @@ -309,33 +309,33 @@ namespace Microsoft.AspNet.Mvc.Razor } [Fact] - public void GetDirectoryInfo_PassesThroughToUnderlyingFileSystem() + public void GetDirectoryInfo_PassesThroughToUnderlyingFileProvider() { // Arrange - var fileSystem = new Mock(); + var fileProvider = new Mock(); var expected = Mock.Of(); - fileSystem.Setup(f => f.GetDirectoryContents("/test-path")) + fileProvider.Setup(f => f.GetDirectoryContents("/test-path")) .Returns(expected) .Verifiable(); var options = new RazorViewEngineOptions { - FileSystem = fileSystem.Object + FileProvider = fileProvider.Object }; var accessor = new Mock>(); accessor.SetupGet(a => a.Options) .Returns(options); - var cachedFileSystem = new DefaultRazorFileSystemCache(accessor.Object); + var cachedFileProvider = new DefaultRazorFileProviderCache(accessor.Object); // Act - var result = cachedFileSystem.GetDirectoryContents("/test-path"); + var result = cachedFileProvider.GetDirectoryContents("/test-path"); // Assert Assert.Same(expected, result); - fileSystem.Verify(); + fileProvider.Verify(); } - public class ControllableExpiringFileInfoCache : DefaultRazorFileSystemCache + public class ControllableExpiringFileInfoCache : DefaultRazorFileProviderCache { public ControllableExpiringFileInfoCache(IOptions optionsAccessor) : base(optionsAccessor) @@ -367,7 +367,7 @@ namespace Microsoft.AspNet.Mvc.Razor _internalUtcNow = UtcNow.AddMilliseconds(milliSeconds); } } - public class DummyFileSystem : IFileSystem + public class DummyFileProvider : IFileProvider { private Dictionary _fileInfos = new Dictionary(StringComparer.OrdinalIgnoreCase); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RazorCompilationServiceTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RazorCompilationServiceTest.cs index fce9da1018..35ea01eea7 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RazorCompilationServiceTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/RazorCompilationServiceTest.cs @@ -3,7 +3,7 @@ using System.IO; using System.Linq; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Parser; diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineOptionsTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineOptionsTest.cs index 12ffb3abc4..1bd68c30bd 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineOptionsTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineOptionsTest.cs @@ -9,13 +9,13 @@ namespace Microsoft.AspNet.Mvc.Razor public class RazorViewEngineOptionsTest { [Fact] - public void FileSystemThrows_IfNullIsAsseigned() + public void FileProviderThrows_IfNullIsAsseigned() { // Arrange var options = new RazorViewEngineOptions(); // Act and Assert - var ex = Assert.Throws(() => options.FileSystem = null); + var ex = Assert.Throws(() => options.FileProvider = null); Assert.Equal("value", ex.ParamName); } } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/project.json b/test/Microsoft.AspNet.Mvc.Razor.Test/project.json index 3166e67205..707efbf704 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/project.json +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/project.json @@ -1,7 +1,7 @@ { "code": [ "**/*.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" ], "dependencies": { diff --git a/test/Microsoft.AspNet.Mvc.Test/RazorViewEngineOptionsSetupTest.cs b/test/Microsoft.AspNet.Mvc.Test/RazorViewEngineOptionsSetupTest.cs index eba5d78c7f..db14a89498 100644 --- a/test/Microsoft.AspNet.Mvc.Test/RazorViewEngineOptionsSetupTest.cs +++ b/test/Microsoft.AspNet.Mvc.Test/RazorViewEngineOptionsSetupTest.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Mvc.Razor; using Microsoft.Framework.Runtime; using Moq; @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc public class RazorViewEngineOptionsSetupTest { [Fact] - public void RazorViewEngineOptionsSetup_SetsUpFileSystem() + public void RazorViewEngineOptionsSetup_SetsUpFileProvider() { // Arrange var options = new RazorViewEngineOptions(); @@ -26,8 +26,8 @@ namespace Microsoft.AspNet.Mvc optionsSetup.Configure(options); // Assert - Assert.NotNull(options.FileSystem); - Assert.IsType(options.FileSystem); + Assert.NotNull(options.FileProvider); + Assert.IsType(options.FileProvider); } } } \ No newline at end of file diff --git a/test/WebSites/RazorViewEngineOptionsWebsite/Startup.cs b/test/WebSites/RazorViewEngineOptionsWebsite/Startup.cs index 550d6b3894..636c9535d7 100644 --- a/test/WebSites/RazorViewEngineOptionsWebsite/Startup.cs +++ b/test/WebSites/RazorViewEngineOptionsWebsite/Startup.cs @@ -4,7 +4,7 @@ using System.IO; using System.Reflection; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Mvc.Razor; using Microsoft.Framework.DependencyInjection; using Microsoft.AspNet.Routing; @@ -23,7 +23,7 @@ namespace RazorViewEngineOptionsWebsite services.Configure(options => { - options.FileSystem = new EmbeddedResourceFileSystem(GetType().GetTypeInfo().Assembly, "EmbeddedResources"); + options.FileProvider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, "EmbeddedResources"); }); }); diff --git a/test/WebSites/RazorViewEngineOptionsWebsite/wwwroot/readme.md b/test/WebSites/RazorViewEngineOptionsWebsite/wwwroot/readme.md index 9473b97ba9..d54d860d6b 100644 --- a/test/WebSites/RazorViewEngineOptionsWebsite/wwwroot/readme.md +++ b/test/WebSites/RazorViewEngineOptionsWebsite/wwwroot/readme.md @@ -1,4 +1,4 @@ RazorViewEngineOptionsWebSite === -This web site illustrates use cases for `RazorViewEngineOptions.FileSystem`. \ No newline at end of file +This web site illustrates use cases for `RazorViewEngineOptions.FileProvider`. \ No newline at end of file