зеркало из https://github.com/dotnet/razor.git
Remove RazorTemplateEngine and friends.
- Also nuked tests and resource entries specific to the template engine. Addresses aspnet/AspNetCore#5079
This commit is contained in:
Родитель
9092c22291
Коммит
d5f0b4c0b4
|
@ -1,60 +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 System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="RazorTemplateEngine"/> for Mvc Razor views.
|
||||
/// </summary>
|
||||
public class MvcRazorTemplateEngine : RazorTemplateEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="MvcRazorTemplateEngine"/>.
|
||||
/// </summary>
|
||||
/// <param name="engine">The <see cref="RazorEngine"/>.</param>
|
||||
/// <param name="project">The <see cref="RazorProject"/>.</param>
|
||||
public MvcRazorTemplateEngine(
|
||||
RazorEngine engine,
|
||||
RazorProject project)
|
||||
: base(engine, project)
|
||||
{
|
||||
Options.ImportsFileName = "_ViewImports.cshtml";
|
||||
Options.DefaultImports = GetDefaultImports();
|
||||
}
|
||||
|
||||
public override RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem)
|
||||
{
|
||||
return base.CreateCodeDocument(projectItem);
|
||||
}
|
||||
|
||||
// Internal for testing.
|
||||
internal static RazorSourceDocument GetDefaultImports()
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
using (var writer = new StreamWriter(stream, Encoding.UTF8))
|
||||
{
|
||||
writer.WriteLine("@using System");
|
||||
writer.WriteLine("@using System.Collections.Generic");
|
||||
writer.WriteLine("@using System.Linq");
|
||||
writer.WriteLine("@using System.Threading.Tasks");
|
||||
writer.WriteLine("@using Microsoft.AspNetCore.Mvc");
|
||||
writer.WriteLine("@using Microsoft.AspNetCore.Mvc.Rendering");
|
||||
writer.WriteLine("@using Microsoft.AspNetCore.Mvc.ViewFeatures");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> Html");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider");
|
||||
writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor");
|
||||
writer.Flush();
|
||||
|
||||
stream.Position = 0;
|
||||
return RazorSourceDocument.ReadFrom(stream, fileName: null, encoding: Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +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 System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="RazorTemplateEngine"/> for Mvc Razor views.
|
||||
/// </summary>
|
||||
public class MvcRazorTemplateEngine : RazorTemplateEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="MvcRazorTemplateEngine"/>.
|
||||
/// </summary>
|
||||
/// <param name="engine">The <see cref="RazorEngine"/>.</param>
|
||||
/// <param name="project">The <see cref="RazorProject"/>.</param>
|
||||
public MvcRazorTemplateEngine(
|
||||
RazorEngine engine,
|
||||
RazorProject project)
|
||||
: base(engine, project)
|
||||
{
|
||||
Options.ImportsFileName = "_ViewImports.cshtml";
|
||||
Options.DefaultImports = GetDefaultImports();
|
||||
}
|
||||
|
||||
public override RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem)
|
||||
{
|
||||
return base.CreateCodeDocument(projectItem);
|
||||
}
|
||||
|
||||
// Internal for testing.
|
||||
internal static RazorSourceDocument GetDefaultImports()
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
using (var writer = new StreamWriter(stream, Encoding.UTF8))
|
||||
{
|
||||
writer.WriteLine("@using System");
|
||||
writer.WriteLine("@using System.Collections.Generic");
|
||||
writer.WriteLine("@using System.Linq");
|
||||
writer.WriteLine("@using System.Threading.Tasks");
|
||||
writer.WriteLine("@using Microsoft.AspNetCore.Mvc");
|
||||
writer.WriteLine("@using Microsoft.AspNetCore.Mvc.Rendering");
|
||||
writer.WriteLine("@using Microsoft.AspNetCore.Mvc.ViewFeatures");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> Html");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url");
|
||||
writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider");
|
||||
writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor");
|
||||
writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor");
|
||||
writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor");
|
||||
writer.Flush();
|
||||
|
||||
stream.Position = 0;
|
||||
return RazorSourceDocument.ReadFrom(stream, fileName: null, encoding: Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1208,20 +1208,6 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
internal static string FormatRazorProject_PathMustStartWithForwardSlash()
|
||||
=> GetString("RazorProject_PathMustStartWithForwardSlash");
|
||||
|
||||
/// <summary>
|
||||
/// The item '{0}' could not be found.
|
||||
/// </summary>
|
||||
internal static string RazorTemplateEngine_ItemCouldNotBeFound
|
||||
{
|
||||
get => GetString("RazorTemplateEngine_ItemCouldNotBeFound");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The item '{0}' could not be found.
|
||||
/// </summary>
|
||||
internal static string FormatRazorTemplateEngine_ItemCouldNotBeFound(object p0)
|
||||
=> string.Format(CultureInfo.CurrentCulture, GetString("RazorTemplateEngine_ItemCouldNotBeFound"), p0);
|
||||
|
||||
/// <summary>
|
||||
/// Remove Tag Helpers for use in the current document.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,241 +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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
{
|
||||
/// <summary>
|
||||
/// Entry point to parse Razor files and generate code.
|
||||
/// </summary>
|
||||
public class RazorTemplateEngine
|
||||
{
|
||||
private RazorTemplateEngineOptions _options;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="RazorTemplateEngine"/>.
|
||||
/// </summary>
|
||||
/// <param name="engine">The <see cref="RazorEngine"/>.</param>
|
||||
/// <param name="project">The <see cref="RazorProject"/>.</param>
|
||||
public RazorTemplateEngine(
|
||||
RazorEngine engine,
|
||||
RazorProject project)
|
||||
{
|
||||
if (engine == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(engine));
|
||||
}
|
||||
|
||||
if (project == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(project));
|
||||
}
|
||||
|
||||
Engine = engine;
|
||||
Project = project;
|
||||
_options = new RazorTemplateEngineOptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="RazorEngine"/>.
|
||||
/// </summary>
|
||||
public RazorEngine Engine { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="RazorProject"/>.
|
||||
/// </summary>
|
||||
public RazorProject Project { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Options to configure <see cref="RazorTemplateEngine"/>.
|
||||
/// </summary>
|
||||
public RazorTemplateEngineOptions Options
|
||||
{
|
||||
get
|
||||
{
|
||||
return _options;
|
||||
}
|
||||
set
|
||||
{
|
||||
_options = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the template specified by the project item <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The template path.</param>
|
||||
/// <returns>The <see cref="RazorCSharpDocument"/>.</returns>
|
||||
public RazorCSharpDocument GenerateCode(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
|
||||
}
|
||||
|
||||
var projectItem = Project.GetItem(path);
|
||||
return GenerateCode(projectItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the template specified by <paramref name="projectItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="projectItem">The <see cref="RazorProjectItem"/>.</param>
|
||||
/// <returns>The <see cref="RazorCSharpDocument"/>.</returns>
|
||||
public RazorCSharpDocument GenerateCode(RazorProjectItem projectItem)
|
||||
{
|
||||
if (projectItem == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(projectItem));
|
||||
}
|
||||
|
||||
if (!projectItem.Exists)
|
||||
{
|
||||
throw new InvalidOperationException(Resources.FormatRazorTemplateEngine_ItemCouldNotBeFound(projectItem.FilePath));
|
||||
}
|
||||
|
||||
var codeDocument = CreateCodeDocument(projectItem);
|
||||
return GenerateCode(codeDocument);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the template specified by <paramref name="codeDocument"/>.
|
||||
/// </summary>
|
||||
/// <param name="codeDocument">The <see cref="RazorProjectItem"/>.</param>
|
||||
/// <returns>The <see cref="RazorCSharpDocument"/>.</returns>
|
||||
public virtual RazorCSharpDocument GenerateCode(RazorCodeDocument codeDocument)
|
||||
{
|
||||
if (codeDocument == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeDocument));
|
||||
}
|
||||
|
||||
Engine.Process(codeDocument);
|
||||
return codeDocument.GetCSharpDocument();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a <see cref="RazorCodeDocument"/> for the specified <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The template path.</param>
|
||||
/// <returns>The created <see cref="RazorCodeDocument"/>.</returns>
|
||||
public virtual RazorCodeDocument CreateCodeDocument(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
|
||||
}
|
||||
|
||||
var projectItem = Project.GetItem(path);
|
||||
return CreateCodeDocument(projectItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a <see cref="RazorCodeDocument"/> for the specified <paramref name="projectItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="projectItem">The <see cref="RazorProjectItem"/>.</param>
|
||||
/// <returns>The created <see cref="RazorCodeDocument"/>.</returns>
|
||||
public virtual RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem)
|
||||
{
|
||||
if (projectItem == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(projectItem));
|
||||
}
|
||||
|
||||
if (!projectItem.Exists)
|
||||
{
|
||||
throw new InvalidOperationException(Resources.FormatRazorTemplateEngine_ItemCouldNotBeFound(projectItem.FilePath));
|
||||
}
|
||||
|
||||
var source = RazorSourceDocument.ReadFrom(projectItem);
|
||||
var imports = GetImports(projectItem);
|
||||
|
||||
return RazorCodeDocument.Create(source, imports);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets <see cref="RazorSourceDocument"/> that are applicable to the specified <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The template path.</param>
|
||||
/// <returns>The sequence of applicable <see cref="RazorSourceDocument"/>.</returns>
|
||||
public IEnumerable<RazorSourceDocument> GetImports(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
|
||||
}
|
||||
|
||||
var projectItem = Project.GetItem(path);
|
||||
return GetImports(projectItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets <see cref="RazorSourceDocument"/> that are applicable to the specified <paramref name="projectItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="projectItem">The <see cref="RazorProjectItem"/>.</param>
|
||||
/// <returns>The sequence of applicable <see cref="RazorSourceDocument"/>.</returns>
|
||||
public virtual IEnumerable<RazorSourceDocument> GetImports(RazorProjectItem projectItem)
|
||||
{
|
||||
if (projectItem == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(projectItem));
|
||||
}
|
||||
var result = new List<RazorSourceDocument>();
|
||||
|
||||
var importProjectItems = GetImportItems(projectItem);
|
||||
foreach (var importItem in importProjectItems)
|
||||
{
|
||||
if (importItem.Exists)
|
||||
{
|
||||
// We want items in descending order. FindHierarchicalItems returns items in ascending order.
|
||||
result.Insert(0, RazorSourceDocument.ReadFrom(importItem));
|
||||
}
|
||||
}
|
||||
|
||||
if (Options.DefaultImports != null)
|
||||
{
|
||||
result.Insert(0, Options.DefaultImports);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sequence of imports with the name specified by <see cref="RazorTemplateEngineOptions.ImportsFileName" />
|
||||
/// that apply to <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to look up import items for.</param>
|
||||
/// <returns>A sequence of <see cref="RazorProjectItem"/> instances that apply to the
|
||||
/// <paramref name="path"/>.</returns>
|
||||
public IEnumerable<RazorProjectItem> GetImportItems(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
|
||||
}
|
||||
|
||||
var projectItem = Project.GetItem(path);
|
||||
return GetImportItems(projectItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sequence of imports with the name specified by <see cref="RazorTemplateEngineOptions.ImportsFileName" />
|
||||
/// that apply to <paramref name="projectItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="projectItem">The <see cref="RazorProjectItem"/> to look up import items for.</param>
|
||||
/// <returns>A sequence of <see cref="RazorProjectItem"/> instances that apply to the
|
||||
/// <paramref name="projectItem"/>.</returns>
|
||||
public virtual IEnumerable<RazorProjectItem> GetImportItems(RazorProjectItem projectItem)
|
||||
{
|
||||
var importsFileName = Options.ImportsFileName;
|
||||
if (!string.IsNullOrEmpty(importsFileName))
|
||||
{
|
||||
return Project.FindHierarchicalItems(projectItem.FilePath, importsFileName);
|
||||
}
|
||||
|
||||
return Enumerable.Empty<RazorProjectItem>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +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.
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for code generation in the <see cref="RazorTemplateEngine"/>.
|
||||
/// </summary>
|
||||
public sealed class RazorTemplateEngineOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the file name of the imports file (e.g. _ViewImports.cshtml).
|
||||
/// </summary>
|
||||
public string ImportsFileName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default set of imports.
|
||||
/// </summary>
|
||||
public RazorSourceDocument DefaultImports { get; set; }
|
||||
}
|
||||
}
|
|
@ -392,9 +392,6 @@ Instead, wrap the contents of the block in "{{}}":
|
|||
<data name="RazorProject_PathMustStartWithForwardSlash" xml:space="preserve">
|
||||
<value>Path must begin with a forward slash '/'.</value>
|
||||
</data>
|
||||
<data name="RazorTemplateEngine_ItemCouldNotBeFound" xml:space="preserve">
|
||||
<value>The item '{0}' could not be found.</value>
|
||||
</data>
|
||||
<data name="RemoveTagHelperDirective_Description" xml:space="preserve">
|
||||
<value>Remove Tag Helpers for use in the current document.</value>
|
||||
</data>
|
||||
|
|
|
@ -1,97 +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 System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||
{
|
||||
public class MvcRazorTemplateEngineTest : RazorProjectEngineTestBase
|
||||
{
|
||||
protected override RazorLanguageVersion Version => RazorLanguageVersion.Version_3_0;
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultImports_IncludesDefaultImports()
|
||||
{
|
||||
// Arrange
|
||||
var expectedImports = new[]
|
||||
{
|
||||
"@using System",
|
||||
"@using System.Collections.Generic",
|
||||
"@using System.Linq",
|
||||
"@using System.Threading.Tasks",
|
||||
"@using Microsoft.AspNetCore.Mvc",
|
||||
"@using Microsoft.AspNetCore.Mvc.Rendering",
|
||||
"@using Microsoft.AspNetCore.Mvc.ViewFeatures",
|
||||
};
|
||||
|
||||
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
|
||||
CreateProjectEngine().Engine,
|
||||
new TestRazorProjectFileSystem());
|
||||
|
||||
// Act
|
||||
var imports = mvcRazorTemplateEngine.Options.DefaultImports;
|
||||
|
||||
// Assert
|
||||
var importContent = GetContent(imports)
|
||||
.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
.Where(line => line.StartsWith("@using"));
|
||||
Assert.Equal(expectedImports, importContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultImports_IncludesDefaulInjects()
|
||||
{
|
||||
// Arrange
|
||||
var expectedImports = new[]
|
||||
{
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> Html",
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json",
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component",
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url",
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider",
|
||||
};
|
||||
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
|
||||
CreateProjectEngine().Engine,
|
||||
new TestRazorProjectFileSystem());
|
||||
|
||||
// Act
|
||||
var imports = mvcRazorTemplateEngine.Options.DefaultImports;
|
||||
|
||||
// Assert
|
||||
var importContent = GetContent(imports)
|
||||
.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
.Where(line => line.StartsWith("@inject"));
|
||||
Assert.Equal(expectedImports, importContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultImports_IncludesDefaultTagHelpers()
|
||||
{
|
||||
// Arrange
|
||||
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
|
||||
CreateProjectEngine().Engine,
|
||||
new TestRazorProjectFileSystem());
|
||||
|
||||
// Act
|
||||
var imports = mvcRazorTemplateEngine.Options.DefaultImports;
|
||||
|
||||
// Assert
|
||||
var importContent = GetContent(imports)
|
||||
.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
.Where(line => line.StartsWith("@addTagHelper"));
|
||||
Assert.Contains("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor", importContent);
|
||||
Assert.Contains("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor", importContent);
|
||||
Assert.Contains("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor", importContent);
|
||||
}
|
||||
|
||||
private string GetContent(RazorSourceDocument imports)
|
||||
{
|
||||
var contentChars = new char[imports.Length];
|
||||
imports.CopyTo(0, contentChars, 0, imports.Length);
|
||||
return new string(contentChars);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,94 +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 System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
||||
{
|
||||
public class MvcRazorTemplateEngineTest : RazorProjectEngineTestBase
|
||||
{
|
||||
protected override RazorLanguageVersion Version => RazorLanguageVersion.Version_1_1;
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultImports_IncludesDefaultImports()
|
||||
{
|
||||
// Arrange
|
||||
var expectedImports = new[]
|
||||
{
|
||||
"@using System",
|
||||
"@using System.Collections.Generic",
|
||||
"@using System.Linq",
|
||||
"@using System.Threading.Tasks",
|
||||
"@using Microsoft.AspNetCore.Mvc",
|
||||
"@using Microsoft.AspNetCore.Mvc.Rendering",
|
||||
"@using Microsoft.AspNetCore.Mvc.ViewFeatures",
|
||||
};
|
||||
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
|
||||
CreateProjectEngine().Engine,
|
||||
new TestRazorProjectFileSystem());
|
||||
|
||||
// Act
|
||||
var imports = mvcRazorTemplateEngine.Options.DefaultImports;
|
||||
|
||||
// Assert
|
||||
var importContent = GetContent(imports)
|
||||
.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
.Where(line => line.StartsWith("@using"));
|
||||
Assert.Equal(expectedImports, importContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultImports_IncludesDefaulInjects()
|
||||
{
|
||||
// Arrange
|
||||
var expectedImports = new[]
|
||||
{
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> Html",
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json",
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component",
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url",
|
||||
"@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider",
|
||||
};
|
||||
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
|
||||
CreateProjectEngine().Engine,
|
||||
new TestRazorProjectFileSystem());
|
||||
|
||||
// Act
|
||||
var imports = mvcRazorTemplateEngine.Options.DefaultImports;
|
||||
|
||||
// Assert
|
||||
var importContent = GetContent(imports)
|
||||
.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
.Where(line => line.StartsWith("@inject"));
|
||||
Assert.Equal(expectedImports, importContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultImports_IncludesDefaultTagHelpers()
|
||||
{
|
||||
// Arrange
|
||||
var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
|
||||
CreateProjectEngine().Engine,
|
||||
new TestRazorProjectFileSystem());
|
||||
|
||||
// Act
|
||||
var imports = mvcRazorTemplateEngine.Options.DefaultImports;
|
||||
|
||||
// Assert
|
||||
var importContent = GetContent(imports)
|
||||
.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
.Where(line => line.StartsWith("@addTagHelper"));
|
||||
Assert.Contains("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor", importContent);
|
||||
}
|
||||
|
||||
private string GetContent(RazorSourceDocument imports)
|
||||
{
|
||||
var contentChars = new char[imports.Length];
|
||||
imports.CopyTo(0, contentChars, 0, imports.Length);
|
||||
return new string(contentChars);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,103 +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 Microsoft.AspNetCore.Razor.Language.Intermediate;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
||||
{
|
||||
public class RazorTemplateEngineIntegrationTest : IntegrationTestBase
|
||||
{
|
||||
[Fact]
|
||||
public void GenerateCodeWithDefaults()
|
||||
{
|
||||
// Arrange
|
||||
var fileSystem = new DefaultRazorProjectFileSystem(TestProjectRoot);
|
||||
var razorEngine = RazorProjectEngine.Create(engine =>
|
||||
{
|
||||
engine.Features.Add(new SuppressChecksumOptionsFeature());
|
||||
}).Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem);
|
||||
|
||||
// Act
|
||||
var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml");
|
||||
|
||||
// Assert
|
||||
AssertCSharpDocumentMatchesBaseline(cSharpDocument);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCodeWithBaseType()
|
||||
{
|
||||
// Arrange
|
||||
var fileSystem = new DefaultRazorProjectFileSystem(TestProjectRoot);
|
||||
var razorEngine = RazorProjectEngine.Create(engine =>
|
||||
{
|
||||
engine.Features.Add(new SuppressChecksumOptionsFeature());
|
||||
|
||||
engine.SetBaseType("MyBaseType");
|
||||
}).Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem);
|
||||
|
||||
// Act
|
||||
var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml");
|
||||
|
||||
// Assert
|
||||
AssertCSharpDocumentMatchesBaseline(cSharpDocument);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCodeWithConfigureClass()
|
||||
{
|
||||
// Arrange
|
||||
var fileSystem = new DefaultRazorProjectFileSystem(TestProjectRoot);
|
||||
var razorEngine = RazorProjectEngine.Create(engine =>
|
||||
{
|
||||
engine.Features.Add(new SuppressChecksumOptionsFeature());
|
||||
|
||||
engine.ConfigureClass((document, @class) =>
|
||||
{
|
||||
@class.ClassName = "MyClass";
|
||||
|
||||
@class.Modifiers.Clear();
|
||||
@class.Modifiers.Add("protected");
|
||||
@class.Modifiers.Add("internal");
|
||||
});
|
||||
|
||||
engine.ConfigureClass((document, @class) =>
|
||||
{
|
||||
@class.TypeParameters = new[] { new TypeParameter() { ParameterName = "TValue", }, };
|
||||
@class.Interfaces = new[] { "global::System.IDisposable" };
|
||||
@class.BaseType = "CustomBaseType";
|
||||
});
|
||||
}).Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem);
|
||||
|
||||
// Act
|
||||
var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml");
|
||||
|
||||
// Assert
|
||||
AssertCSharpDocumentMatchesBaseline(cSharpDocument);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCodeWithSetNamespace()
|
||||
{
|
||||
// Arrange
|
||||
var fileSystem = new DefaultRazorProjectFileSystem(TestProjectRoot);
|
||||
var razorEngine = RazorProjectEngine.Create(engine =>
|
||||
{
|
||||
engine.Features.Add(new SuppressChecksumOptionsFeature());
|
||||
|
||||
engine.SetNamespace("MyApp.Razor.Views");
|
||||
}).Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem);
|
||||
|
||||
// Act
|
||||
var cSharpDocument = templateEngine.GenerateCode($"{FileName}.cshtml");
|
||||
|
||||
// Assert
|
||||
AssertCSharpDocumentMatchesBaseline(cSharpDocument);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,361 +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 System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
{
|
||||
public class RazorTemplateEngineTest : RazorProjectEngineTestBase
|
||||
{
|
||||
protected override RazorLanguageVersion Version => RazorLanguageVersion.Latest;
|
||||
|
||||
[Fact]
|
||||
public void GetImports_CanQueryInformationOnNonExistentFileWithoutImports()
|
||||
{
|
||||
// Arrange
|
||||
var fileSystem = new TestRazorProjectFileSystem();
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem)
|
||||
{
|
||||
Options =
|
||||
{
|
||||
ImportsFileName = "MyImport.cshtml"
|
||||
}
|
||||
};
|
||||
var projectItemToQuery = fileSystem.GetItem("/Views/Home/Index.cshtml");
|
||||
|
||||
// Act
|
||||
var imports = templateEngine.GetImports(projectItemToQuery);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(imports);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetImports_CanQueryInformationOnNonExistentFileWithImports()
|
||||
{
|
||||
// Arrange
|
||||
var path = "/Views/Home/MyImport.cshtml";
|
||||
var projectItem = new TestRazorProjectItem(path);
|
||||
var project = new TestRazorProjectFileSystem(new[] { projectItem });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project)
|
||||
{
|
||||
Options =
|
||||
{
|
||||
ImportsFileName = "MyImport.cshtml"
|
||||
}
|
||||
};
|
||||
var projectItemToQuery = project.GetItem("/Views/Home/Index.cshtml");
|
||||
|
||||
// Act
|
||||
var imports = templateEngine.GetImports(projectItemToQuery);
|
||||
|
||||
// Assert
|
||||
var import = Assert.Single(imports);
|
||||
Assert.Equal(projectItem.FilePath, import.FilePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCode_ThrowsIfItemCannotBeFound()
|
||||
{
|
||||
// Arrange
|
||||
var project = new TestRazorProjectFileSystem(new RazorProjectItem[] { });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project);
|
||||
|
||||
// Act & Assert
|
||||
var ex = Assert.Throws<InvalidOperationException>(
|
||||
() => templateEngine.GenerateCode("/does-not-exist.cstml"));
|
||||
Assert.Equal("The item '/does-not-exist.cstml' could not be found.", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingOptions_ThrowsIfValueIsNull()
|
||||
{
|
||||
// Arrange
|
||||
var project = new TestRazorProjectFileSystem(new RazorProjectItem[] { });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project);
|
||||
|
||||
// Act & Assert
|
||||
ExceptionAssert.ThrowsArgumentNull(
|
||||
() => templateEngine.Options = null,
|
||||
"value");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCode_WithPath()
|
||||
{
|
||||
// Arrange
|
||||
var path = "/Views/Home/Index.cshtml";
|
||||
var projectItem = new TestRazorProjectItem(path);
|
||||
var project = new TestRazorProjectFileSystem(new[] { projectItem });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project);
|
||||
|
||||
// Act
|
||||
var cSharpDocument = templateEngine.GenerateCode(path);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(cSharpDocument);
|
||||
Assert.NotEmpty(cSharpDocument.GeneratedCode);
|
||||
Assert.Empty(cSharpDocument.Diagnostics);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCode_ThrowsIfProjectItemCannotBeFound()
|
||||
{
|
||||
// Arrange
|
||||
var path = "/Views/Home/Index.cshtml";
|
||||
var project = new TestRazorProjectFileSystem(new RazorProjectItem[] { });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project);
|
||||
|
||||
// Act & Assert
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => templateEngine.GenerateCode(path));
|
||||
Assert.Equal($"The item '{path}' could not be found.", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCode_WithProjectItem()
|
||||
{
|
||||
// Arrange
|
||||
var path = "/Views/Home/Index.cshtml";
|
||||
var projectItem = new TestRazorProjectItem(path);
|
||||
var project = new TestRazorProjectFileSystem(new[] { projectItem });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project);
|
||||
|
||||
// Act
|
||||
var cSharpDocument = templateEngine.GenerateCode(projectItem);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(cSharpDocument);
|
||||
Assert.NotEmpty(cSharpDocument.GeneratedCode);
|
||||
Assert.Empty(cSharpDocument.Diagnostics);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateCode_WithCodeDocument()
|
||||
{
|
||||
// Arrange
|
||||
var path = "/Views/Home/Index.cshtml";
|
||||
var projectItem = new TestRazorProjectItem(path);
|
||||
var project = new TestRazorProjectFileSystem(new[] { projectItem });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project);
|
||||
|
||||
// Act - 1
|
||||
var codeDocument = templateEngine.CreateCodeDocument(path);
|
||||
|
||||
// Assert - 1
|
||||
Assert.NotNull(codeDocument);
|
||||
|
||||
// Act - 2
|
||||
var cSharpDocument = templateEngine.GenerateCode(codeDocument);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(cSharpDocument);
|
||||
Assert.NotEmpty(cSharpDocument.GeneratedCode);
|
||||
Assert.Empty(cSharpDocument.Diagnostics);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateCodeDocument_ThrowsIfPathCannotBeFound()
|
||||
{
|
||||
// Arrange
|
||||
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
|
||||
var project = new TestRazorProjectFileSystem(new[] { projectItem });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project)
|
||||
{
|
||||
Options =
|
||||
{
|
||||
ImportsFileName = "MyImport.cshtml",
|
||||
}
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => templateEngine.CreateCodeDocument("/DoesNotExist.cshtml"));
|
||||
|
||||
// Assert
|
||||
Assert.Equal("The item '/DoesNotExist.cshtml' could not be found.", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateCodeDocument_IncludesImportsIfFileIsPresent()
|
||||
{
|
||||
// Arrange
|
||||
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
|
||||
var import1 = new TestRazorProjectItem("/MyImport.cshtml");
|
||||
var import2 = new TestRazorProjectItem("/Views/Home/MyImport.cshtml");
|
||||
var project = new TestRazorProjectFileSystem(new[] { import1, import2, projectItem });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project)
|
||||
{
|
||||
Options =
|
||||
{
|
||||
ImportsFileName = "MyImport.cshtml",
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var codeDocument = templateEngine.CreateCodeDocument("/Views/Home/Index.cshtml");
|
||||
|
||||
// Assert
|
||||
Assert.Collection(codeDocument.Imports,
|
||||
import => Assert.Equal("/MyImport.cshtml", import.FilePath),
|
||||
import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FilePath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateCodeDocument_IncludesDefaultImportIfNotNull()
|
||||
{
|
||||
// Arrange
|
||||
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
|
||||
var import1 = new TestRazorProjectItem("/MyImport.cshtml");
|
||||
var import2 = new TestRazorProjectItem("/Views/Home/MyImport.cshtml");
|
||||
var project = new TestRazorProjectFileSystem(new[] { import1, import2, projectItem });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var defaultImport = RazorSourceDocument.ReadFrom(new MemoryStream(), "Default.cshtml");
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project)
|
||||
{
|
||||
Options =
|
||||
{
|
||||
ImportsFileName = "MyImport.cshtml",
|
||||
DefaultImports = defaultImport,
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var codeDocument = templateEngine.CreateCodeDocument(projectItem);
|
||||
|
||||
// Assert
|
||||
Assert.Collection(codeDocument.Imports,
|
||||
import => Assert.Same(defaultImport, import),
|
||||
import => Assert.Equal("/MyImport.cshtml", import.FilePath),
|
||||
import => Assert.Equal("/Views/Home/MyImport.cshtml", import.FilePath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateCodeDocument_NullImportFileName_IncludesDefaultImportIfNotNull()
|
||||
{
|
||||
// Arrange
|
||||
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
|
||||
var project = new TestRazorProjectFileSystem(new[] { projectItem });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var defaultImport = RazorSourceDocument.ReadFrom(new MemoryStream(), "Default.cshtml");
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project)
|
||||
{
|
||||
Options =
|
||||
{
|
||||
DefaultImports = defaultImport,
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var codeDocument = templateEngine.CreateCodeDocument(projectItem);
|
||||
|
||||
// Assert
|
||||
Assert.Collection(codeDocument.Imports,
|
||||
import => Assert.Same(defaultImport, import));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetImportItems_WithPath_ReturnsAllImportsForFile()
|
||||
{
|
||||
// Arrange
|
||||
var expected = new[] { "/Views/Home/MyImport.cshtml", "/Views/MyImport.cshtml", "/MyImport.cshtml" };
|
||||
var project = new TestRazorProjectFileSystem();
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project)
|
||||
{
|
||||
Options =
|
||||
{
|
||||
ImportsFileName = "MyImport.cshtml"
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var imports = templateEngine.GetImportItems("/Views/Home/Index.cshtml");
|
||||
|
||||
// Assert
|
||||
var paths = imports.Select(i => i.FilePath);
|
||||
Assert.Equal(expected, paths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetImportItems_WithItem_ReturnsAllImportsForFile()
|
||||
{
|
||||
// Arrange
|
||||
var expected = new[] { "/Views/Home/MyImport.cshtml", "/Views/MyImport.cshtml", "/MyImport.cshtml" };
|
||||
var projectItem = new TestRazorProjectItem("/Views/Home/Index.cshtml");
|
||||
var fileSystem = new TestRazorProjectFileSystem(new[] { projectItem });
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, fileSystem)
|
||||
{
|
||||
Options =
|
||||
{
|
||||
ImportsFileName = "MyImport.cshtml"
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var imports = templateEngine.GetImportItems(projectItem);
|
||||
|
||||
// Assert
|
||||
var paths = imports.Select(i => i.FilePath);
|
||||
Assert.Equal(expected, paths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateCodeDocument_WithFileSystemProject_ReturnsCorrectItems()
|
||||
{
|
||||
// Arrange
|
||||
var testFolder = Path.Combine(
|
||||
TestProject.GetProjectDirectory(typeof(DefaultRazorProjectFileSystemTest)),
|
||||
"TestFiles",
|
||||
"DefaultRazorProjectFileSystem");
|
||||
|
||||
var project = new DefaultRazorProjectFileSystem(testFolder);
|
||||
var razorEngine = CreateProjectEngine().Engine;
|
||||
var templateEngine = new RazorTemplateEngine(razorEngine, project)
|
||||
{
|
||||
Options =
|
||||
{
|
||||
ImportsFileName = "_ViewImports.cshtml"
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var codeDocument = templateEngine.CreateCodeDocument("/Views/Home/Index.cshtml");
|
||||
|
||||
// Assert
|
||||
Assert.Collection(
|
||||
codeDocument.Imports,
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(Path.Combine(testFolder, "_ViewImports.cshtml"), item.FilePath);
|
||||
Assert.Equal("_ViewImports.cshtml", item.RelativePath);
|
||||
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(Path.Combine(testFolder, "Views", "_ViewImports.cshtml"), item.FilePath);
|
||||
Assert.Equal(Path.Combine("Views", "_ViewImports.cshtml"), item.RelativePath);
|
||||
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(Path.Combine(testFolder, "Views", "Home", "_ViewImports.cshtml"), item.FilePath);
|
||||
Assert.Equal(Path.Combine("Views", "Home", "_ViewImports.cshtml"), item.RelativePath);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
// <auto-generated/>
|
||||
#pragma warning disable 1591
|
||||
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(Razor.Template), @"default", @"/TestFiles/IntegrationTests/RazorTemplateEngineIntegrationTest/GenerateCodeWithBaseType.cshtml")]
|
||||
namespace Razor
|
||||
{
|
||||
#line hidden
|
||||
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"38aa8e26c5d2a85c61d8e93fe69dd326fe82671b", @"/TestFiles/IntegrationTests/RazorTemplateEngineIntegrationTest/GenerateCodeWithBaseType.cshtml")]
|
||||
public class Template : MyBaseType
|
||||
{
|
||||
#pragma warning disable 1998
|
||||
public async override global::System.Threading.Tasks.Task ExecuteAsync()
|
||||
{
|
||||
WriteLiteral("<h1>Hello world!</h1>");
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
}
|
||||
}
|
||||
#pragma warning restore 1591
|
|
@ -1 +0,0 @@
|
|||
<h1>Hello world!</h1>
|
|
@ -1,18 +0,0 @@
|
|||
// <auto-generated/>
|
||||
#pragma warning disable 1591
|
||||
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(Razor.MyClass), @"default", @"/TestFiles/IntegrationTests/RazorTemplateEngineIntegrationTest/GenerateCodeWithConfigureClass.cshtml")]
|
||||
namespace Razor
|
||||
{
|
||||
#line hidden
|
||||
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"38aa8e26c5d2a85c61d8e93fe69dd326fe82671b", @"/TestFiles/IntegrationTests/RazorTemplateEngineIntegrationTest/GenerateCodeWithConfigureClass.cshtml")]
|
||||
protected internal class MyClass<TValue> : CustomBaseType, global::System.IDisposable
|
||||
{
|
||||
#pragma warning disable 1998
|
||||
public async override global::System.Threading.Tasks.Task ExecuteAsync()
|
||||
{
|
||||
WriteLiteral("<h1>Hello world!</h1>");
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
}
|
||||
}
|
||||
#pragma warning restore 1591
|
|
@ -1 +0,0 @@
|
|||
<h1>Hello world!</h1>
|
|
@ -1,18 +0,0 @@
|
|||
// <auto-generated/>
|
||||
#pragma warning disable 1591
|
||||
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(Razor.Template), @"default", @"/TestFiles/IntegrationTests/RazorTemplateEngineIntegrationTest/GenerateCodeWithDefaults.cshtml")]
|
||||
namespace Razor
|
||||
{
|
||||
#line hidden
|
||||
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"38aa8e26c5d2a85c61d8e93fe69dd326fe82671b", @"/TestFiles/IntegrationTests/RazorTemplateEngineIntegrationTest/GenerateCodeWithDefaults.cshtml")]
|
||||
public class Template
|
||||
{
|
||||
#pragma warning disable 1998
|
||||
public async override global::System.Threading.Tasks.Task ExecuteAsync()
|
||||
{
|
||||
WriteLiteral("<h1>Hello world!</h1>");
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
}
|
||||
}
|
||||
#pragma warning restore 1591
|
|
@ -1 +0,0 @@
|
|||
<h1>Hello world!</h1>
|
|
@ -1,18 +0,0 @@
|
|||
// <auto-generated/>
|
||||
#pragma warning disable 1591
|
||||
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(MyApp.Razor.Views.Template), @"default", @"/TestFiles/IntegrationTests/RazorTemplateEngineIntegrationTest/GenerateCodeWithSetNamespace.cshtml")]
|
||||
namespace MyApp.Razor.Views
|
||||
{
|
||||
#line hidden
|
||||
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"38aa8e26c5d2a85c61d8e93fe69dd326fe82671b", @"/TestFiles/IntegrationTests/RazorTemplateEngineIntegrationTest/GenerateCodeWithSetNamespace.cshtml")]
|
||||
public class Template
|
||||
{
|
||||
#pragma warning disable 1998
|
||||
public async override global::System.Threading.Tasks.Task ExecuteAsync()
|
||||
{
|
||||
WriteLiteral("<h1>Hello world!</h1>");
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
}
|
||||
}
|
||||
#pragma warning restore 1591
|
Загрузка…
Ссылка в новой задаче