Merge pull request #2060 from aspnet/dev

Merging changes from dev to stay current
This commit is contained in:
Artak Mkrtchyan 2018-02-12 22:11:42 -08:00 committed by GitHub
commit 924aec8a0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 232 additions and 230 deletions

View File

@ -1,19 +1,17 @@
init: init:
- git config --global core.autocrlf true - git config --global core.autocrlf true
branches: branches:
only: only:
- master - dev
- release - /^release\/.*$/
- dev - /^(.*\/)?ci-.*$/
- /^(.*\/)?ci-.*$/
- /^rel\/.*/
build_script: build_script:
- ps: .\run.ps1 default-build - ps: .\run.ps1 default-build
clone_depth: 1 clone_depth: 1
environment: environment:
global: global:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: 1 DOTNET_CLI_TELEMETRY_OPTOUT: 1
test: off test: 'off'
deploy: off deploy: 'off'
os: Visual Studio 2017 Preview os: Visual Studio 2017 Preview

View File

@ -3,25 +3,25 @@ sudo: required
dist: trusty dist: trusty
env: env:
global: global:
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
- DOTNET_CLI_TELEMETRY_OPTOUT: 1 - DOTNET_CLI_TELEMETRY_OPTOUT: 1
addons: addons:
apt: apt:
packages: packages:
- libunwind8 - libunwind8
mono: none mono: none
os: os:
- linux - linux
- osx - osx
osx_image: xcode8.2 osx_image: xcode8.2
branches: branches:
only: only:
- master - dev
- release - /^release\/.*$/
- dev - /^(.*\/)?ci-.*$/
- /^(.*\/)?ci-.*$/
- /^rel\/.*/
before_install: before_install:
- if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s
/usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
/usr/local/lib/; fi
script: script:
- ./build.sh - ./build.sh

View File

@ -24,10 +24,10 @@ namespace Microsoft.AspNetCore.Razor.Performance
var engine = RazorEngine.Create(b => { RazorExtensions.Register(b); }); var engine = RazorEngine.Create(b => { RazorExtensions.Register(b); });
var project = RazorProject.Create(root.FullName); var fileSystem = RazorProjectFileSystem.Create(root.FullName);
DesignTimeTemplateEngine = new MvcRazorTemplateEngine(RazorEngine.CreateDesignTime(b => { RazorExtensions.Register(b); }), project); DesignTimeTemplateEngine = new MvcRazorTemplateEngine(RazorEngine.CreateDesignTime(b => { RazorExtensions.Register(b); }), fileSystem);
RuntimeTemplateEngine = new MvcRazorTemplateEngine(RazorEngine.Create(b => { RazorExtensions.Register(b); }), project); RuntimeTemplateEngine = new MvcRazorTemplateEngine(RazorEngine.Create(b => { RazorExtensions.Register(b); }), fileSystem);
var codeDocument = RuntimeTemplateEngine.CreateCodeDocument(Path.Combine(root.FullName, "MSN.cshtml")); var codeDocument = RuntimeTemplateEngine.CreateCodeDocument(Path.Combine(root.FullName, "MSN.cshtml"));

View File

@ -4,20 +4,20 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="Package Versions"> <PropertyGroup Label="Package Versions">
<BenchmarkDotNetPackageVersion>0.10.11</BenchmarkDotNetPackageVersion> <BenchmarkDotNetPackageVersion>0.10.11</BenchmarkDotNetPackageVersion>
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview2-15692</InternalAspNetCoreSdkPackageVersion> <InternalAspNetCoreSdkPackageVersion>2.1.0-preview2-15698</InternalAspNetCoreSdkPackageVersion>
<MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>2.1.0-preview2-28215</MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion> <MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>2.1.0-preview2-30077</MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>
<MicrosoftAspNetCoreHtmlAbstractionsPackageVersion>2.1.0-preview2-28215</MicrosoftAspNetCoreHtmlAbstractionsPackageVersion> <MicrosoftAspNetCoreHtmlAbstractionsPackageVersion>2.1.0-preview2-30077</MicrosoftAspNetCoreHtmlAbstractionsPackageVersion>
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-28215</MicrosoftAspNetCoreTestingPackageVersion> <MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30077</MicrosoftAspNetCoreTestingPackageVersion>
<MicrosoftBuildFrameworkPackageVersion>15.3.409</MicrosoftBuildFrameworkPackageVersion> <MicrosoftBuildFrameworkPackageVersion>15.3.409</MicrosoftBuildFrameworkPackageVersion>
<MicrosoftBuildPackageVersion>15.3.409</MicrosoftBuildPackageVersion> <MicrosoftBuildPackageVersion>15.3.409</MicrosoftBuildPackageVersion>
<MicrosoftBuildUtilitiesCorePackageVersion>15.3.409</MicrosoftBuildUtilitiesCorePackageVersion> <MicrosoftBuildUtilitiesCorePackageVersion>15.3.409</MicrosoftBuildUtilitiesCorePackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>2.6.1</MicrosoftCodeAnalysisCommonPackageVersion> <MicrosoftCodeAnalysisCommonPackageVersion>2.6.1</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>2.6.1</MicrosoftCodeAnalysisCSharpPackageVersion> <MicrosoftCodeAnalysisCSharpPackageVersion>2.6.1</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.1.0-preview2-28215</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion> <MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.1.0-preview2-30077</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>
<MicrosoftExtensionsCopyOnWriteDictionarySourcesPackageVersion>2.1.0-preview2-28215</MicrosoftExtensionsCopyOnWriteDictionarySourcesPackageVersion> <MicrosoftExtensionsCopyOnWriteDictionarySourcesPackageVersion>2.1.0-preview2-30077</MicrosoftExtensionsCopyOnWriteDictionarySourcesPackageVersion>
<MicrosoftExtensionsDependencyModelPackageVersion>2.1.0-preview2-25711-01</MicrosoftExtensionsDependencyModelPackageVersion> <MicrosoftExtensionsDependencyModelPackageVersion>2.1.0-preview2-25711-01</MicrosoftExtensionsDependencyModelPackageVersion>
<MicrosoftExtensionsHashCodeCombinerSourcesPackageVersion>2.1.0-preview2-28215</MicrosoftExtensionsHashCodeCombinerSourcesPackageVersion> <MicrosoftExtensionsHashCodeCombinerSourcesPackageVersion>2.1.0-preview2-30077</MicrosoftExtensionsHashCodeCombinerSourcesPackageVersion>
<MicrosoftExtensionsWebEncodersPackageVersion>2.1.0-preview2-28215</MicrosoftExtensionsWebEncodersPackageVersion> <MicrosoftExtensionsWebEncodersPackageVersion>2.1.0-preview2-30077</MicrosoftExtensionsWebEncodersPackageVersion>
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion> <MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26130-04</MicrosoftNETCoreApp21PackageVersion> <MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26130-04</MicrosoftNETCoreApp21PackageVersion>
<MicrosoftNETTestSdkPackageVersion>15.3.0</MicrosoftNETTestSdkPackageVersion> <MicrosoftNETTestSdkPackageVersion>15.3.0</MicrosoftNETTestSdkPackageVersion>
@ -39,7 +39,7 @@
<MonoAddinsPackageVersion>1.3.7</MonoAddinsPackageVersion> <MonoAddinsPackageVersion>1.3.7</MonoAddinsPackageVersion>
<MonoDevelopSdkPackageVersion>1.0.1</MonoDevelopSdkPackageVersion> <MonoDevelopSdkPackageVersion>1.0.1</MonoDevelopSdkPackageVersion>
<MoqPackageVersion>4.7.49</MoqPackageVersion> <MoqPackageVersion>4.7.49</MoqPackageVersion>
<NETStandard20PackageVersion>2.0.0</NETStandard20PackageVersion> <NETStandardLibrary20PackageVersion>2.0.1</NETStandardLibrary20PackageVersion>
<NewtonsoftJsonPackageVersion>10.0.1</NewtonsoftJsonPackageVersion> <NewtonsoftJsonPackageVersion>10.0.1</NewtonsoftJsonPackageVersion>
<StreamJsonRpcPackageVersion>1.1.92</StreamJsonRpcPackageVersion> <StreamJsonRpcPackageVersion>1.1.92</StreamJsonRpcPackageVersion>
<SystemDiagnosticsDiagnosticSourcePackageVersion>4.5.0-preview2-26130-01</SystemDiagnosticsDiagnosticSourcePackageVersion> <SystemDiagnosticsDiagnosticSourcePackageVersion>4.5.0-preview2-26130-01</SystemDiagnosticsDiagnosticSourcePackageVersion>
@ -56,8 +56,8 @@
<VSIX_MicrosoftVisualStudioLanguageServicesRazorRemoteClientPackageVersion>2.7.0-beta3-62512-06</VSIX_MicrosoftVisualStudioLanguageServicesRazorRemoteClientPackageVersion> <VSIX_MicrosoftVisualStudioLanguageServicesRazorRemoteClientPackageVersion>2.7.0-beta3-62512-06</VSIX_MicrosoftVisualStudioLanguageServicesRazorRemoteClientPackageVersion>
<XunitAnalyzersPackageVersion>0.8.0</XunitAnalyzersPackageVersion> <XunitAnalyzersPackageVersion>0.8.0</XunitAnalyzersPackageVersion>
<XunitPackageVersion>2.3.1</XunitPackageVersion> <XunitPackageVersion>2.3.1</XunitPackageVersion>
<XunitRunnerVisualStudioPackageVersion>2.3.1</XunitRunnerVisualStudioPackageVersion> <XunitRunnerVisualStudioPackageVersion>2.4.0-beta.1.build3945</XunitRunnerVisualStudioPackageVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(DotNetPackageVersionPropsPath)" Condition=" '$(DotNetPackageVersionPropsPath)' != '' " /> <Import Project="$(DotNetPackageVersionPropsPath)" Condition=" '$(DotNetPackageVersionPropsPath)' != '' " />
</Project> </Project>

View File

@ -1,2 +1,2 @@
version:2.1.0-preview2-15696 version:2.1.0-preview2-15698
commithash:85ae1301d1a2ff19aab6837cc657699ccca719b5 commithash:7216e5068cb1957e09d45fcbe58a744dd5c2de73

View File

@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework' AND '$(OutputType)'=='library'"> <ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework' AND '$(OutputType)'=='library'">
<PackageReference Include="NETStandard.Library" Version="$(NETStandard20PackageVersion)" /> <PackageReference Include="NETStandard.Library" Version="$(NETStandardLibrary20PackageVersion)" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -14,18 +14,18 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
{ {
private const string ImportsFileName = "_ViewImports.cshtml"; private const string ImportsFileName = "_ViewImports.cshtml";
public IReadOnlyList<RazorSourceDocument> GetImports(string sourceFilePath) public IReadOnlyList<RazorSourceDocument> GetImports(RazorProjectItem projectItem)
{ {
if (string.IsNullOrEmpty(sourceFilePath)) if (projectItem == null)
{ {
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpy, nameof(sourceFilePath)); throw new ArgumentNullException(nameof(projectItem));
} }
var imports = new List<RazorSourceDocument>(); var imports = new List<RazorSourceDocument>();
AddDefaultDirectivesImport(imports); AddDefaultDirectivesImport(imports);
// We add hierarchical imports second so any default directive imports can be overridden. // We add hierarchical imports second so any default directive imports can be overridden.
AddHierarchicalImports(sourceFilePath, imports); AddHierarchicalImports(projectItem, imports);
return imports; return imports;
} }
@ -58,10 +58,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
} }
// Internal for testing // Internal for testing
internal void AddHierarchicalImports(string sourceFilePath, List<RazorSourceDocument> imports) internal void AddHierarchicalImports(RazorProjectItem projectItem, List<RazorSourceDocument> imports)
{ {
// We want items in descending order. FindHierarchicalItems returns items in ascending order. // We want items in descending order. FindHierarchicalItems returns items in ascending order.
var importProjectItems = ProjectEngine.FileSystem.FindHierarchicalItems(sourceFilePath, ImportsFileName).Reverse(); var importProjectItems = ProjectEngine.FileSystem.FindHierarchicalItems(projectItem.FilePath, ImportsFileName).Reverse();
foreach (var importProjectItem in importProjectItems) foreach (var importProjectItem in importProjectItems)
{ {
RazorSourceDocument importSourceDocument; RazorSourceDocument importSourceDocument;

View File

@ -14,18 +14,18 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
private const string ImportsFileName = "_ViewImports.cshtml"; private const string ImportsFileName = "_ViewImports.cshtml";
public IReadOnlyList<RazorSourceDocument> GetImports(string sourceFilePath) public IReadOnlyList<RazorSourceDocument> GetImports(RazorProjectItem projectItem)
{ {
if (string.IsNullOrEmpty(sourceFilePath)) if (projectItem == null)
{ {
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpy, nameof(sourceFilePath)); throw new ArgumentNullException(nameof(projectItem));
} }
var imports = new List<RazorSourceDocument>(); var imports = new List<RazorSourceDocument>();
AddDefaultDirectivesImport(imports); AddDefaultDirectivesImport(imports);
// We add hierarchical imports second so any default directive imports can be overridden. // We add hierarchical imports second so any default directive imports can be overridden.
AddHierarchicalImports(sourceFilePath, imports); AddHierarchicalImports(projectItem, imports);
return imports; return imports;
} }
@ -60,10 +60,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
// Internal for testing // Internal for testing
internal void AddHierarchicalImports(string sourceFilePath, List<RazorSourceDocument> imports) internal void AddHierarchicalImports(RazorProjectItem projectItem, List<RazorSourceDocument> imports)
{ {
// We want items in descending order. FindHierarchicalItems returns items in ascending order. // We want items in descending order. FindHierarchicalItems returns items in ascending order.
var importProjectItems = ProjectEngine.FileSystem.FindHierarchicalItems(sourceFilePath, ImportsFileName).Reverse(); var importProjectItems = ProjectEngine.FileSystem.FindHierarchicalItems(projectItem.FilePath, ImportsFileName).Reverse();
foreach (var importProjectItem in importProjectItems) foreach (var importProjectItem in importProjectItems)
{ {
RazorSourceDocument importSourceDocument; RazorSourceDocument importSourceDocument;

View File

@ -8,6 +8,6 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
internal class DefaultRazorImportFeature : RazorProjectEngineFeatureBase, IRazorImportFeature internal class DefaultRazorImportFeature : RazorProjectEngineFeatureBase, IRazorImportFeature
{ {
public IReadOnlyList<RazorSourceDocument> GetImports(string sourceFilePath) => Array.Empty<RazorSourceDocument>(); public IReadOnlyList<RazorSourceDocument> GetImports(RazorProjectItem projectItem) => Array.Empty<RazorSourceDocument>();
} }
} }

View File

@ -45,29 +45,16 @@ namespace Microsoft.AspNetCore.Razor.Language
public override IReadOnlyList<IRazorProjectEngineFeature> Features { get; } public override IReadOnlyList<IRazorProjectEngineFeature> Features { get; }
public override RazorCodeDocument Process(string filePath) public override RazorCodeDocument Process(RazorProjectItem projectItem)
{ {
if (string.IsNullOrEmpty(filePath)) if (projectItem == null)
{ {
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(filePath)); throw new ArgumentNullException(nameof(projectItem));
}
var projectItem = FileSystem.GetItem(filePath);
var sourceDocument = RazorSourceDocument.ReadFrom(projectItem);
var codeDocument = Process(sourceDocument);
return codeDocument;
}
public override RazorCodeDocument Process(RazorSourceDocument sourceDocument)
{
if (sourceDocument == null)
{
throw new ArgumentNullException(nameof(sourceDocument));
} }
var importFeature = GetRequiredFeature<IRazorImportFeature>(); var importFeature = GetRequiredFeature<IRazorImportFeature>();
var imports = importFeature.GetImports(sourceDocument.FilePath); var imports = importFeature.GetImports(projectItem);
var sourceDocument = RazorSourceDocument.ReadFrom(projectItem);
var codeDocument = RazorCodeDocument.Create(sourceDocument, imports); var codeDocument = RazorCodeDocument.Create(sourceDocument, imports);

View File

@ -8,9 +8,9 @@ using System.Linq;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
internal class FileSystemRazorProject : RazorProjectFileSystem internal class DefaultRazorProjectFileSystem : RazorProjectFileSystem
{ {
public FileSystemRazorProject(string root) public DefaultRazorProjectFileSystem(string root)
{ {
if (string.IsNullOrEmpty(root)) if (string.IsNullOrEmpty(root))
{ {
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator
var filePath = "/" + relativePhysicalPath.Replace(Path.DirectorySeparatorChar, '/'); var filePath = "/" + relativePhysicalPath.Replace(Path.DirectorySeparatorChar, '/');
return new FileSystemRazorProjectItem(basePath, filePath, relativePhysicalPath, file); return new DefaultRazorProjectItem(basePath, filePath, relativePhysicalPath, file);
}); });
} }
@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator
var filePath = "/" + relativePhysicalPath.Replace(Path.DirectorySeparatorChar, '/'); var filePath = "/" + relativePhysicalPath.Replace(Path.DirectorySeparatorChar, '/');
return new FileSystemRazorProjectItem("/", filePath, relativePhysicalPath, new FileInfo(absolutePath)); return new DefaultRazorProjectItem("/", filePath, relativePhysicalPath, new FileInfo(absolutePath));
} }
protected override string NormalizeAndEnsureValidPath(string path) protected override string NormalizeAndEnsureValidPath(string path)

View File

@ -5,16 +5,16 @@ using System.IO;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
internal class FileSystemRazorProjectItem : RazorProjectItem internal class DefaultRazorProjectItem : RazorProjectItem
{ {
/// <summary> /// <summary>
/// Initializes a new instance of <see cref="FileSystemRazorProjectItem"/>. /// Initializes a new instance of <see cref="DefaultRazorProjectItem"/>.
/// </summary> /// </summary>
/// <param name="basePath">The base path.</param> /// <param name="basePath">The base path.</param>
/// <param name="relativePhysicalPath">The physical path of the base path.</param> /// <param name="relativePhysicalPath">The physical path of the base path.</param>
/// <param name="filePath">The path.</param> /// <param name="filePath">The path.</param>
/// <param name="file">The <see cref="FileInfo"/>.</param> /// <param name="file">The <see cref="FileInfo"/>.</param>
public FileSystemRazorProjectItem(string basePath, string filePath, string relativePhysicalPath, FileInfo file) public DefaultRazorProjectItem(string basePath, string filePath, string relativePhysicalPath, FileInfo file)
{ {
BasePath = basePath; BasePath = basePath;
FilePath = filePath; FilePath = filePath;

View File

@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
public interface IRazorImportFeature : IRazorProjectEngineFeature public interface IRazorImportFeature : IRazorProjectEngineFeature
{ {
IReadOnlyList<RazorSourceDocument> GetImports(string sourceFilePath); IReadOnlyList<RazorSourceDocument> GetImports(RazorProjectItem projectItem);
} }
} }

View File

@ -129,9 +129,10 @@ namespace Microsoft.AspNetCore.Razor.Language
/// </summary> /// </summary>
/// <param name="rootDirectoryPath">The directory to root the file system at.</param> /// <param name="rootDirectoryPath">The directory to root the file system at.</param>
/// <returns>A <see cref="RazorProject"/></returns> /// <returns>A <see cref="RazorProject"/></returns>
[Obsolete("This method is obsolete and will be removed in a future version. Please use " + nameof(RazorProjectFileSystem) + "." + nameof(RazorProjectFileSystem.Create) + " instead.")]
public static RazorProject Create(string rootDirectoryPath) public static RazorProject Create(string rootDirectoryPath)
{ {
return new FileSystemRazorProject(rootDirectoryPath); return new DefaultRazorProjectFileSystem(rootDirectoryPath);
} }
} }
} }

View File

@ -14,9 +14,7 @@ namespace Microsoft.AspNetCore.Razor.Language
public abstract IReadOnlyList<IRazorProjectEngineFeature> Features { get; } public abstract IReadOnlyList<IRazorProjectEngineFeature> Features { get; }
public abstract RazorCodeDocument Process(string filePath); public abstract RazorCodeDocument Process(RazorProjectItem projectItem);
public abstract RazorCodeDocument Process(RazorSourceDocument sourceDocument);
public static RazorProjectEngine Create(RazorProjectFileSystem fileSystem) => Create(fileSystem, configure: null); public static RazorProjectEngine Create(RazorProjectFileSystem fileSystem) => Create(fileSystem, configure: null);

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
private RazorProjectEngine _projectEngine; private RazorProjectEngine _projectEngine;
public RazorProjectEngine ProjectEngine public virtual RazorProjectEngine ProjectEngine
{ {
get => _projectEngine; get => _projectEngine;
set set

View File

@ -1,18 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. 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 System;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
public abstract class RazorProjectFileSystem : RazorProject public abstract class RazorProjectFileSystem : RazorProject
{ {
/// <summary> /// <summary>
/// Create a Razor project based on a physical file system. /// Create a Razor project file system based off of a root directory.
/// </summary> /// </summary>
/// <param name="rootDirectoryPath">The directory to root the file system at.</param> /// <param name="rootDirectoryPath">The directory to root the file system at.</param>
/// <returns>A <see cref="RazorProject"/></returns> /// <returns>A <see cref="RazorProjectFileSystem"/></returns>
public static new RazorProjectFileSystem Create(string rootDirectoryPath) public new static RazorProjectFileSystem Create(string rootDirectoryPath)
{ {
return new FileSystemRazorProject(rootDirectoryPath); if (string.IsNullOrEmpty(rootDirectoryPath))
{
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(rootDirectoryPath));
}
return new DefaultRazorProjectFileSystem(rootDirectoryPath);
} }
} }
} }

View File

@ -1,14 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. 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 System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
/// <summary> /// <summary>
/// An item in <see cref="RazorProject"/>. /// An item in a <see cref="RazorProjectFileSystem"/>.
/// </summary> /// </summary>
[DebuggerDisplay("{" + nameof(DebuggerToString) + "()}")] [DebuggerDisplay("{" + nameof(DebuggerToString) + "()}")]
public abstract class RazorProjectItem public abstract class RazorProjectItem

View File

@ -10,20 +10,19 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
internal class VirtualRazorProjectFileSystem : RazorProjectFileSystem internal class VirtualRazorProjectFileSystem : RazorProjectFileSystem
{ {
private readonly DirectoryNode Root = new DirectoryNode("/"); private readonly DirectoryNode _root = new DirectoryNode("/");
public override IEnumerable<RazorProjectItem> EnumerateItems(string basePath) public override IEnumerable<RazorProjectItem> EnumerateItems(string basePath)
{ {
basePath = NormalizeAndEnsureValidPath(basePath); basePath = NormalizeAndEnsureValidPath(basePath);
var directory = Root.GetDirectory(basePath); var directory = _root.GetDirectory(basePath);
return directory?.EnumerateItems() ?? Enumerable.Empty<RazorProjectItem>(); return directory?.EnumerateItems() ?? Enumerable.Empty<RazorProjectItem>();
} }
public override RazorProjectItem GetItem(string path) public override RazorProjectItem GetItem(string path)
{ {
path = NormalizeAndEnsureValidPath(path); path = NormalizeAndEnsureValidPath(path);
return Root.GetItem(path) ?? new NotFoundProjectItem(string.Empty, path); return _root.GetItem(path) ?? new NotFoundProjectItem(string.Empty, path);
} }
public void Add(RazorProjectItem projectItem) public void Add(RazorProjectItem projectItem)
@ -34,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
var filePath = NormalizeAndEnsureValidPath(projectItem.FilePath); var filePath = NormalizeAndEnsureValidPath(projectItem.FilePath);
Root.AddFile(new FileNode(filePath, projectItem)); _root.AddFile(new FileNode(filePath, projectItem));
} }
// Internal for testing // Internal for testing

View File

@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Razor.Tools
var project = new VirtualRazorProjectFileSystem(); var project = new VirtualRazorProjectFileSystem();
foreach (var item in inputItems) foreach (var item in inputItems)
{ {
var projectItem = new FileSystemRazorProjectItem( var projectItem = new DefaultRazorProjectItem(
basePath: "/", basePath: "/",
filePath: item.FilePath, filePath: item.FilePath,
relativePhysicalPath: item.RelativePhysicalPath, relativePhysicalPath: item.RelativePhysicalPath,

View File

@ -13,6 +13,7 @@
<ItemGroup> <ItemGroup>
<None Include="Sdk\*" Pack="true" PackagePath="Sdk\" /> <None Include="Sdk\*" Pack="true" PackagePath="Sdk\" />
<None Include="build\**\*" Pack="true" PackagePath="build" /> <None Include="build\**\*" Pack="true" PackagePath="build" />
<None Include="buildMultiTargeting\**\*" Pack="true" PackagePath="buildMultiTargeting" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -30,6 +30,7 @@ Copyright (c) .NET Foundation. All rights reserved.
--> -->
<PropertyGroup> <PropertyGroup>
<PrepareForRazorGenerateDependsOn> <PrepareForRazorGenerateDependsOn>
ResolveRazorConfiguration;
ResolveRazorGenerateInputs; ResolveRazorGenerateInputs;
AssignRazorGenerateTargetPaths; AssignRazorGenerateTargetPaths;
ResolveAssemblyReferenceRazorGenerateInputs; ResolveAssemblyReferenceRazorGenerateInputs;
@ -181,6 +182,23 @@ Copyright (c) .NET Foundation. All rights reserved.
<Target Name="RazorCompile" DependsOnTargets="$(RazorCompileDependsOn)"> <Target Name="RazorCompile" DependsOnTargets="$(RazorCompileDependsOn)">
</Target> </Target>
<!--
Computes the applicable @(ResolvedRazorConfiguration) and @(ResolvedRazorExtension) items that match the project's
configuration.
-->
<Target
Name="ResolveRazorConfiguration"
Condition="'$(RazorDefaultConfiguration)'!=''">
<ItemGroup>
<ResolvedRazorConfiguration Include="@(RazorConfiguration)" Condition="'%(RazorConfiguration.Identity)'=='$(RazorDefaultConfiguration)'" />
</ItemGroup>
<FindInList List="@(RazorExtension)" ItemSpecToFind="@(RazorConfiguration->Metadata('Extensions'))">
<Output TaskParameter="ItemFound" ItemName="ResolvedRazorExtension" />
</FindInList>
</Target>
<!-- <!--
Generates assembly attributes in support for Razor runtime code generation. This is a set of standard Generates assembly attributes in support for Razor runtime code generation. This is a set of standard
metadata attributes (defined in Microsoft.AspNetCore.Razor.Runtime) that capture the build-time metadata attributes (defined in Microsoft.AspNetCore.Razor.Runtime) that capture the build-time
@ -193,19 +211,10 @@ Copyright (c) .NET Foundation. All rights reserved.
it will be unset by default. it will be unset by default.
--> -->
<Target <Target
Name="RazorGetAssemblyAttributes" Name="RazorGetAssemblyAttributes"
AfterTargets="GetAssemblyAttributes" AfterTargets="GetAssemblyAttributes"
Condition="'$(GenerateRazorAssemblyInfo)'=='true' and '$(RazorDefaultConfiguration)'!=''"> Condition="'$(GenerateRazorAssemblyInfo)'=='true' and '$(RazorDefaultConfiguration)'!=''"
DependsOnTargets="ResolveRazorConfiguration">
<ItemGroup>
<_ResolvedRazorConfiguration Include="@(RazorConfiguration)" Condition="'%(RazorConfiguration.Identity)'=='$(RazorDefaultConfiguration)'" />
<_ResolvedRazorExtensionName Include="%(_ResolvedRazorConfiguration.Extensions)"/>
</ItemGroup>
<FindInList List="@(RazorExtension)" ItemSpecToFind="%(_ResolvedRazorExtensionName.Identity)">
<Output TaskParameter="ItemFound" ItemName="_ResolvedRazorExtension" />
</FindInList>
<ItemGroup> <ItemGroup>
<AssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute"> <AssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute">
<_Parameter1>$(RazorLangVersion)</_Parameter1> <_Parameter1>$(RazorLangVersion)</_Parameter1>
@ -213,9 +222,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<AssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute"> <AssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute">
<_Parameter1>$(RazorDefaultConfiguration)</_Parameter1> <_Parameter1>$(RazorDefaultConfiguration)</_Parameter1>
</AssemblyAttribute> </AssemblyAttribute>
<AssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute" Condition="'%(_ResolvedRazorExtension.AssemblyName)'!=''"> <AssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute" Condition="'%(ResolvedRazorExtension.AssemblyName)'!=''">
<_Parameter1>%(_ResolvedRazorExtension.Identity)</_Parameter1> <_Parameter1>%(ResolvedRazorExtension.Identity)</_Parameter1>
<_Parameter2>%(_ResolvedRazorExtension.AssemblyName)</_Parameter2> <_Parameter2>%(ResolvedRazorExtension.AssemblyName)</_Parameter2>
</AssemblyAttribute> </AssemblyAttribute>
</ItemGroup> </ItemGroup>

View File

@ -60,7 +60,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
} }
}); });
var templateEngine = new Mvc1_X.MvcRazorTemplateEngine(engine, RazorProject.Create(projectPath)); var templateEngine = new Mvc1_X.MvcRazorTemplateEngine(engine, RazorProjectFileSystem.Create(projectPath));
templateEngine.Options.ImportsFileName = "_ViewImports.cshtml"; templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
return templateEngine; return templateEngine;
} }
@ -73,7 +73,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
MvcLatest.RazorExtensions.Register(b); MvcLatest.RazorExtensions.Register(b);
}); });
var templateEngine = new MvcLatest.MvcRazorTemplateEngine(engine, RazorProject.Create(projectPath)); var templateEngine = new MvcLatest.MvcRazorTemplateEngine(engine, RazorProjectFileSystem.Create(projectPath));
templateEngine.Options.ImportsFileName = "_ViewImports.cshtml"; templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
return templateEngine; return templateEngine;
} }

View File

@ -73,7 +73,7 @@ Examples:
public static IList<RazorPageGeneratorResult> MainCore(RazorEngine razorEngine, string targetProjectDirectory) public static IList<RazorPageGeneratorResult> MainCore(RazorEngine razorEngine, string targetProjectDirectory)
{ {
var viewDirectories = Directory.EnumerateDirectories(targetProjectDirectory, "Views", SearchOption.AllDirectories); var viewDirectories = Directory.EnumerateDirectories(targetProjectDirectory, "Views", SearchOption.AllDirectories);
var razorProject = RazorProject.Create(targetProjectDirectory); var razorProject = RazorProjectFileSystem.Create(targetProjectDirectory);
var templateEngine = new RazorTemplateEngine(razorEngine, razorProject); var templateEngine = new RazorTemplateEngine(razorEngine, razorProject);
templateEngine.Options.DefaultImports = RazorSourceDocument.Create(@" templateEngine.Options.DefaultImports = RazorSourceDocument.Create(@"
@using System @using System

View File

@ -29,12 +29,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
// Arrange // Arrange
var imports = new List<RazorSourceDocument>(); var imports = new List<RazorSourceDocument>();
var projectItem = new TestRazorProjectItem("/Contact/Index.cshtml");
var testFileSystem = new TestRazorProjectFileSystem(new[] var testFileSystem = new TestRazorProjectFileSystem(new[]
{ {
new TestRazorProjectItem("/Index.cshtml"), new TestRazorProjectItem("/Index.cshtml"),
new TestRazorProjectItem("/_ViewImports.cshtml"), new TestRazorProjectItem("/_ViewImports.cshtml"),
new TestRazorProjectItem("/Contact/_ViewImports.cshtml"), new TestRazorProjectItem("/Contact/_ViewImports.cshtml"),
new TestRazorProjectItem("/Contact/Index.cshtml"), projectItem,
}); });
var mvcImportFeature = new DefaultMvcImportFeature() var mvcImportFeature = new DefaultMvcImportFeature()
{ {
@ -42,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
}; };
// Act // Act
mvcImportFeature.AddHierarchicalImports("/Contact/Index.cshtml", imports); mvcImportFeature.AddHierarchicalImports(projectItem, imports);
// Assert // Assert
Assert.Collection(imports, Assert.Collection(imports,
@ -55,17 +56,15 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
// Arrange // Arrange
var imports = new List<RazorSourceDocument>(); var imports = new List<RazorSourceDocument>();
var testFileSystem = new TestRazorProjectFileSystem(new[] var projectItem = new TestRazorProjectItem("/Pages/Contact/Index.cshtml");
{ var testFileSystem = new TestRazorProjectFileSystem(new[] { projectItem });
new TestRazorProjectItem("/Pages/Contact/Index.cshtml"),
});
var mvcImportFeature = new DefaultMvcImportFeature() var mvcImportFeature = new DefaultMvcImportFeature()
{ {
ProjectEngine = Mock.Of<RazorProjectEngine>(projectEngine => projectEngine.FileSystem == testFileSystem) ProjectEngine = Mock.Of<RazorProjectEngine>(projectEngine => projectEngine.FileSystem == testFileSystem)
}; };
// Act // Act
mvcImportFeature.AddHierarchicalImports("/Pages/Contact/Index.cshtml", imports); mvcImportFeature.AddHierarchicalImports(projectItem, imports);
// Assert // Assert
Assert.Collection(imports, Assert.Collection(imports,

View File

@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
}; };
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine( var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
RazorEngine.Create(), RazorEngine.Create(),
new TestRazorProject()); new TestRazorProjectFileSystem());
// Act // Act
var imports = mvcRazorTemplateEngine.Options.DefaultImports; var imports = mvcRazorTemplateEngine.Options.DefaultImports;
@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
}; };
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine( var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
RazorEngine.Create(), RazorEngine.Create(),
new TestRazorProject()); new TestRazorProjectFileSystem());
// Act // Act
var imports = mvcRazorTemplateEngine.Options.DefaultImports; var imports = mvcRazorTemplateEngine.Options.DefaultImports;
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
// Arrange // Arrange
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine( var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
RazorEngine.Create(), RazorEngine.Create(),
new TestRazorProject()); new TestRazorProjectFileSystem());
// Act // Act
var imports = mvcRazorTemplateEngine.Options.DefaultImports; var imports = mvcRazorTemplateEngine.Options.DefaultImports;

View File

@ -29,12 +29,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
{ {
// Arrange // Arrange
var imports = new List<RazorSourceDocument>(); var imports = new List<RazorSourceDocument>();
var projectItem = new TestRazorProjectItem("/Contact/Index.cshtml");
var testFileSystem = new TestRazorProjectFileSystem(new[] var testFileSystem = new TestRazorProjectFileSystem(new[]
{ {
new TestRazorProjectItem("/Index.cshtml"), new TestRazorProjectItem("/Index.cshtml"),
new TestRazorProjectItem("/_ViewImports.cshtml"), new TestRazorProjectItem("/_ViewImports.cshtml"),
new TestRazorProjectItem("/Contact/_ViewImports.cshtml"), new TestRazorProjectItem("/Contact/_ViewImports.cshtml"),
new TestRazorProjectItem("/Contact/Index.cshtml"), projectItem,
}); });
var mvcImportFeature = new DefaultMvcImportFeature() var mvcImportFeature = new DefaultMvcImportFeature()
{ {
@ -42,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
}; };
// Act // Act
mvcImportFeature.AddHierarchicalImports("/Contact/Index.cshtml", imports); mvcImportFeature.AddHierarchicalImports(projectItem, imports);
// Assert // Assert
Assert.Collection(imports, Assert.Collection(imports,
@ -55,17 +56,15 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
{ {
// Arrange // Arrange
var imports = new List<RazorSourceDocument>(); var imports = new List<RazorSourceDocument>();
var testFileSystem = new TestRazorProjectFileSystem(new[] var projectItem = new TestRazorProjectItem("/Pages/Contact/Index.cshtml");
{ var testFileSystem = new TestRazorProjectFileSystem(new[] { projectItem });
new TestRazorProjectItem("/Pages/Contact/Index.cshtml"),
});
var mvcImportFeature = new DefaultMvcImportFeature() var mvcImportFeature = new DefaultMvcImportFeature()
{ {
ProjectEngine = Mock.Of<RazorProjectEngine>(projectEngine => projectEngine.FileSystem == testFileSystem) ProjectEngine = Mock.Of<RazorProjectEngine>(projectEngine => projectEngine.FileSystem == testFileSystem)
}; };
// Act // Act
mvcImportFeature.AddHierarchicalImports("/Pages/Contact/Index.cshtml", imports); mvcImportFeature.AddHierarchicalImports(projectItem, imports);
// Assert // Assert
Assert.Collection(imports, Assert.Collection(imports,

View File

@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
}; };
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine( var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
RazorEngine.Create(), RazorEngine.Create(),
new TestRazorProject()); new TestRazorProjectFileSystem());
// Act // Act
var imports = mvcRazorTemplateEngine.Options.DefaultImports; var imports = mvcRazorTemplateEngine.Options.DefaultImports;
@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
}; };
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine( var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
RazorEngine.Create(), RazorEngine.Create(),
new TestRazorProject()); new TestRazorProjectFileSystem());
// Act // Act
var imports = mvcRazorTemplateEngine.Options.DefaultImports; var imports = mvcRazorTemplateEngine.Options.DefaultImports;
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
// Arrange // Arrange
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine( var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
RazorEngine.Create(), RazorEngine.Create(),
new TestRazorProject()); new TestRazorProjectFileSystem());
// Act // Act
var imports = mvcRazorTemplateEngine.Options.DefaultImports; var imports = mvcRazorTemplateEngine.Options.DefaultImports;

View File

@ -0,0 +1,34 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
{
public class DesignTimeBuildIntegrationTest : MSBuildIntegrationTestBase
{
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task DesignTimeBuild_DoesNotRunRazorTargets()
{
// Using Compile here instead of CompileDesignTime because the latter is only defined when using
// the VS targets. This is a close enough simulation for an SDK project
var result = await DotnetMSBuild("Compile", "/p:RazorCompileOnBuild=true /p:DesignTimeBuild=true /clp:PerformanceSummary");
Assert.BuildPassed(result);
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.dll");
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.pdb");
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.dll");
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb");
// This target should be part of the design time build.
Assert.Contains("RazorGetAssemblyAttributes", result.Output);
// We don't want to see the expensive Razor targets in the performance summary, since they shouldn't run
// during a design time build.
Assert.DoesNotContain("RazorCoreGenerate", result.Output);
Assert.DoesNotContain("RazorCoreCompile", result.Output);
}
}
}

View File

@ -12,10 +12,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public void Process_GetsImportsFromFeature() public void Process_GetsImportsFromFeature()
{ {
// Arrange // Arrange
var sourceDocument = TestRazorSourceDocument.Create(); var projectItem = new TestRazorProjectItem("Index.cshtml");
var testImport = TestRazorSourceDocument.Create(); var testImport = TestRazorSourceDocument.Create();
var importFeature = new Mock<IRazorImportFeature>(); var importFeature = new Mock<IRazorImportFeature>();
importFeature.Setup(feature => feature.GetImports(It.IsAny<string>())) importFeature.Setup(feature => feature.GetImports(It.IsAny<RazorProjectItem>()))
.Returns(new[] { testImport }); .Returns(new[] { testImport });
var projectEngine = RazorProjectEngine.Create(TestRazorProjectFileSystem.Empty, builder => var projectEngine = RazorProjectEngine.Create(TestRazorProjectFileSystem.Empty, builder =>
{ {
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.Language
}); });
// Act // Act
var codeDocument = projectEngine.Process(sourceDocument); var codeDocument = projectEngine.Process(projectItem);
// Assert // Assert
var import = Assert.Single(codeDocument.Imports); var import = Assert.Single(codeDocument.Imports);
@ -34,11 +34,11 @@ namespace Microsoft.AspNetCore.Razor.Language
public void Process_GeneratesCodeDocumentWithValidCSharpDocument() public void Process_GeneratesCodeDocumentWithValidCSharpDocument()
{ {
// Arrange // Arrange
var sourceDocument = TestRazorSourceDocument.Create(); var projectItem = new TestRazorProjectItem("Index.cshtml");
var projectEngine = RazorProjectEngine.Create(TestRazorProjectFileSystem.Empty); var projectEngine = RazorProjectEngine.Create(TestRazorProjectFileSystem.Empty);
// Act // Act
var codeDocument = projectEngine.Process(sourceDocument); var codeDocument = projectEngine.Process(projectItem);
// Assert // Assert
var csharpDocument = codeDocument.GetCSharpDocument(); var csharpDocument = codeDocument.GetCSharpDocument();

View File

@ -1,29 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Moq;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Language
{
public class DefaultRazorProjectEngineTest
{
[Fact]
public void Process_AsksFileSystemForItems()
{
// Arrange
var razorProjectItem = new TestRazorProjectItem("/some/path.cshtml");
var testFileSystem = new Mock<RazorProjectFileSystem>();
testFileSystem.Setup(fileSystem => fileSystem.GetItem("/some/path.cshtml"))
.Returns(razorProjectItem)
.Verifiable();
var projectEngine = RazorProjectEngine.Create(testFileSystem.Object);
// Act
projectEngine.Process("/some/path.cshtml");
// Assert
testFileSystem.Verify();
}
}
}

View File

@ -8,12 +8,12 @@ using Xunit;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
public class FileSystemRazorProjectTest public class DefaultRazorProjectFileSystemTest
{ {
private static string TestFolder { get; } = Path.Combine( private static string TestFolder { get; } = Path.Combine(
TestProject.GetProjectDirectory(typeof(FileSystemRazorProjectTest)), TestProject.GetProjectDirectory(typeof(DefaultRazorProjectFileSystemTest)),
"TestFiles", "TestFiles",
"FileSystemRazorProject"); "DefaultRazorProjectFileSystem");
[Theory] [Theory]
[InlineData(null)] [InlineData(null)]
@ -21,20 +21,20 @@ namespace Microsoft.AspNetCore.Razor.Language
public void NormalizeAndEnsureValidPath_ThrowsIfPathIsNullOrEmpty(string path) public void NormalizeAndEnsureValidPath_ThrowsIfPathIsNullOrEmpty(string path)
{ {
// Arrange // Arrange
var project = new TestFileSystemRazorProject("C:/some/test/path/root"); var fileSystem = new TestRazorProjectFileSystem("C:/some/test/path/root");
// Act and Assert // Act and Assert
ExceptionAssert.ThrowsArgumentNullOrEmptyString(() => project.NormalizeAndEnsureValidPath(path), "path"); ExceptionAssert.ThrowsArgumentNullOrEmptyString(() => fileSystem.NormalizeAndEnsureValidPath(path), "path");
} }
[Fact] [Fact]
public void NormalizeAndEnsureValidPath_NormalizesToAbsolutePath() public void NormalizeAndEnsureValidPath_NormalizesToAbsolutePath()
{ {
// Arrange // Arrange
var project = new TestFileSystemRazorProject("C:/some/test/path/root"); var fileSystem = new TestRazorProjectFileSystem("C:/some/test/path/root");
// Act // Act
var absolutePath = project.NormalizeAndEnsureValidPath("file.cshtml"); var absolutePath = fileSystem.NormalizeAndEnsureValidPath("file.cshtml");
// Assert // Assert
Assert.Equal("C:/some/test/path/root/file.cshtml", absolutePath); Assert.Equal("C:/some/test/path/root/file.cshtml", absolutePath);
@ -44,10 +44,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public void NormalizeAndEnsureValidPath_NormalizesToAbsolutePathWithoutForwardSlash() public void NormalizeAndEnsureValidPath_NormalizesToAbsolutePathWithoutForwardSlash()
{ {
// Arrange // Arrange
var project = new TestFileSystemRazorProject("C:/some/test/path/root"); var fileSystem = new TestRazorProjectFileSystem("C:/some/test/path/root");
// Act // Act
var absolutePath = project.NormalizeAndEnsureValidPath("/file.cshtml"); var absolutePath = fileSystem.NormalizeAndEnsureValidPath("/file.cshtml");
// Assert // Assert
Assert.Equal("C:/some/test/path/root/file.cshtml", absolutePath); Assert.Equal("C:/some/test/path/root/file.cshtml", absolutePath);
@ -57,10 +57,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public void NormalizeAndEnsureValidPath_NormalizesToForwardSlashes() public void NormalizeAndEnsureValidPath_NormalizesToForwardSlashes()
{ {
// Arrange // Arrange
var project = new TestFileSystemRazorProject(@"C:\some\test\path\root"); var fileSystem = new TestRazorProjectFileSystem(@"C:\some\test\path\root");
// Act // Act
var absolutePath = project.NormalizeAndEnsureValidPath(@"something\file.cshtml"); var absolutePath = fileSystem.NormalizeAndEnsureValidPath(@"something\file.cshtml");
// Assert // Assert
Assert.Equal("C:/some/test/path/root/something/file.cshtml", absolutePath); Assert.Equal("C:/some/test/path/root/something/file.cshtml", absolutePath);
@ -70,10 +70,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public void EnumerateItems_DiscoversAllCshtmlFiles() public void EnumerateItems_DiscoversAllCshtmlFiles()
{ {
// Arrange // Arrange
var fileSystemProject = new FileSystemRazorProject(TestFolder); var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);
// Act // Act
var items = fileSystemProject.EnumerateItems("/"); var items = fileSystem.EnumerateItems("/");
// Assert // Assert
Assert.Collection( Assert.Collection(
@ -130,10 +130,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public void EnumerateItems_DiscoversAllCshtmlFiles_UnderSpecifiedBasePath() public void EnumerateItems_DiscoversAllCshtmlFiles_UnderSpecifiedBasePath()
{ {
// Arrange // Arrange
var fileSystemProject = new FileSystemRazorProject(TestFolder); var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);
// Act // Act
var items = fileSystemProject.EnumerateItems("/Views"); var items = fileSystem.EnumerateItems("/Views");
// Assert // Assert
Assert.Collection( Assert.Collection(
@ -172,10 +172,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public void EnumerateItems_ReturnsEmptySequence_WhenBasePathDoesNotExist() public void EnumerateItems_ReturnsEmptySequence_WhenBasePathDoesNotExist()
{ {
// Arrange // Arrange
var fileSystemProject = new FileSystemRazorProject(TestFolder); var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);
// Act // Act
var items = fileSystemProject.EnumerateItems("/Does-Not-Exist"); var items = fileSystem.EnumerateItems("/Does-Not-Exist");
// Assert // Assert
Assert.Empty(items); Assert.Empty(items);
@ -185,10 +185,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public void FindHierarchicalItems_FindsItemsWithMatchingNames() public void FindHierarchicalItems_FindsItemsWithMatchingNames()
{ {
// Arrange // Arrange
var fileSystemProject = new FileSystemRazorProject(TestFolder); var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);
// Act // Act
var items = fileSystemProject.FindHierarchicalItems("/Views/Home/Index.cshtml", "_ViewImports.cshtml"); var items = fileSystem.FindHierarchicalItems("/Views/Home/Index.cshtml", "_ViewImports.cshtml");
// Assert // Assert
Assert.Collection( Assert.Collection(
@ -224,10 +224,10 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
// Arrange // Arrange
var filePath = "/Views/About/About.cshtml"; var filePath = "/Views/About/About.cshtml";
var fileSystemProject = new FileSystemRazorProject(TestFolder); var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);
// Act // Act
var item = fileSystemProject.GetItem(filePath); var item = fileSystem.GetItem(filePath);
// Assert // Assert
Assert.True(item.Exists); Assert.True(item.Exists);
@ -242,18 +242,18 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
// Arrange // Arrange
var path = "/NotFound.cshtml"; var path = "/NotFound.cshtml";
var fileSystemProject = new FileSystemRazorProject(TestFolder); var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);
// Act // Act
var item = fileSystemProject.GetItem(path); var item = fileSystem.GetItem(path);
// Assert // Assert
Assert.False(item.Exists); Assert.False(item.Exists);
} }
private class TestFileSystemRazorProject : FileSystemRazorProject private class TestRazorProjectFileSystem : DefaultRazorProjectFileSystem
{ {
public TestFileSystemRazorProject(string root) : base(root) public TestRazorProjectFileSystem(string root) : base(root)
{ {
} }

View File

@ -6,21 +6,21 @@ using Xunit;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
public class FileSystemRazorProjectItemTest public class DefaultRazorProjectItemTest
{ {
private static string TestFolder { get; } = Path.Combine( private static string TestFolder { get; } = Path.Combine(
TestProject.GetProjectDirectory(typeof(FileSystemRazorProjectItemTest)), TestProject.GetProjectDirectory(typeof(DefaultRazorProjectItemTest)),
"TestFiles", "TestFiles",
"FileSystemRazorProject"); "DefaultRazorProjectFileSystem");
[Fact] [Fact]
public void FileSystemRazorProjectItem_SetsProperties() public void DefaultRazorProjectItem_SetsProperties()
{ {
// Arrange // Arrange
var fileInfo = new FileInfo(Path.Combine(TestFolder, "Home.cshtml")); var fileInfo = new FileInfo(Path.Combine(TestFolder, "Home.cshtml"));
// Act // Act
var projectItem = new FileSystemRazorProjectItem("/", "/Home.cshtml", "Home.cshtml", fileInfo); var projectItem = new DefaultRazorProjectItem("/", "/Home.cshtml", "Home.cshtml", fileInfo);
// Assert // Assert
Assert.Equal("/Home.cshtml", projectItem.FilePath); Assert.Equal("/Home.cshtml", projectItem.FilePath);
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var fileInfo = new FileInfo(Path.Combine(TestFolder, "Views", "FileDoesNotExist.cshtml")); var fileInfo = new FileInfo(Path.Combine(TestFolder, "Views", "FileDoesNotExist.cshtml"));
// Act // Act
var projectItem = new FileSystemRazorProjectItem("/Views", "/FileDoesNotExist.cshtml", Path.Combine("Views", "FileDoesNotExist.cshtml"), fileInfo); var projectItem = new DefaultRazorProjectItem("/Views", "/FileDoesNotExist.cshtml", Path.Combine("Views", "FileDoesNotExist.cshtml"), fileInfo);
// Assert // Assert
Assert.False(projectItem.Exists); Assert.False(projectItem.Exists);
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
// Arrange // Arrange
var fileInfo = new FileInfo(Path.Combine(TestFolder, "Home.cshtml")); var fileInfo = new FileInfo(Path.Combine(TestFolder, "Home.cshtml"));
var projectItem = new FileSystemRazorProjectItem("/", "/Home.cshtml", "Home.cshtml", fileInfo); var projectItem = new DefaultRazorProjectItem("/", "/Home.cshtml", "Home.cshtml", fileInfo);
// Act // Act
var stream = projectItem.Read(); var stream = projectItem.Read();

View File

@ -12,12 +12,12 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
public void GenerateCodeWithDefaults() public void GenerateCodeWithDefaults()
{ {
// Arrange // Arrange
var project = new FileSystemRazorProject(TestProjectRoot); var fileSystem = new DefaultRazorProjectFileSystem(TestProjectRoot);
var razorEngine = RazorEngine.Create(engine => var razorEngine = RazorEngine.Create(engine =>
{ {
engine.Features.Add(new SuppressChecksumOptionsFeature()); engine.Features.Add(new SuppressChecksumOptionsFeature());
}); });
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem);
// Act // Act
var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml"); var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml");
@ -30,14 +30,14 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
public void GenerateCodeWithBaseType() public void GenerateCodeWithBaseType()
{ {
// Arrange // Arrange
var project = new FileSystemRazorProject(TestProjectRoot); var fileSystem = new DefaultRazorProjectFileSystem(TestProjectRoot);
var razorEngine = RazorEngine.Create(engine => var razorEngine = RazorEngine.Create(engine =>
{ {
engine.Features.Add(new SuppressChecksumOptionsFeature()); engine.Features.Add(new SuppressChecksumOptionsFeature());
engine.SetBaseType("MyBaseType"); engine.SetBaseType("MyBaseType");
}); });
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem);
// Act // Act
var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml"); var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml");
@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
public void GenerateCodeWithConfigureClass() public void GenerateCodeWithConfigureClass()
{ {
// Arrange // Arrange
var project = new FileSystemRazorProject(TestProjectRoot); var fileSystem = new DefaultRazorProjectFileSystem(TestProjectRoot);
var razorEngine = RazorEngine.Create(engine => var razorEngine = RazorEngine.Create(engine =>
{ {
engine.Features.Add(new SuppressChecksumOptionsFeature()); engine.Features.Add(new SuppressChecksumOptionsFeature());
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
@class.BaseType = "CustomBaseType"; @class.BaseType = "CustomBaseType";
}); });
}); });
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem);
// Act // Act
var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml"); var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml");
@ -83,14 +83,14 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
public void GenerateCodeWithSetNamespace() public void GenerateCodeWithSetNamespace()
{ {
// Arrange // Arrange
var project = new FileSystemRazorProject(TestProjectRoot); var fileSystem = new DefaultRazorProjectFileSystem(TestProjectRoot);
var razorEngine = RazorEngine.Create(engine => var razorEngine = RazorEngine.Create(engine =>
{ {
engine.Features.Add(new SuppressChecksumOptionsFeature()); engine.Features.Add(new SuppressChecksumOptionsFeature());
engine.SetNamespace("MyApp.Razor.Views"); engine.SetNamespace("MyApp.Razor.Views");
}); });
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem);
// Act // Act
var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml"); var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml");

View File

@ -15,16 +15,16 @@ namespace Microsoft.AspNetCore.Razor.Language
public void GetImports_CanQueryInformationOnNonExistentFileWithoutImports() public void GetImports_CanQueryInformationOnNonExistentFileWithoutImports()
{ {
// Arrange // Arrange
var project = new TestRazorProject(); var fileSystem = new TestRazorProjectFileSystem();
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project) var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem)
{ {
Options = Options =
{ {
ImportsFileName = "MyImport.cshtml" ImportsFileName = "MyImport.cshtml"
} }
}; };
var projectItemToQuery = project.GetItem("/Views/Home/Index.cshtml"); var projectItemToQuery = fileSystem.GetItem("/Views/Home/Index.cshtml");
// Act // Act
var imports = templateEngine.GetImports(projectItemToQuery); var imports = templateEngine.GetImports(projectItemToQuery);
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Razor.Language
// Arrange // Arrange
var path = "/Views/Home/MyImport.cshtml"; var path = "/Views/Home/MyImport.cshtml";
var projectItem = new TestRazorProjectItem(path); var projectItem = new TestRazorProjectItem(path);
var project = new TestRazorProject(new[] { projectItem }); var project = new TestRazorProjectFileSystem(new[] { projectItem });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project) var templateEngine = new RazorTemplateEngine(razorEngine, project)
{ {
@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Razor.Language
public void GenerateCode_ThrowsIfItemCannotBeFound() public void GenerateCode_ThrowsIfItemCannotBeFound()
{ {
// Arrange // Arrange
var project = new TestRazorProject(new RazorProjectItem[] { }); var project = new TestRazorProjectFileSystem(new RazorProjectItem[] { });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, project);
@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Razor.Language
public void SettingOptions_ThrowsIfValueIsNull() public void SettingOptions_ThrowsIfValueIsNull()
{ {
// Arrange // Arrange
var project = new TestRazorProject(new RazorProjectItem[] { }); var project = new TestRazorProjectFileSystem(new RazorProjectItem[] { });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, project);
@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Razor.Language
// Arrange // Arrange
var path = "/Views/Home/Index.cshtml"; var path = "/Views/Home/Index.cshtml";
var projectItem = new TestRazorProjectItem(path); var projectItem = new TestRazorProjectItem(path);
var project = new TestRazorProject(new[] { projectItem }); var project = new TestRazorProjectFileSystem(new[] { projectItem });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, project);
@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
// Arrange // Arrange
var path = "/Views/Home/Index.cshtml"; var path = "/Views/Home/Index.cshtml";
var project = new TestRazorProject(new RazorProjectItem[] { }); var project = new TestRazorProjectFileSystem(new RazorProjectItem[] { });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, project);
@ -125,7 +125,7 @@ namespace Microsoft.AspNetCore.Razor.Language
// Arrange // Arrange
var path = "/Views/Home/Index.cshtml"; var path = "/Views/Home/Index.cshtml";
var projectItem = new TestRazorProjectItem(path); var projectItem = new TestRazorProjectItem(path);
var project = new TestRazorProject(new[] { projectItem }); var project = new TestRazorProjectFileSystem(new[] { projectItem });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, project);
@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Razor.Language
// Arrange // Arrange
var path = "/Views/Home/Index.cshtml"; var path = "/Views/Home/Index.cshtml";
var projectItem = new TestRazorProjectItem(path); var projectItem = new TestRazorProjectItem(path);
var project = new TestRazorProject(new[] { projectItem }); var project = new TestRazorProjectFileSystem(new[] { projectItem });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project); var templateEngine = new RazorTemplateEngine(razorEngine, project);
@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
// Arrange // Arrange
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml"); var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
var project = new TestRazorProject(new[] { projectItem }); var project = new TestRazorProjectFileSystem(new[] { projectItem });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project) var templateEngine = new RazorTemplateEngine(razorEngine, project)
{ {
@ -192,7 +192,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml"); var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
var import1 = new TestRazorProjectItem("/MyImport.cshtml"); var import1 = new TestRazorProjectItem("/MyImport.cshtml");
var import2 = new TestRazorProjectItem("/Views/Home/MyImport.cshtml"); var import2 = new TestRazorProjectItem("/Views/Home/MyImport.cshtml");
var project = new TestRazorProject(new[] { import1, import2, projectItem }); var project = new TestRazorProjectFileSystem(new[] { import1, import2, projectItem });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project) var templateEngine = new RazorTemplateEngine(razorEngine, project)
{ {
@ -218,7 +218,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml"); var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
var import1 = new TestRazorProjectItem("/MyImport.cshtml"); var import1 = new TestRazorProjectItem("/MyImport.cshtml");
var import2 = new TestRazorProjectItem("/Views/Home/MyImport.cshtml"); var import2 = new TestRazorProjectItem("/Views/Home/MyImport.cshtml");
var project = new TestRazorProject(new[] { import1, import2, projectItem }); var project = new TestRazorProjectFileSystem(new[] { import1, import2, projectItem });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var defaultImport = RazorSourceDocument.ReadFrom(new MemoryStream(), "Default.cshtml"); var defaultImport = RazorSourceDocument.ReadFrom(new MemoryStream(), "Default.cshtml");
var templateEngine = new RazorTemplateEngine(razorEngine, project) var templateEngine = new RazorTemplateEngine(razorEngine, project)
@ -245,7 +245,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
// Arrange // Arrange
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml"); var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
var project = new TestRazorProject(new[] { projectItem }); var project = new TestRazorProjectFileSystem(new[] { projectItem });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var defaultImport = RazorSourceDocument.ReadFrom(new MemoryStream(), "Default.cshtml"); var defaultImport = RazorSourceDocument.ReadFrom(new MemoryStream(), "Default.cshtml");
var templateEngine = new RazorTemplateEngine(razorEngine, project) var templateEngine = new RazorTemplateEngine(razorEngine, project)
@ -269,7 +269,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
// Arrange // Arrange
var expected = new[] { "/Views/Home/MyImport.cshtml", "/Views/MyImport.cshtml", "/MyImport.cshtml" }; var expected = new[] { "/Views/Home/MyImport.cshtml", "/Views/MyImport.cshtml", "/MyImport.cshtml" };
var project = new TestRazorProject(); var project = new TestRazorProjectFileSystem();
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project) var templateEngine = new RazorTemplateEngine(razorEngine, project)
{ {
@ -293,9 +293,9 @@ namespace Microsoft.AspNetCore.Razor.Language
// Arrange // Arrange
var expected = new[] { "/Views/Home/MyImport.cshtml", "/Views/MyImport.cshtml", "/MyImport.cshtml" }; var expected = new[] { "/Views/Home/MyImport.cshtml", "/Views/MyImport.cshtml", "/MyImport.cshtml" };
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml"); var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
var project = new TestRazorProject(new[] { projectItem }); var fileSystem = new TestRazorProjectFileSystem(new[] { projectItem });
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project) var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem)
{ {
Options = Options =
{ {
@ -316,11 +316,11 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
// Arrange // Arrange
var testFolder = Path.Combine( var testFolder = Path.Combine(
TestProject.GetProjectDirectory(typeof(FileSystemRazorProjectTest)), TestProject.GetProjectDirectory(typeof(DefaultRazorProjectFileSystemTest)),
"TestFiles", "TestFiles",
"FileSystemRazorProject"); "DefaultRazorProjectFileSystem");
var project = new FileSystemRazorProject(testFolder); var project = new DefaultRazorProjectFileSystem(testFolder);
var razorEngine = RazorEngine.Create(); var razorEngine = RazorEngine.Create();
var templateEngine = new RazorTemplateEngine(razorEngine, project) var templateEngine = new RazorTemplateEngine(razorEngine, project)
{ {

View File

@ -544,7 +544,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
var items = new List<RazorProjectItem>(); var items = new List<RazorProjectItem>();
items.Add(new TestRazorProjectItem(path)); items.Add(new TestRazorProjectItem(path));
var project = new TestRazorProject(items); var project = new TestRazorProjectFileSystem(items);
var templateEngine = new RazorTemplateEngine(engine, project); var templateEngine = new RazorTemplateEngine(engine, project);
templateEngine.Options.DefaultImports = RazorSourceDocument.Create("@addTagHelper *, Test", "_TestImports.cshtml"); templateEngine.Options.DefaultImports = RazorSourceDocument.Create("@addTagHelper *, Test", "_TestImports.cshtml");

View File

@ -599,7 +599,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
var items = new List<RazorProjectItem>(); var items = new List<RazorProjectItem>();
items.Add(new TestRazorProjectItem(path)); items.Add(new TestRazorProjectItem(path));
var project = new TestRazorProject(items); var project = new TestRazorProjectFileSystem(items);
var templateEngine = new RazorTemplateEngine(engine, project); var templateEngine = new RazorTemplateEngine(engine, project);
templateEngine.Options.DefaultImports = RazorSourceDocument.Create("@addTagHelper *, Test", "_TestImports.cshtml"); templateEngine.Options.DefaultImports = RazorSourceDocument.Create("@addTagHelper *, Test", "_TestImports.cshtml");