Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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.

using System.Linq;
Expand Down Expand Up @@ -525,6 +525,90 @@ public void RazorPageWithNoLeadingPageDirective_Runtime()
var diagnotics = compiled.CodeDocument.GetCSharpDocument().Diagnostics;
Assert.Equal("RZ3906", Assert.Single(diagnotics).Id);
}

[Fact]
public void RazorPage_WithCssScope()
{
// Arrange
AddCSharpSyntaxTree($@"
[{typeof(HtmlTargetElementAttribute).FullName}({"\"all\""})]
public class AllTagHelper : {typeof(TagHelper).FullName}
{{
public string Bar {{ get; set; }}
}}

[{typeof(HtmlTargetElementAttribute).FullName}({"\"form\""})]
public class FormTagHelper : {typeof(TagHelper).FullName}
{{
}}
");

// Act
// This test case attempts to use all syntaxes that might interact with auto-generated attributes
var generated = CompileToCSharp(@"@page
@addTagHelper *, AppCode
@{
ViewData[""Title""] = ""Home page"";
}
<div class=""text-center"">
<h1 class=""display-4"">Welcome</h1>
<p>Learn about<a href= ""https://docs.microsoft.com/aspnet/core"" > building Web apps with ASP.NET Core</a>.</p>
</div>
<all Bar=""Foo""></all>
<form asp-route=""register"" method=""post"">
<input name=""regular input"" />
</form>
", cssScope: "TestCssScope");

// Assert
var intermediate = generated.CodeDocument.GetDocumentIntermediateNode();
var csharp = generated.CodeDocument.GetCSharpDocument();
AssertDocumentNodeMatchesBaseline(intermediate);
AssertCSharpDocumentMatchesBaseline(csharp);
CompileToAssembly(generated);
}

[Fact]
public void RazorView_WithCssScope()
{
// Arrange
AddCSharpSyntaxTree($@"
[{typeof(HtmlTargetElementAttribute).FullName}({"\"all\""})]
public class AllTagHelper : {typeof(TagHelper).FullName}
{{
public string Bar {{ get; set; }}
}}

[{typeof(HtmlTargetElementAttribute).FullName}({"\"form\""})]
public class FormTagHelper : {typeof(TagHelper).FullName}
{{
}}
");

// Act
// This test case attempts to use all syntaxes that might interact with auto-generated attributes
var generated = CompileToCSharp(@"@addTagHelper *, AppCode
@{
ViewData[""Title""] = ""Home page"";
}
<div class=""text-center"">
<h1 class=""display-4"">Welcome</h1>
<p>Learn about<a href= ""https://docs.microsoft.com/aspnet/core"" > building Web apps with ASP.NET Core</a>.</p>
</div>
<all Bar=""Foo""></all>
<form asp-route=""register"" method=""post"">
<input name=""regular input"" />
</form>
", cssScope: "TestCssScope");

// Assert
var intermediate = generated.CodeDocument.GetDocumentIntermediateNode();
var csharp = generated.CodeDocument.GetCSharpDocument();
AssertDocumentNodeMatchesBaseline(intermediate);
AssertCSharpDocumentMatchesBaseline(csharp);
CompileToAssembly(generated);
}

#endregion

#region DesignTime
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#pragma checksum "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "49d2096aaab8b6d729072d0a3bd7f0417de686ed"
// <auto-generated/>
#pragma warning disable 1591
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), @"mvc.1.0.razor-page", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")]
namespace AspNetCore
{
#line hidden
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;
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"49d2096aaab8b6d729072d0a3bd7f0417de686ed", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")]
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.RazorPages.Page
{
private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_0 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("Bar", "Foo", global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_1 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("asp-route", new global::Microsoft.AspNetCore.Html.HtmlString("register"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_2 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("method", new global::Microsoft.AspNetCore.Html.HtmlString("post"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
#pragma warning disable 0169
private string __tagHelperStringValueBuffer;
#pragma warning restore 0169
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager
{
get
{
if (__backed__tagHelperScopeManager == null)
{
__backed__tagHelperScopeManager = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager(StartTagHelperWritingScope, EndTagHelperWritingScope);
}
return __backed__tagHelperScopeManager;
}
}
private global::AllTagHelper __AllTagHelper;
private global::FormTagHelper __FormTagHelper;
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
#nullable restore
#line 3 "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml"

ViewData["Title"] = "Home page";

#line default
#line hidden
#nullable disable
WriteLiteral("<div TestCssScope class=\"text-center\">\r\n <h1 TestCssScope class=\"display-4\">Welcome</h1>\r\n <p TestCssScope>Learn about<a TestCssScope href= \"https://docs.microsoft.com/aspnet/core\" > building Web apps with ASP.NET Core</a>.</p>\r\n</div>\r\n");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("all", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => {
}
);
__AllTagHelper = CreateTagHelper<global::AllTagHelper>();
__tagHelperExecutionContext.Add(__AllTagHelper);
__AllTagHelper.Bar = (string)__tagHelperAttribute_0.Value;
__tagHelperExecutionContext.AddTagHelperAttribute(__tagHelperAttribute_0);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
if (!__tagHelperExecutionContext.Output.IsContentModified)
{
await __tagHelperExecutionContext.SetOutputContentAsync();
}
Write(__tagHelperExecutionContext.Output);
__tagHelperExecutionContext = __tagHelperScopeManager.End();
WriteLiteral("\r\n");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("form", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => {
WriteLiteral("\r\n <input TestCssScope name=\"regular input\" />\r\n");
}
);
__FormTagHelper = CreateTagHelper<global::FormTagHelper>();
__tagHelperExecutionContext.Add(__FormTagHelper);
__tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1);
__tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
if (!__tagHelperExecutionContext.Output.IsContentModified)
{
await __tagHelperExecutionContext.SetOutputContentAsync();
}
Write(__tagHelperExecutionContext.Output);
__tagHelperExecutionContext = __tagHelperScopeManager.End();
WriteLiteral("\r\n");
}
#pragma warning restore 1998
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test> Html { get; private set; }
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test> ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test>)PageContext?.ViewData;
public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model;
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Document -
RazorCompiledItemAttribute -
NamespaceDeclaration - - AspNetCore
UsingDirective - (1:0,1 [14] ) - System
UsingDirective - (16:1,1 [34] ) - System.Collections.Generic
UsingDirective - (51:2,1 [19] ) - System.Linq
UsingDirective - (71:3,1 [30] ) - System.Threading.Tasks
UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc
UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering
UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures
RazorSourceChecksumAttribute -
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - global::Microsoft.AspNetCore.Mvc.RazorPages.Page -
PreallocatedTagHelperPropertyValue - - __tagHelperAttribute_0 - Bar - Foo - HtmlAttributeValueStyle.DoubleQuotes
PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_1 - asp-route - register - HtmlAttributeValueStyle.DoubleQuotes
PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_2 - method - post - HtmlAttributeValueStyle.DoubleQuotes
DefaultTagHelperRuntime -
FieldDeclaration - - private - global::AllTagHelper - __AllTagHelper
FieldDeclaration - - private - global::FormTagHelper - __FormTagHelper
MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync
CSharpCode - (35:2,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (35:2,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - \n ViewData["Title"] = "Home page";\n
HtmlContent - (78:5,0 [191] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (78:5,0 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <div
IntermediateToken - - Html - TestCssScope
LazyIntermediateToken - (82:5,4 [20] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - class="text-center"
LazyIntermediateToken - (102:5,24 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
LazyIntermediateToken - (103:5,25 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (109:6,4 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <h1
IntermediateToken - - Html - TestCssScope
LazyIntermediateToken - (112:6,7 [18] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - class="display-4"
LazyIntermediateToken - (130:6,25 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
LazyIntermediateToken - (131:6,26 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Welcome
LazyIntermediateToken - (138:6,33 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </h1>
LazyIntermediateToken - (143:6,38 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (149:7,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <p
IntermediateToken - - Html - TestCssScope
LazyIntermediateToken - (151:7,6 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
LazyIntermediateToken - (152:7,7 [11] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Learn about
LazyIntermediateToken - (163:7,18 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <a
IntermediateToken - - Html - TestCssScope
LazyIntermediateToken - (165:7,20 [47] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - href= "https://docs.microsoft.com/aspnet/core"
LazyIntermediateToken - (212:7,67 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
LazyIntermediateToken - (213:7,68 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
LazyIntermediateToken - (214:7,69 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - building Web apps with ASP.NET Core
LazyIntermediateToken - (250:7,105 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </a>
LazyIntermediateToken - (254:7,109 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - .
LazyIntermediateToken - (255:7,110 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </p>
LazyIntermediateToken - (259:7,114 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (261:8,0 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </div>
LazyIntermediateToken - (267:8,6 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
TagHelper - (269:9,0 [21] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - all - TagMode.StartTagAndEndTag
DefaultTagHelperBody -
DefaultTagHelperCreate - - AllTagHelper
PreallocatedTagHelperProperty - (279:9,10 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - __tagHelperAttribute_0 - Bar - Bar
DefaultTagHelperExecute -
HtmlContent - (290:9,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (290:9,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
TagHelper - (292:10,0 [84] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - form - TagMode.StartTagAndEndTag
DefaultTagHelperBody -
HtmlContent - (333:10,41 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (333:10,41 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (337:11,2 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <input
IntermediateToken - - Html - TestCssScope
LazyIntermediateToken - (343:11,8 [21] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - name="regular input"
LazyIntermediateToken - (364:11,29 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
LazyIntermediateToken - (365:11,30 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - />
LazyIntermediateToken - (367:11,32 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
DefaultTagHelperCreate - - FormTagHelper
PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_1
PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_2
DefaultTagHelperExecute -
HtmlContent - (376:12,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (376:12,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
Inject -
Inject -
Inject -
Inject -
Inject -
CSharpCode -
IntermediateToken - - CSharp - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test> ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test>)PageContext?.ViewData;
CSharpCode -
IntermediateToken - - CSharp - public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model;
Loading