diff --git a/Razor.Multitargeting.sln b/Razor.Multitargeting.sln new file mode 100644 index 0000000000..ed30737f85 --- /dev/null +++ b/Razor.Multitargeting.sln @@ -0,0 +1,287 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26802.3001 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3C0D6505-79B3-49D0-B4C3-176F0F1836ED}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{92463391-81BE-462B-AC3C-78C6C760741F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor", "src\Microsoft.AspNetCore.Razor\Microsoft.AspNetCore.Razor.csproj", "{EDA30434-C567-44DC-B8B6-2566A7F77163}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Runtime", "src\Microsoft.AspNetCore.Razor.Runtime\Microsoft.AspNetCore.Razor.Runtime.csproj", "{D0196096-1B01-4133-AACE-1A10A0F7247C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F8C12DD6-659D-405A-AA27-FB22AD92A010}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + build\common.props = build\common.props + build\dependencies.props = build\dependencies.props + NuGet.config = NuGet.config + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPageGenerator", "src\RazorPageGenerator\RazorPageGenerator.csproj", "{7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Language", "src\Microsoft.AspNetCore.Razor.Language\Microsoft.AspNetCore.Razor.Language.csproj", "{932F3C9C-A6C0-40D3-BA50-9309886242FC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Language.Test", "test\Microsoft.AspNetCore.Razor.Language.Test\Microsoft.AspNetCore.Razor.Language.Test.csproj", "{969357A4-CCF1-46D9-B002-9AA072AFC75C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Runtime.Test", "test\Microsoft.AspNetCore.Razor.Runtime.Test\Microsoft.AspNetCore.Razor.Runtime.Test.csproj", "{277AB67E-9C8D-4799-A18C-C628E70A8664}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Razor.Workspaces", "src\Microsoft.CodeAnalysis.Razor.Workspaces\Microsoft.CodeAnalysis.Razor.Workspaces.csproj", "{0F265874-C592-448B-BC4F-3430AB03E0DC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Remote.Razor", "src\Microsoft.CodeAnalysis.Remote.Razor\Microsoft.CodeAnalysis.Remote.Razor.csproj", "{4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tooling", "tooling", "{C0CC1E1F-1559-44DE-93A8-63259CEA2AAB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.VisualStudio.RazorExtension", "tooling\Microsoft.VisualStudio.RazorExtension\Microsoft.VisualStudio.RazorExtension.csproj", "{D66B45B5-CBFD-4947-81F1-F30AB80EA992}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Razor", "src\Microsoft.CodeAnalysis.Razor\Microsoft.CodeAnalysis.Razor.csproj", "{42403DAF-F0BC-4F3A-B7F2-46D7013345D8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Razor.Test", "test\Microsoft.CodeAnalysis.Razor.Test\Microsoft.CodeAnalysis.Razor.Test.csproj", "{7A8A1664-37CE-4376-81CA-1862CF5F91D9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.LanguageServices.Razor", "src\Microsoft.VisualStudio.LanguageServices.Razor\Microsoft.VisualStudio.LanguageServices.Razor.csproj", "{E5D92DB7-5CBF-410A-9685-FF76F71EC96F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPageGenerator.Test", "test\RazorPageGenerator.Test\RazorPageGenerator.Test.csproj", "{96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.LanguageServices.Razor.Test", "test\Microsoft.VisualStudio.LanguageServices.Razor.Test\Microsoft.VisualStudio.LanguageServices.Razor.Test.csproj", "{37E61BDB-658E-4F44-A499-D64CC6D35485}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Razor.Extensions", "src\Microsoft.AspNetCore.Mvc.Razor.Extensions\Microsoft.AspNetCore.Mvc.Razor.Extensions.csproj", "{995F2FEB-65FA-4399-B1C0-16E0B3FBDB15}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Razor.Extensions.Test", "test\Microsoft.AspNetCore.Mvc.Razor.Extensions.Test\Microsoft.AspNetCore.Mvc.Razor.Extensions.Test.csproj", "{7CFD5646-A757-4498-9E01-9C8528ED60AE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Test.Common", "test\Microsoft.AspNetCore.Razor.Test.Common\Microsoft.AspNetCore.Razor.Test.Common.csproj", "{078AEF36-F319-4CE2-BAA2-5B58A6536B46}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Performance", "test\Microsoft.AspNetCore.Razor.Performance\Microsoft.AspNetCore.Razor.Performance.csproj", "{82C23CF8-95FF-40F7-BF50-3AD9EE21ED58}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Test.MvcShim", "test\Microsoft.AspNetCore.Razor.Test.MvcShim\Microsoft.AspNetCore.Razor.Test.MvcShim.csproj", "{8F165A3F-A18C-4649-AA08-C0E1BA5F5C90}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Razor.Workspaces.Test", "test\Microsoft.CodeAnalysis.Razor.Workspaces.Test\Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj", "{C61AAE12-5007-4205-A220-68F354A7F235}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X", "src\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.csproj", "{F1538809-7347-45D2-A7AC-C1D89CF0BBD4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test", "test\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test.csproj", "{296D4516-0323-4D28-955D-B0324E4F10BE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X", "test\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.csproj", "{AC5CA24B-B81E-4B20-B193-2E3983B1896C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + DebugNoVSIX|Any CPU = DebugNoVSIX|Any CPU + Release|Any CPU = Release|Any CPU + ReleaseNoVSIX|Any CPU = ReleaseNoVSIX|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EDA30434-C567-44DC-B8B6-2566A7F77163}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDA30434-C567-44DC-B8B6-2566A7F77163}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDA30434-C567-44DC-B8B6-2566A7F77163}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {EDA30434-C567-44DC-B8B6-2566A7F77163}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {EDA30434-C567-44DC-B8B6-2566A7F77163}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EDA30434-C567-44DC-B8B6-2566A7F77163}.Release|Any CPU.Build.0 = Release|Any CPU + {EDA30434-C567-44DC-B8B6-2566A7F77163}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {EDA30434-C567-44DC-B8B6-2566A7F77163}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {D0196096-1B01-4133-AACE-1A10A0F7247C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D0196096-1B01-4133-AACE-1A10A0F7247C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D0196096-1B01-4133-AACE-1A10A0F7247C}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {D0196096-1B01-4133-AACE-1A10A0F7247C}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {D0196096-1B01-4133-AACE-1A10A0F7247C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D0196096-1B01-4133-AACE-1A10A0F7247C}.Release|Any CPU.Build.0 = Release|Any CPU + {D0196096-1B01-4133-AACE-1A10A0F7247C}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {D0196096-1B01-4133-AACE-1A10A0F7247C}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.Release|Any CPU.Build.0 = Release|Any CPU + {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {932F3C9C-A6C0-40D3-BA50-9309886242FC}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {932F3C9C-A6C0-40D3-BA50-9309886242FC}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {932F3C9C-A6C0-40D3-BA50-9309886242FC}.Release|Any CPU.Build.0 = Release|Any CPU + {932F3C9C-A6C0-40D3-BA50-9309886242FC}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {932F3C9C-A6C0-40D3-BA50-9309886242FC}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {969357A4-CCF1-46D9-B002-9AA072AFC75C}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {969357A4-CCF1-46D9-B002-9AA072AFC75C}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {969357A4-CCF1-46D9-B002-9AA072AFC75C}.Release|Any CPU.Build.0 = Release|Any CPU + {969357A4-CCF1-46D9-B002-9AA072AFC75C}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {969357A4-CCF1-46D9-B002-9AA072AFC75C}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {277AB67E-9C8D-4799-A18C-C628E70A8664}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {277AB67E-9C8D-4799-A18C-C628E70A8664}.Debug|Any CPU.Build.0 = Debug|Any CPU + {277AB67E-9C8D-4799-A18C-C628E70A8664}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {277AB67E-9C8D-4799-A18C-C628E70A8664}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {277AB67E-9C8D-4799-A18C-C628E70A8664}.Release|Any CPU.ActiveCfg = Release|Any CPU + {277AB67E-9C8D-4799-A18C-C628E70A8664}.Release|Any CPU.Build.0 = Release|Any CPU + {277AB67E-9C8D-4799-A18C-C628E70A8664}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {277AB67E-9C8D-4799-A18C-C628E70A8664}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {0F265874-C592-448B-BC4F-3430AB03E0DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F265874-C592-448B-BC4F-3430AB03E0DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F265874-C592-448B-BC4F-3430AB03E0DC}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {0F265874-C592-448B-BC4F-3430AB03E0DC}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {0F265874-C592-448B-BC4F-3430AB03E0DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F265874-C592-448B-BC4F-3430AB03E0DC}.Release|Any CPU.Build.0 = Release|Any CPU + {0F265874-C592-448B-BC4F-3430AB03E0DC}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {0F265874-C592-448B-BC4F-3430AB03E0DC}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4}.Release|Any CPU.Build.0 = Release|Any CPU + {4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {D66B45B5-CBFD-4947-81F1-F30AB80EA992}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D66B45B5-CBFD-4947-81F1-F30AB80EA992}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D66B45B5-CBFD-4947-81F1-F30AB80EA992}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {D66B45B5-CBFD-4947-81F1-F30AB80EA992}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D66B45B5-CBFD-4947-81F1-F30AB80EA992}.Release|Any CPU.Build.0 = Release|Any CPU + {D66B45B5-CBFD-4947-81F1-F30AB80EA992}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {42403DAF-F0BC-4F3A-B7F2-46D7013345D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {42403DAF-F0BC-4F3A-B7F2-46D7013345D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {42403DAF-F0BC-4F3A-B7F2-46D7013345D8}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {42403DAF-F0BC-4F3A-B7F2-46D7013345D8}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {42403DAF-F0BC-4F3A-B7F2-46D7013345D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {42403DAF-F0BC-4F3A-B7F2-46D7013345D8}.Release|Any CPU.Build.0 = Release|Any CPU + {42403DAF-F0BC-4F3A-B7F2-46D7013345D8}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {42403DAF-F0BC-4F3A-B7F2-46D7013345D8}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {7A8A1664-37CE-4376-81CA-1862CF5F91D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A8A1664-37CE-4376-81CA-1862CF5F91D9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A8A1664-37CE-4376-81CA-1862CF5F91D9}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {7A8A1664-37CE-4376-81CA-1862CF5F91D9}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {7A8A1664-37CE-4376-81CA-1862CF5F91D9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A8A1664-37CE-4376-81CA-1862CF5F91D9}.Release|Any CPU.Build.0 = Release|Any CPU + {7A8A1664-37CE-4376-81CA-1862CF5F91D9}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {7A8A1664-37CE-4376-81CA-1862CF5F91D9}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {E5D92DB7-5CBF-410A-9685-FF76F71EC96F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5D92DB7-5CBF-410A-9685-FF76F71EC96F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5D92DB7-5CBF-410A-9685-FF76F71EC96F}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {E5D92DB7-5CBF-410A-9685-FF76F71EC96F}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {E5D92DB7-5CBF-410A-9685-FF76F71EC96F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5D92DB7-5CBF-410A-9685-FF76F71EC96F}.Release|Any CPU.Build.0 = Release|Any CPU + {E5D92DB7-5CBF-410A-9685-FF76F71EC96F}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {E5D92DB7-5CBF-410A-9685-FF76F71EC96F}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63}.Debug|Any CPU.Build.0 = Debug|Any CPU + {96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63}.Release|Any CPU.ActiveCfg = Release|Any CPU + {96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63}.Release|Any CPU.Build.0 = Release|Any CPU + {96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {37E61BDB-658E-4F44-A499-D64CC6D35485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37E61BDB-658E-4F44-A499-D64CC6D35485}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37E61BDB-658E-4F44-A499-D64CC6D35485}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {37E61BDB-658E-4F44-A499-D64CC6D35485}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {37E61BDB-658E-4F44-A499-D64CC6D35485}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37E61BDB-658E-4F44-A499-D64CC6D35485}.Release|Any CPU.Build.0 = Release|Any CPU + {37E61BDB-658E-4F44-A499-D64CC6D35485}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {37E61BDB-658E-4F44-A499-D64CC6D35485}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {995F2FEB-65FA-4399-B1C0-16E0B3FBDB15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {995F2FEB-65FA-4399-B1C0-16E0B3FBDB15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {995F2FEB-65FA-4399-B1C0-16E0B3FBDB15}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {995F2FEB-65FA-4399-B1C0-16E0B3FBDB15}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {995F2FEB-65FA-4399-B1C0-16E0B3FBDB15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {995F2FEB-65FA-4399-B1C0-16E0B3FBDB15}.Release|Any CPU.Build.0 = Release|Any CPU + {995F2FEB-65FA-4399-B1C0-16E0B3FBDB15}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {995F2FEB-65FA-4399-B1C0-16E0B3FBDB15}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {7CFD5646-A757-4498-9E01-9C8528ED60AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7CFD5646-A757-4498-9E01-9C8528ED60AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7CFD5646-A757-4498-9E01-9C8528ED60AE}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {7CFD5646-A757-4498-9E01-9C8528ED60AE}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {7CFD5646-A757-4498-9E01-9C8528ED60AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7CFD5646-A757-4498-9E01-9C8528ED60AE}.Release|Any CPU.Build.0 = Release|Any CPU + {7CFD5646-A757-4498-9E01-9C8528ED60AE}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {7CFD5646-A757-4498-9E01-9C8528ED60AE}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {078AEF36-F319-4CE2-BAA2-5B58A6536B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {078AEF36-F319-4CE2-BAA2-5B58A6536B46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {078AEF36-F319-4CE2-BAA2-5B58A6536B46}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {078AEF36-F319-4CE2-BAA2-5B58A6536B46}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {078AEF36-F319-4CE2-BAA2-5B58A6536B46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {078AEF36-F319-4CE2-BAA2-5B58A6536B46}.Release|Any CPU.Build.0 = Release|Any CPU + {078AEF36-F319-4CE2-BAA2-5B58A6536B46}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {078AEF36-F319-4CE2-BAA2-5B58A6536B46}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {82C23CF8-95FF-40F7-BF50-3AD9EE21ED58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82C23CF8-95FF-40F7-BF50-3AD9EE21ED58}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82C23CF8-95FF-40F7-BF50-3AD9EE21ED58}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {82C23CF8-95FF-40F7-BF50-3AD9EE21ED58}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {82C23CF8-95FF-40F7-BF50-3AD9EE21ED58}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82C23CF8-95FF-40F7-BF50-3AD9EE21ED58}.Release|Any CPU.Build.0 = Release|Any CPU + {82C23CF8-95FF-40F7-BF50-3AD9EE21ED58}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {82C23CF8-95FF-40F7-BF50-3AD9EE21ED58}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {8F165A3F-A18C-4649-AA08-C0E1BA5F5C90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F165A3F-A18C-4649-AA08-C0E1BA5F5C90}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F165A3F-A18C-4649-AA08-C0E1BA5F5C90}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {8F165A3F-A18C-4649-AA08-C0E1BA5F5C90}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {8F165A3F-A18C-4649-AA08-C0E1BA5F5C90}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F165A3F-A18C-4649-AA08-C0E1BA5F5C90}.Release|Any CPU.Build.0 = Release|Any CPU + {8F165A3F-A18C-4649-AA08-C0E1BA5F5C90}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {8F165A3F-A18C-4649-AA08-C0E1BA5F5C90}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {C61AAE12-5007-4205-A220-68F354A7F235}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C61AAE12-5007-4205-A220-68F354A7F235}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C61AAE12-5007-4205-A220-68F354A7F235}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {C61AAE12-5007-4205-A220-68F354A7F235}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {C61AAE12-5007-4205-A220-68F354A7F235}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C61AAE12-5007-4205-A220-68F354A7F235}.Release|Any CPU.Build.0 = Release|Any CPU + {C61AAE12-5007-4205-A220-68F354A7F235}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {C61AAE12-5007-4205-A220-68F354A7F235}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {F1538809-7347-45D2-A7AC-C1D89CF0BBD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1538809-7347-45D2-A7AC-C1D89CF0BBD4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1538809-7347-45D2-A7AC-C1D89CF0BBD4}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {F1538809-7347-45D2-A7AC-C1D89CF0BBD4}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {F1538809-7347-45D2-A7AC-C1D89CF0BBD4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1538809-7347-45D2-A7AC-C1D89CF0BBD4}.Release|Any CPU.Build.0 = Release|Any CPU + {F1538809-7347-45D2-A7AC-C1D89CF0BBD4}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {F1538809-7347-45D2-A7AC-C1D89CF0BBD4}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {296D4516-0323-4D28-955D-B0324E4F10BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {296D4516-0323-4D28-955D-B0324E4F10BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {296D4516-0323-4D28-955D-B0324E4F10BE}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {296D4516-0323-4D28-955D-B0324E4F10BE}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {296D4516-0323-4D28-955D-B0324E4F10BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {296D4516-0323-4D28-955D-B0324E4F10BE}.Release|Any CPU.Build.0 = Release|Any CPU + {296D4516-0323-4D28-955D-B0324E4F10BE}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {296D4516-0323-4D28-955D-B0324E4F10BE}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + {AC5CA24B-B81E-4B20-B193-2E3983B1896C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC5CA24B-B81E-4B20-B193-2E3983B1896C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC5CA24B-B81E-4B20-B193-2E3983B1896C}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU + {AC5CA24B-B81E-4B20-B193-2E3983B1896C}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU + {AC5CA24B-B81E-4B20-B193-2E3983B1896C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC5CA24B-B81E-4B20-B193-2E3983B1896C}.Release|Any CPU.Build.0 = Release|Any CPU + {AC5CA24B-B81E-4B20-B193-2E3983B1896C}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU + {AC5CA24B-B81E-4B20-B193-2E3983B1896C}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {EDA30434-C567-44DC-B8B6-2566A7F77163} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {D0196096-1B01-4133-AACE-1A10A0F7247C} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {7BE58880-36AD-4CD5-9E16-2A5AFEA790EF} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {932F3C9C-A6C0-40D3-BA50-9309886242FC} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {969357A4-CCF1-46D9-B002-9AA072AFC75C} = {92463391-81BE-462B-AC3C-78C6C760741F} + {277AB67E-9C8D-4799-A18C-C628E70A8664} = {92463391-81BE-462B-AC3C-78C6C760741F} + {0F265874-C592-448B-BC4F-3430AB03E0DC} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {4EAD959D-73B2-4FB2-B46F-16CEB1EF49D4} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {D66B45B5-CBFD-4947-81F1-F30AB80EA992} = {C0CC1E1F-1559-44DE-93A8-63259CEA2AAB} + {42403DAF-F0BC-4F3A-B7F2-46D7013345D8} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {7A8A1664-37CE-4376-81CA-1862CF5F91D9} = {92463391-81BE-462B-AC3C-78C6C760741F} + {E5D92DB7-5CBF-410A-9685-FF76F71EC96F} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {96EB1BD4-B8E0-4F52-A068-BBCACA7E3F63} = {92463391-81BE-462B-AC3C-78C6C760741F} + {37E61BDB-658E-4F44-A499-D64CC6D35485} = {92463391-81BE-462B-AC3C-78C6C760741F} + {995F2FEB-65FA-4399-B1C0-16E0B3FBDB15} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {7CFD5646-A757-4498-9E01-9C8528ED60AE} = {92463391-81BE-462B-AC3C-78C6C760741F} + {078AEF36-F319-4CE2-BAA2-5B58A6536B46} = {92463391-81BE-462B-AC3C-78C6C760741F} + {82C23CF8-95FF-40F7-BF50-3AD9EE21ED58} = {92463391-81BE-462B-AC3C-78C6C760741F} + {8F165A3F-A18C-4649-AA08-C0E1BA5F5C90} = {92463391-81BE-462B-AC3C-78C6C760741F} + {C61AAE12-5007-4205-A220-68F354A7F235} = {92463391-81BE-462B-AC3C-78C6C760741F} + {F1538809-7347-45D2-A7AC-C1D89CF0BBD4} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED} + {296D4516-0323-4D28-955D-B0324E4F10BE} = {92463391-81BE-462B-AC3C-78C6C760741F} + {AC5CA24B-B81E-4B20-B193-2E3983B1896C} = {92463391-81BE-462B-AC3C-78C6C760741F} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0035341D-175A-4D05-95E6-F1C2785A1E26} + EndGlobalSection +EndGlobal diff --git a/build/repo.props b/build/repo.props index ebb303b291..0682648647 100644 --- a/build/repo.props +++ b/build/repo.props @@ -4,5 +4,7 @@ + + diff --git a/build/repo.targets b/build/repo.targets index b56c922230..dff5b9de57 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -1,7 +1,7 @@ - + Configuration=$(Configuration)NoVSIX diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/CSharpIdentifier.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/CSharpIdentifier.cs new file mode 100644 index 0000000000..dc3183ba1d --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/CSharpIdentifier.cs @@ -0,0 +1,63 @@ +// 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.Globalization; +using System.Text; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + internal static class CSharpIdentifier + { + public static string GetClassNameFromPath(string path) + { + if (string.IsNullOrEmpty(path)) + { + return path; + } + + return SanitizeClassName(path); + } + + // CSharp Spec §2.4.2 + private static bool IsIdentifierStart(char character) + { + return char.IsLetter(character) || + character == '_' || + CharUnicodeInfo.GetUnicodeCategory(character) == UnicodeCategory.LetterNumber; + } + + public static bool IsIdentifierPart(char character) + { + return char.IsDigit(character) || + IsIdentifierStart(character) || + IsIdentifierPartByUnicodeCategory(character); + } + + private static bool IsIdentifierPartByUnicodeCategory(char character) + { + var category = CharUnicodeInfo.GetUnicodeCategory(character); + + return category == UnicodeCategory.NonSpacingMark || // Mn + category == UnicodeCategory.SpacingCombiningMark || // Mc + category == UnicodeCategory.ConnectorPunctuation || // Pc + category == UnicodeCategory.Format; // Cf + } + + public static string SanitizeClassName(string inputName) + { + if (!IsIdentifierStart(inputName[0]) && IsIdentifierPart(inputName[0])) + { + inputName = "_" + inputName; + } + + var builder = new StringBuilder(inputName.Length); + for (var i = 0; i < inputName.Length; i++) + { + var ch = inputName[i]; + builder.Append(IsIdentifierPart(ch) ? ch : '_'); + } + + return builder.ToString(); + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/IInjectTargetExtension.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/IInjectTargetExtension.cs new file mode 100644 index 0000000000..781932ba8c --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/IInjectTargetExtension.cs @@ -0,0 +1,12 @@ +// 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.CodeGeneration; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public interface IInjectTargetExtension : ICodeTargetExtension + { + void WriteInjectProperty(CodeRenderingContext context, InjectIntermediateNode node); + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/InjectDirective.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/InjectDirective.cs new file mode 100644 index 0000000000..a98c45780b --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/InjectDirective.cs @@ -0,0 +1,99 @@ +// 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; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public static class InjectDirective + { + public static readonly DirectiveDescriptor Directive = DirectiveDescriptor.CreateDirective( + "inject", + DirectiveKind.SingleLine, + builder => + { + builder.AddTypeToken().AddMemberToken(); + builder.Usage = DirectiveUsage.FileScopedMultipleOccurring; + }); + + public static IRazorEngineBuilder Register(IRazorEngineBuilder builder) + { + builder.AddDirective(Directive); + builder.Features.Add(new Pass()); + builder.AddTargetExtension(new InjectTargetExtension()); + return builder; + } + + internal class Pass : IntermediateNodePassBase, IRazorDirectiveClassifierPass + { + // Runs after the @model and @namespace directives + public override int Order => 10; + + protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) + { + var visitor = new Visitor(); + visitor.Visit(documentNode); + var modelType = ModelDirective.GetModelType(documentNode); + + var properties = new HashSet(StringComparer.Ordinal); + + for (var i = visitor.Directives.Count - 1; i >= 0; i--) + { + var directive = visitor.Directives[i]; + var tokens = directive.Tokens.ToArray(); + if (tokens.Length < 2) + { + continue; + } + + var typeName = tokens[0].Content; + var memberName = tokens[1].Content; + + if (!properties.Add(memberName)) + { + continue; + } + + typeName = typeName.Replace("", "<" + modelType + ">"); + + var injectNode = new InjectIntermediateNode() + { + TypeName = typeName, + MemberName = memberName, + }; + + visitor.Class.Children.Add(injectNode); + } + } + } + + private class Visitor : IntermediateNodeWalker + { + public ClassDeclarationIntermediateNode Class { get; private set; } + + public IList Directives { get; } = new List(); + + public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node) + { + if (Class == null) + { + Class = node; + } + + base.VisitClassDeclaration(node); + } + + public override void VisitDirective(DirectiveIntermediateNode node) + { + if (node.Directive == Directive) + { + Directives.Add(node); + } + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/InjectIntermediateNode.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/InjectIntermediateNode.cs new file mode 100644 index 0000000000..4405aea120 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/InjectIntermediateNode.cs @@ -0,0 +1,51 @@ +// 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 Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class InjectIntermediateNode : ExtensionIntermediateNode + { + public string TypeName { get; set; } + + public string MemberName { get; set; } + + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; + + public override void Accept(IntermediateNodeVisitor visitor) + { + if (visitor == null) + { + throw new ArgumentNullException(nameof(visitor)); + } + + AcceptExtensionNode(this, visitor); + } + + public override void WriteNode(CodeTarget target, CodeRenderingContext context) + { + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var extension = target.GetExtension(); + if (extension == null) + { + ReportMissingCodeTargetExtension(context); + return; + } + + extension.WriteInjectProperty(context, this); + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/InjectTargetExtension.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/InjectTargetExtension.cs new file mode 100644 index 0000000000..23effb4081 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/InjectTargetExtension.cs @@ -0,0 +1,44 @@ +// 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 Microsoft.AspNetCore.Razor.Language.CodeGeneration; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class InjectTargetExtension : IInjectTargetExtension + { + private const string RazorInjectAttribute = "[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]"; + + public void WriteInjectProperty(CodeRenderingContext context, InjectIntermediateNode node) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (node == null) + { + throw new ArgumentNullException(nameof(node)); + } + + var property = $"public {node.TypeName} {node.MemberName} {{ get; private set; }}"; + + if (node.Source.HasValue) + { + using (context.CodeWriter.BuildLinePragma(node.Source.Value)) + { + context.CodeWriter + .WriteLine(RazorInjectAttribute) + .WriteLine(property); + } + } + else + { + context.CodeWriter + .WriteLine(RazorInjectAttribute) + .WriteLine(property); + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/LegacySectionTargetExtension.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/LegacySectionTargetExtension.cs new file mode 100644 index 0000000000..52698cdfe8 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/LegacySectionTargetExtension.cs @@ -0,0 +1,32 @@ +// 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.CodeGeneration; + +namespace Microsoft.AspNetCore.Razor.Language.Extensions +{ + internal class LegacySectionTargetExtension : ISectionTargetExtension + { + private static readonly string DefaultWriterName = "__razor_section_writer"; + + public static readonly string DefaultSectionMethodName = "DefineSection"; + + public string SectionMethodName { get; set; } = DefaultSectionMethodName; + + public void WriteSection(CodeRenderingContext context, SectionIntermediateNode node) + { + context.CodeWriter + .WriteStartMethodInvocation(SectionMethodName) + .Write("\"") + .Write(node.SectionName) + .Write("\", "); + + using (context.CodeWriter.BuildAsyncLambda(DefaultWriterName)) + { + context.RenderChildren(node); + } + + context.CodeWriter.WriteEndMethodInvocation(endLine: true); + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.csproj b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.csproj new file mode 100644 index 0000000000..6298ff78bc --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.csproj @@ -0,0 +1,28 @@ + + + + + + ASP.NET Core design time hosting infrastructure for the Razor view engine. + net46;netstandard2.0 + $(NoWarn);CS1591 + true + aspnetcore;aspnetcoremvc;cshtml;razor + + + + + Shared\CodeWriterExtensions.cs + + + + + + + + + + + + + diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ModelDirective.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ModelDirective.cs new file mode 100644 index 0000000000..44aeb40f93 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ModelDirective.cs @@ -0,0 +1,131 @@ +// 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; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public static class ModelDirective + { + public static readonly DirectiveDescriptor Directive = DirectiveDescriptor.CreateDirective( + "model", + DirectiveKind.SingleLine, + builder => + { + builder.AddTypeToken(); + builder.Usage = DirectiveUsage.FileScopedSinglyOccurring; + }); + + public static IRazorEngineBuilder Register(IRazorEngineBuilder builder) + { + builder.AddDirective(Directive); + builder.Features.Add(new Pass(builder.DesignTime)); + return builder; + } + + public static string GetModelType(DocumentIntermediateNode document) + { + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + + var visitor = new Visitor(); + return GetModelType(document, visitor); + } + + private static string GetModelType(DocumentIntermediateNode document, Visitor visitor) + { + visitor.Visit(document); + + for (var i = visitor.ModelDirectives.Count - 1; i >= 0; i--) + { + var directive = visitor.ModelDirectives[i]; + + var tokens = directive.Tokens.ToArray(); + if (tokens.Length >= 1) + { + return tokens[0].Content; + } + } + + return "dynamic"; + } + + internal class Pass : IntermediateNodePassBase, IRazorDirectiveClassifierPass + { + private readonly bool _designTime; + + public Pass(bool designTime) + { + _designTime = designTime; + } + + // Runs after the @inherits directive + public override int Order => 5; + + protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) + { + var visitor = new Visitor(); + var modelType = GetModelType(documentNode, visitor); + + if (_designTime) + { + // Alias the TModel token to a known type. + // This allows design time compilation to succeed for Razor files where the token isn't replaced. + var typeName = $"global::{typeof(object).FullName}"; + var usingNode = new UsingDirectiveIntermediateNode() + { + Content = $"TModel = {typeName}" + }; + + visitor.Namespace?.Children.Insert(0, usingNode); + } + + var baseType = visitor.Class?.BaseType?.Replace("", "<" + modelType + ">"); + visitor.Class.BaseType = baseType; + } + } + + private class Visitor : IntermediateNodeWalker + { + public NamespaceDeclarationIntermediateNode Namespace { get; private set; } + + public ClassDeclarationIntermediateNode Class { get; private set; } + + public IList ModelDirectives { get; } = new List(); + + public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node) + { + if (Namespace == null) + { + Namespace = node; + } + + base.VisitNamespaceDeclaration(node); + } + + public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node) + { + if (Class == null) + { + Class = node; + } + + base.VisitClassDeclaration(node); + } + + public override void VisitDirective(DirectiveIntermediateNode node) + { + if (node.Directive == Directive) + { + ModelDirectives.Add(node); + } + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ModelExpressionPass.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ModelExpressionPass.cs new file mode 100644 index 0000000000..c943afe5bc --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ModelExpressionPass.cs @@ -0,0 +1,85 @@ +// 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.Text; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class ModelExpressionPass : IntermediateNodePassBase, IRazorOptimizationPass + { + private const string ModelExpressionTypeName = "Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression"; + + protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) + { + var visitor = new Visitor(); + visitor.Visit(documentNode); + } + + private class Visitor : IntermediateNodeWalker + { + public List TagHelpers { get; } = new List(); + + public override void VisitTagHelperProperty(TagHelperPropertyIntermediateNode node) + { + if (string.Equals(node.BoundAttribute.TypeName, ModelExpressionTypeName, StringComparison.Ordinal) || + (node.IsIndexerNameMatch && + string.Equals(node.BoundAttribute.IndexerTypeName, ModelExpressionTypeName, StringComparison.Ordinal))) + { + var expression = new CSharpExpressionIntermediateNode(); + + expression.Children.Add(new IntermediateToken() + { + Kind = TokenKind.CSharp, + Content = "ModelExpressionProvider.CreateModelExpression(ViewData, __model => ", + }); + + if (node.Children.Count == 1 && node.Children[0] is IntermediateToken token && token.IsCSharp) + { + // A 'simple' expression will look like __model => __model.Foo + + expression.Children.Add(new IntermediateToken() + { + Kind = TokenKind.CSharp, + Content = "__model." + }); + + expression.Children.Add(token); + } + else + { + for (var i = 0; i < node.Children.Count; i++) + { + if (node.Children[i] is CSharpExpressionIntermediateNode nestedExpression) + { + for (var j = 0; j < nestedExpression.Children.Count; j++) + { + if (nestedExpression.Children[j] is IntermediateToken cSharpToken && + cSharpToken.IsCSharp) + { + expression.Children.Add(cSharpToken); + } + } + + continue; + } + } + } + + expression.Children.Add(new IntermediateToken() + { + Kind = TokenKind.CSharp, + Content = ")", + }); + + node.Children.Clear(); + + node.Children.Add(expression); + } + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/MvcRazorTemplateEngine.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/MvcRazorTemplateEngine.cs new file mode 100644 index 0000000000..442eddddbc --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/MvcRazorTemplateEngine.cs @@ -0,0 +1,64 @@ +// 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 +{ + /// + /// A for Mvc Razor views. + /// + public class MvcRazorTemplateEngine : RazorTemplateEngine + { + /// + /// Initializes a new instance of . + /// + /// The . + /// The . + public MvcRazorTemplateEngine( + RazorEngine engine, + RazorProject project) + : base(engine, project) + { + Options.ImportsFileName = "_ViewImports.cshtml"; + Options.DefaultImports = GetDefaultImports(); + } + + /// + public override RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem) + { + var codeDocument = base.CreateCodeDocument(projectItem); + codeDocument.SetRelativePath(projectItem.FilePath); + + return codeDocument; + } + + // 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 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); + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/MvcViewDocumentClassifierPass.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/MvcViewDocumentClassifierPass.cs new file mode 100644 index 0000000000..6fb18e2641 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/MvcViewDocumentClassifierPass.cs @@ -0,0 +1,42 @@ +// 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; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class MvcViewDocumentClassifierPass : DocumentClassifierPassBase + { + public static readonly string MvcViewDocumentKind = "mvc.1.0.view"; + + protected override string DocumentKind => MvcViewDocumentKind; + + protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) => true; + + protected override void OnDocumentStructureCreated( + RazorCodeDocument codeDocument, + NamespaceDeclarationIntermediateNode @namespace, + ClassDeclarationIntermediateNode @class, + MethodDeclarationIntermediateNode method) + { + var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FilePath; + + base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method); + + @namespace.Content = "AspNetCore"; + + @class.ClassName = CSharpIdentifier.GetClassNameFromPath(filePath); + @class.BaseType = "global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"; + @class.Modifiers.Clear(); + @class.Modifiers.Add("public"); + + method.MethodName = "ExecuteAsync"; + method.Modifiers.Clear(); + method.Modifiers.Add("public"); + method.Modifiers.Add("async"); + method.Modifiers.Add("override"); + method.ReturnType = $"global::{typeof(System.Threading.Tasks.Task).FullName}"; + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..8bed236c69 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// 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.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Properties/Resources.Designer.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..bf80e26862 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Properties/Resources.Designer.cs @@ -0,0 +1,142 @@ +// +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class Resources + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Resources", typeof(Resources).GetTypeInfo().Assembly); + + /// + /// Value cannot be null or empty. + /// + internal static string ArgumentCannotBeNullOrEmpy + { + get => GetString("ArgumentCannotBeNullOrEmpy"); + } + + /// + /// Value cannot be null or empty. + /// + internal static string FormatArgumentCannotBeNullOrEmpy() + => GetString("ArgumentCannotBeNullOrEmpy"); + + /// + /// The 'inherits' keyword is not allowed when a '{0}' keyword is used. + /// + internal static string MvcRazorCodeParser_CannotHaveModelAndInheritsKeyword + { + get => GetString("MvcRazorCodeParser_CannotHaveModelAndInheritsKeyword"); + } + + /// + /// The 'inherits' keyword is not allowed when a '{0}' keyword is used. + /// + internal static string FormatMvcRazorCodeParser_CannotHaveModelAndInheritsKeyword(object p0) + => string.Format(CultureInfo.CurrentCulture, GetString("MvcRazorCodeParser_CannotHaveModelAndInheritsKeyword"), p0); + + /// + /// A property name must be specified when using the '{0}' statement. Format for a '{0}' statement is '@{0} <Type Name> <Property Name>'. + /// + internal static string MvcRazorCodeParser_InjectDirectivePropertyNameRequired + { + get => GetString("MvcRazorCodeParser_InjectDirectivePropertyNameRequired"); + } + + /// + /// A property name must be specified when using the '{0}' statement. Format for a '{0}' statement is '@{0} <Type Name> <Property Name>'. + /// + internal static string FormatMvcRazorCodeParser_InjectDirectivePropertyNameRequired(object p0) + => string.Format(CultureInfo.CurrentCulture, GetString("MvcRazorCodeParser_InjectDirectivePropertyNameRequired"), p0); + + /// + /// The '{0}' keyword must be followed by a type name on the same line. + /// + internal static string MvcRazorCodeParser_KeywordMustBeFollowedByTypeName + { + get => GetString("MvcRazorCodeParser_KeywordMustBeFollowedByTypeName"); + } + + /// + /// The '{0}' keyword must be followed by a type name on the same line. + /// + internal static string FormatMvcRazorCodeParser_KeywordMustBeFollowedByTypeName(object p0) + => string.Format(CultureInfo.CurrentCulture, GetString("MvcRazorCodeParser_KeywordMustBeFollowedByTypeName"), p0); + + /// + /// Only one '{0}' statement is allowed in a file. + /// + internal static string MvcRazorCodeParser_OnlyOneModelStatementIsAllowed + { + get => GetString("MvcRazorCodeParser_OnlyOneModelStatementIsAllowed"); + } + + /// + /// Only one '{0}' statement is allowed in a file. + /// + internal static string FormatMvcRazorCodeParser_OnlyOneModelStatementIsAllowed(object p0) + => string.Format(CultureInfo.CurrentCulture, GetString("MvcRazorCodeParser_OnlyOneModelStatementIsAllowed"), p0); + + /// + /// Invalid tag helper property '{0}.{1}'. Dictionary values must not be of type '{2}'. + /// + internal static string MvcRazorParser_InvalidPropertyType + { + get => GetString("MvcRazorParser_InvalidPropertyType"); + } + + /// + /// Invalid tag helper property '{0}.{1}'. Dictionary values must not be of type '{2}'. + /// + internal static string FormatMvcRazorParser_InvalidPropertyType(object p0, object p1, object p2) + => string.Format(CultureInfo.CurrentCulture, GetString("MvcRazorParser_InvalidPropertyType"), p0, p1, p2); + + /// + /// The '@{0}' directive specified in {1} file will not be imported. The directive must appear at the top of each Razor cshtml file. + /// + internal static string PageDirectiveCannotBeImported + { + get => GetString("PageDirectiveCannotBeImported"); + } + + /// + /// The '@{0}' directive specified in {1} file will not be imported. The directive must appear at the top of each Razor cshtml file. + /// + internal static string FormatPageDirectiveCannotBeImported(object p0, object p1) + => string.Format(CultureInfo.CurrentCulture, GetString("PageDirectiveCannotBeImported"), p0, p1); + + /// + /// Runtime code generation for Mvc 1.x is not supported. + /// + internal static string RuntimeCodeGenerationNotSupported + { + get => GetString("RuntimeCodeGenerationNotSupported"); + } + + /// + /// Runtime code generation for Mvc 1.x is not supported. + /// + internal static string FormatRuntimeCodeGenerationNotSupported() + => GetString("RuntimeCodeGenerationNotSupported"); + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Properties/ViewComponentResources.Designer.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Properties/ViewComponentResources.Designer.cs new file mode 100644 index 0000000000..58228a720f --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Properties/ViewComponentResources.Designer.cs @@ -0,0 +1,100 @@ +// +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class ViewComponentResources + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.ViewComponentResources", typeof(ViewComponentResources).GetTypeInfo().Assembly); + + /// + /// View component '{0}' must have exactly one public method named '{1}' or '{2}'. + /// + internal static string ViewComponent_AmbiguousMethods + { + get => GetString("ViewComponent_AmbiguousMethods"); + } + + /// + /// View component '{0}' must have exactly one public method named '{1}' or '{2}'. + /// + internal static string FormatViewComponent_AmbiguousMethods(object p0, object p1, object p2) + => string.Format(CultureInfo.CurrentCulture, GetString("ViewComponent_AmbiguousMethods"), p0, p1, p2); + + /// + /// Method '{0}' of view component '{1}' should be declared to return {2}&lt;T&gt;. + /// + internal static string ViewComponent_AsyncMethod_ShouldReturnTask + { + get => GetString("ViewComponent_AsyncMethod_ShouldReturnTask"); + } + + /// + /// Method '{0}' of view component '{1}' should be declared to return {2}&lt;T&gt;. + /// + internal static string FormatViewComponent_AsyncMethod_ShouldReturnTask(object p0, object p1, object p2) + => string.Format(CultureInfo.CurrentCulture, GetString("ViewComponent_AsyncMethod_ShouldReturnTask"), p0, p1, p2); + + /// + /// Could not find an '{0}' or '{1}' method for the view component '{2}'. + /// + internal static string ViewComponent_CannotFindMethod + { + get => GetString("ViewComponent_CannotFindMethod"); + } + + /// + /// Could not find an '{0}' or '{1}' method for the view component '{2}'. + /// + internal static string FormatViewComponent_CannotFindMethod(object p0, object p1, object p2) + => string.Format(CultureInfo.CurrentCulture, GetString("ViewComponent_CannotFindMethod"), p0, p1, p2); + + /// + /// Method '{0}' of view component '{1}' cannot return a {2}. + /// + internal static string ViewComponent_SyncMethod_CannotReturnTask + { + get => GetString("ViewComponent_SyncMethod_CannotReturnTask"); + } + + /// + /// Method '{0}' of view component '{1}' cannot return a {2}. + /// + internal static string FormatViewComponent_SyncMethod_CannotReturnTask(object p0, object p1, object p2) + => string.Format(CultureInfo.CurrentCulture, GetString("ViewComponent_SyncMethod_CannotReturnTask"), p0, p1, p2); + + /// + /// Method '{0}' of view component '{1}' should be declared to return a value. + /// + internal static string ViewComponent_SyncMethod_ShouldReturnValue + { + get => GetString("ViewComponent_SyncMethod_ShouldReturnValue"); + } + + /// + /// Method '{0}' of view component '{1}' should be declared to return a value. + /// + internal static string FormatViewComponent_SyncMethod_ShouldReturnValue(object p0, object p1) + => string.Format(CultureInfo.CurrentCulture, GetString("ViewComponent_SyncMethod_ShouldReturnValue"), p0, p1); + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/RazorCodeDocumentExtensions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/RazorCodeDocumentExtensions.cs new file mode 100644 index 0000000000..487ad3d2dc --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/RazorCodeDocumentExtensions.cs @@ -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; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + internal static class RazorCodeDocumentExtensions + { + private const string RelativePathKey = "relative-path"; + + public static string GetRelativePath(this RazorCodeDocument document) + { + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + + return document.Items[RelativePathKey] as string; + } + + + public static void SetRelativePath(this RazorCodeDocument document, string relativePath) + { + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + + document.Items[RelativePathKey] = relativePath; + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/RazorExtensions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/RazorExtensions.cs new file mode 100644 index 0000000000..10db898bac --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/RazorExtensions.cs @@ -0,0 +1,53 @@ +// 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 Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public static class RazorExtensions + { + public static void Register(IRazorEngineBuilder builder) + { + EnsureDesignTime(builder); + + InjectDirective.Register(builder); + ModelDirective.Register(builder); + + FunctionsDirective.Register(builder); + InheritsDirective.Register(builder); + + // Register section directive with the 1.x compatible target extension. + builder.AddDirective(SectionDirective.Directive); + builder.Features.Add(new SectionDirectivePass()); + builder.AddTargetExtension(new LegacySectionTargetExtension()); + + builder.AddTargetExtension(new TemplateTargetExtension() + { + TemplateTypeName = "global::Microsoft.AspNetCore.Mvc.Razor.HelperResult", + }); + + builder.Features.Add(new ModelExpressionPass()); + builder.Features.Add(new MvcViewDocumentClassifierPass()); + } + + public static void RegisterViewComponentTagHelpers(IRazorEngineBuilder builder) + { + EnsureDesignTime(builder); + + builder.Features.Add(new ViewComponentTagHelperPass()); + } + + private static void EnsureDesignTime(IRazorEngineBuilder builder) + { + if (builder.DesignTime) + { + return; + } + + throw new NotSupportedException(Resources.RuntimeCodeGenerationNotSupported); + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/RazorExtensionsDiagnosticFactory.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/RazorExtensionsDiagnosticFactory.cs new file mode 100644 index 0000000000..578de74478 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/RazorExtensionsDiagnosticFactory.cs @@ -0,0 +1,103 @@ +// 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.Threading.Tasks; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + internal class RazorExtensionsDiagnosticFactory + { + private const string DiagnosticPrefix = "RZ"; + + public static readonly RazorDiagnosticDescriptor ViewComponent_CannotFindMethod = + new RazorDiagnosticDescriptor( + $"{DiagnosticPrefix}3900", + () => ViewComponentResources.ViewComponent_CannotFindMethod, + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic CreateViewComponent_CannotFindMethod(string tagHelperType) + { + var diagnostic = RazorDiagnostic.Create( + ViewComponent_CannotFindMethod, + new SourceSpan(SourceLocation.Undefined, contentLength: 0), + ViewComponentTypes.SyncMethodName, + ViewComponentTypes.AsyncMethodName, + tagHelperType); + + return diagnostic; + } + + public static readonly RazorDiagnosticDescriptor ViewComponent_AmbiguousMethods = + new RazorDiagnosticDescriptor( + $"{DiagnosticPrefix}3901", + () => ViewComponentResources.ViewComponent_AmbiguousMethods, + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic CreateViewComponent_AmbiguousMethods(string tagHelperType) + { + var diagnostic = RazorDiagnostic.Create( + ViewComponent_AmbiguousMethods, + new SourceSpan(SourceLocation.Undefined, contentLength: 0), + tagHelperType, + ViewComponentTypes.SyncMethodName, + ViewComponentTypes.AsyncMethodName); + + return diagnostic; + } + + public static readonly RazorDiagnosticDescriptor ViewComponent_AsyncMethod_ShouldReturnTask = + new RazorDiagnosticDescriptor( + $"{DiagnosticPrefix}3902", + () => ViewComponentResources.ViewComponent_AsyncMethod_ShouldReturnTask, + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic CreateViewComponent_AsyncMethod_ShouldReturnTask(string tagHelperType) + { + var diagnostic = RazorDiagnostic.Create( + ViewComponent_AsyncMethod_ShouldReturnTask, + new SourceSpan(SourceLocation.Undefined, contentLength: 0), + ViewComponentTypes.AsyncMethodName, + tagHelperType, + nameof(Task)); + + return diagnostic; + } + + public static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_ShouldReturnValue = + new RazorDiagnosticDescriptor( + $"{DiagnosticPrefix}3903", + () => ViewComponentResources.ViewComponent_SyncMethod_ShouldReturnValue, + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic CreateViewComponent_SyncMethod_ShouldReturnValue(string tagHelperType) + { + var diagnostic = RazorDiagnostic.Create( + ViewComponent_SyncMethod_ShouldReturnValue, + new SourceSpan(SourceLocation.Undefined, contentLength: 0), + ViewComponentTypes.SyncMethodName, + tagHelperType); + + return diagnostic; + } + + public static readonly RazorDiagnosticDescriptor ViewComponent_SyncMethod_CannotReturnTask = + new RazorDiagnosticDescriptor( + $"{DiagnosticPrefix}3904", + () => ViewComponentResources.ViewComponent_SyncMethod_CannotReturnTask, + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic CreateViewComponent_SyncMethod_CannotReturnTask(string tagHelperType) + { + var diagnostic = RazorDiagnostic.Create( + ViewComponent_SyncMethod_CannotReturnTask, + new SourceSpan(SourceLocation.Undefined, contentLength: 0), + ViewComponentTypes.SyncMethodName, + tagHelperType, + nameof(Task)); + + return diagnostic; + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Resources.resx b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Resources.resx new file mode 100644 index 0000000000..6342165c1c --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/Resources.resx @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Value cannot be null or empty. + + + The 'inherits' keyword is not allowed when a '{0}' keyword is used. + + + A property name must be specified when using the '{0}' statement. Format for a '{0}' statement is '@{0} <Type Name> <Property Name>'. + + + The '{0}' keyword must be followed by a type name on the same line. + + + Only one '{0}' statement is allowed in a file. + + + Invalid tag helper property '{0}.{1}'. Dictionary values must not be of type '{2}'. + + + The '@{0}' directive specified in {1} file will not be imported. The directive must appear at the top of each Razor cshtml file. + + + Runtime code generation for Mvc 1.x is not supported. + + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/TagHelperDescriptorExtensions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/TagHelperDescriptorExtensions.cs new file mode 100644 index 0000000000..b455fc7423 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/TagHelperDescriptorExtensions.cs @@ -0,0 +1,37 @@ +// 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 Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public static class TagHelperDescriptorExtensions + { + /// + /// Indicates whether a represents a view component. + /// + /// The to check. + /// Whether a represents a view component. + public static bool IsViewComponentKind(this TagHelperDescriptor tagHelper) + { + if (tagHelper == null) + { + throw new ArgumentNullException(nameof(tagHelper)); + } + + return string.Equals(ViewComponentTagHelperConventions.Kind, tagHelper.Kind, StringComparison.Ordinal); + } + + public static string GetViewComponentName(this TagHelperDescriptor tagHelper) + { + if (tagHelper == null) + { + throw new ArgumentNullException(nameof(tagHelper)); + } + + tagHelper.Metadata.TryGetValue(ViewComponentTagHelperMetadata.Name, out var result); + return result; + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentResources.resx b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentResources.resx new file mode 100644 index 0000000000..d6aad4ff3f --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentResources.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + View component '{0}' must have exactly one public method named '{1}' or '{2}'. + + + Method '{0}' of view component '{1}' should be declared to return {2}&lt;T&gt;. + + + Could not find an '{0}' or '{1}' method for the view component '{2}'. + + + Method '{0}' of view component '{1}' cannot return a {2}. + + + Method '{0}' of view component '{1}' should be declared to return a value. + + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperConventions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperConventions.cs new file mode 100644 index 0000000000..f02d874dc5 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperConventions.cs @@ -0,0 +1,10 @@ +// 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.Mvc.Razor.Extensions.Version1_X +{ + public static class ViewComponentTagHelperConventions + { + public static readonly string Kind = "MVC.ViewComponent"; + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperDescriptorFactory.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperDescriptorFactory.cs new file mode 100644 index 0000000000..68966e734c --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperDescriptorFactory.cs @@ -0,0 +1,269 @@ +// 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.Collections.Immutable; +using System.Linq; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + internal class ViewComponentTagHelperDescriptorFactory + { + private readonly INamedTypeSymbol _viewComponentAttributeSymbol; + private readonly INamedTypeSymbol _genericTaskSymbol; + private readonly INamedTypeSymbol _taskSymbol; + private readonly INamedTypeSymbol _iDictionarySymbol; + + private static readonly SymbolDisplayFormat FullNameTypeDisplayFormat = + SymbolDisplayFormat.FullyQualifiedFormat + .WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted) + .WithMiscellaneousOptions(SymbolDisplayFormat.FullyQualifiedFormat.MiscellaneousOptions & (~SymbolDisplayMiscellaneousOptions.UseSpecialTypes)); + + private static readonly IReadOnlyDictionary PrimitiveDisplayTypeNameLookups = new Dictionary(StringComparer.Ordinal) + { + [typeof(byte).FullName] = "byte", + [typeof(sbyte).FullName] = "sbyte", + [typeof(int).FullName] = "int", + [typeof(uint).FullName] = "uint", + [typeof(short).FullName] = "short", + [typeof(ushort).FullName] = "ushort", + [typeof(long).FullName] = "long", + [typeof(ulong).FullName] = "ulong", + [typeof(float).FullName] = "float", + [typeof(double).FullName] = "double", + [typeof(char).FullName] = "char", + [typeof(bool).FullName] = "bool", + [typeof(object).FullName] = "object", + [typeof(string).FullName] = "string", + [typeof(decimal).FullName] = "decimal", + }; + + public ViewComponentTagHelperDescriptorFactory(Compilation compilation) + { + _viewComponentAttributeSymbol = compilation.GetTypeByMetadataName(ViewComponentTypes.ViewComponentAttribute); + _genericTaskSymbol = compilation.GetTypeByMetadataName(ViewComponentTypes.GenericTask); + _taskSymbol = compilation.GetTypeByMetadataName(ViewComponentTypes.Task); + _iDictionarySymbol = compilation.GetTypeByMetadataName(ViewComponentTypes.IDictionary); + } + + public virtual TagHelperDescriptor CreateDescriptor(INamedTypeSymbol type) + { + var assemblyName = type.ContainingAssembly.Name; + var shortName = GetShortName(type); + var tagName = $"vc:{HtmlConventions.ToHtmlCase(shortName)}"; + var typeName = $"__Generated__{shortName}ViewComponentTagHelper"; + var displayName = shortName + "ViewComponentTagHelper"; + var descriptorBuilder = TagHelperDescriptorBuilder.Create(ViewComponentTagHelperConventions.Kind, typeName, assemblyName); + descriptorBuilder.SetTypeName(typeName); + descriptorBuilder.DisplayName = displayName; + + if (TryFindInvokeMethod(type, out var method, out var diagnostic)) + { + var methodParameters = method.Parameters; + descriptorBuilder.TagMatchingRule(ruleBuilder => + { + ruleBuilder.TagName = tagName; + AddRequiredAttributes(methodParameters, ruleBuilder); + }); + + AddBoundAttributes(methodParameters, displayName, descriptorBuilder); + } + else + { + descriptorBuilder.Diagnostics.Add(diagnostic); + } + + descriptorBuilder.Metadata[ViewComponentTagHelperMetadata.Name] = shortName; + + var descriptor = descriptorBuilder.Build(); + return descriptor; + } + + private bool TryFindInvokeMethod(INamedTypeSymbol type, out IMethodSymbol method, out RazorDiagnostic diagnostic) + { + var methods = type.GetMembers() + .OfType() + .Where(m => + m.DeclaredAccessibility == Accessibility.Public && + (string.Equals(m.Name, ViewComponentTypes.AsyncMethodName, StringComparison.Ordinal) || + string.Equals(m.Name, ViewComponentTypes.SyncMethodName, StringComparison.Ordinal))) + .ToArray(); + + if (methods.Length == 0) + { + diagnostic = RazorExtensionsDiagnosticFactory.CreateViewComponent_CannotFindMethod(type.ToDisplayString(FullNameTypeDisplayFormat)); + method = null; + return false; + } + else if (methods.Length > 1) + { + diagnostic = RazorExtensionsDiagnosticFactory.CreateViewComponent_AmbiguousMethods(type.ToDisplayString(FullNameTypeDisplayFormat)); + method = null; + return false; + } + + var selectedMethod = methods[0]; + var returnType = selectedMethod.ReturnType as INamedTypeSymbol; + if (string.Equals(selectedMethod.Name, ViewComponentTypes.AsyncMethodName, StringComparison.Ordinal)) + { + // Will invoke asynchronously. Method must not return Task or Task. + if (returnType == _taskSymbol) + { + // This is ok. + } + else if (returnType.IsGenericType && returnType.ConstructedFrom == _genericTaskSymbol) + { + // This is ok. + } + else + { + diagnostic = RazorExtensionsDiagnosticFactory.CreateViewComponent_AsyncMethod_ShouldReturnTask(type.ToDisplayString(FullNameTypeDisplayFormat)); + method = null; + return false; + } + } + else + { + // Will invoke synchronously. Method must not return void, Task or Task. + if (returnType.SpecialType == SpecialType.System_Void) + { + diagnostic = RazorExtensionsDiagnosticFactory.CreateViewComponent_SyncMethod_ShouldReturnValue(type.ToDisplayString(FullNameTypeDisplayFormat)); + method = null; + return false; + } + else if (returnType == _taskSymbol) + { + diagnostic = RazorExtensionsDiagnosticFactory.CreateViewComponent_SyncMethod_CannotReturnTask(type.ToDisplayString(FullNameTypeDisplayFormat)); + method = null; + return false; + } + else if (returnType.IsGenericType && returnType.ConstructedFrom == _genericTaskSymbol) + { + diagnostic = RazorExtensionsDiagnosticFactory.CreateViewComponent_SyncMethod_CannotReturnTask(type.ToDisplayString(FullNameTypeDisplayFormat)); + method = null; + return false; + } + } + + method = selectedMethod; + diagnostic = null; + return true; + } + + private void AddRequiredAttributes(ImmutableArray methodParameters, TagMatchingRuleDescriptorBuilder builder) + { + foreach (var parameter in methodParameters) + { + if (GetIndexerValueTypeName(parameter) == null) + { + // Set required attributes only for non-indexer attributes. Indexer attributes can't be required attributes + // because there are two ways of setting values for the attribute. + builder.Attribute(attributeBuilder => + { + var lowerKebabName = HtmlConventions.ToHtmlCase(parameter.Name); + attributeBuilder.Name =lowerKebabName; + }); + } + } + } + + private void AddBoundAttributes(ImmutableArray methodParameters, string containingDisplayName, TagHelperDescriptorBuilder builder) + { + foreach (var parameter in methodParameters) + { + var lowerKebabName = HtmlConventions.ToHtmlCase(parameter.Name); + var typeName = parameter.Type.ToDisplayString(FullNameTypeDisplayFormat); + + if (!PrimitiveDisplayTypeNameLookups.TryGetValue(typeName, out var simpleName)) + { + simpleName = typeName; + } + + builder.BindAttribute(attributeBuilder => + { + attributeBuilder.Name = lowerKebabName; + attributeBuilder.TypeName = typeName; + attributeBuilder.DisplayName = $"{simpleName} {containingDisplayName}.{parameter.Name}"; + attributeBuilder.SetPropertyName(parameter.Name); + + if (parameter.Type.TypeKind == TypeKind.Enum) + { + attributeBuilder.IsEnum = true; + } + else + { + var dictionaryValueType = GetIndexerValueTypeName(parameter); + if (dictionaryValueType != null) + { + attributeBuilder.AsDictionary(lowerKebabName + "-", dictionaryValueType); + } + } + }); + } + } + + private string GetIndexerValueTypeName(IParameterSymbol parameter) + { + INamedTypeSymbol dictionaryType; + if ((parameter.Type as INamedTypeSymbol)?.ConstructedFrom == _iDictionarySymbol) + { + dictionaryType = (INamedTypeSymbol)parameter.Type; + } + else if (parameter.Type.AllInterfaces.Any(s => s.ConstructedFrom == _iDictionarySymbol)) + { + dictionaryType = parameter.Type.AllInterfaces.First(s => s.ConstructedFrom == _iDictionarySymbol); + } + else + { + dictionaryType = null; + } + + if (dictionaryType == null || dictionaryType.TypeArguments[0].SpecialType != SpecialType.System_String) + { + return null; + } + + var type = dictionaryType.TypeArguments[1]; + var typeName = type.ToDisplayString(FullNameTypeDisplayFormat); + + return typeName; + } + + private string GetShortName(INamedTypeSymbol componentType) + { + var viewComponentAttribute = componentType.GetAttributes().Where(a => a.AttributeClass == _viewComponentAttributeSymbol).FirstOrDefault(); + var name = viewComponentAttribute + ?.NamedArguments + .Where(namedArgument => string.Equals(namedArgument.Key, ViewComponentTypes.ViewComponent.Name, StringComparison.Ordinal)) + .FirstOrDefault() + .Value + .Value as string; + + if (!string.IsNullOrEmpty(name)) + { + var separatorIndex = name.LastIndexOf('.'); + if (separatorIndex >= 0) + { + return name.Substring(separatorIndex + 1); + } + else + { + return name; + } + } + + // Get name by convention + if (componentType.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix, StringComparison.OrdinalIgnoreCase)) + { + return componentType.Name.Substring(0, componentType.Name.Length - ViewComponentTypes.ViewComponentSuffix.Length); + } + else + { + return componentType.Name; + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperDescriptorProvider.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperDescriptorProvider.cs new file mode 100644 index 0000000000..0b85fdaab3 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperDescriptorProvider.cs @@ -0,0 +1,72 @@ +// 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 Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Razor; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public sealed class ViewComponentTagHelperDescriptorProvider : RazorEngineFeatureBase, ITagHelperDescriptorProvider + { + // Hack for testability. The visitor will normally just no op if we're not referencing + // an appropriate version of MVC. + internal bool ForceEnabled { get; set; } + + public int Order { get; set; } + + public void Execute(TagHelperDescriptorProviderContext context) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var compilation = context.GetCompilation(); + if (compilation == null) + { + // No compilation, nothing to do. + return; + } + + var types = new List(); + var visitor = ViewComponentTypeVisitor.Create(compilation, types); + if (ForceEnabled) + { + visitor.Enabled = true; + } + + // We always visit the global namespace. + visitor.Visit(compilation.Assembly.GlobalNamespace); + + foreach (var reference in compilation.References) + { + if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol assembly) + { + if (IsTagHelperAssembly(assembly)) + { + visitor.Visit(assembly.GlobalNamespace); + } + } + } + + var factory = new ViewComponentTagHelperDescriptorFactory(compilation); + for (var i = 0; i < types.Count; i++) + { + var descriptor = factory.CreateDescriptor(types[i]); + + if (descriptor != null) + { + context.Results.Add(descriptor); + } + } + } + + private bool IsTagHelperAssembly(IAssemblySymbol assembly) + { + return assembly.Name != null && !assembly.Name.StartsWith("System.", StringComparison.Ordinal); + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperMetadata.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperMetadata.cs new file mode 100644 index 0000000000..1718829c39 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperMetadata.cs @@ -0,0 +1,14 @@ +// 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.Mvc.Razor.Extensions.Version1_X +{ + public static class ViewComponentTagHelperMetadata + { + /// + /// The key in a containing + /// the short name of a view component. + /// + public static readonly string Name = "MVC.ViewComponent.Name"; + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperPass.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperPass.cs new file mode 100644 index 0000000000..8fdfb8a6a1 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTagHelperPass.cs @@ -0,0 +1,342 @@ +// 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.Diagnostics; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Extensions; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class ViewComponentTagHelperPass : IntermediateNodePassBase, IRazorOptimizationPass + { + // Run after the default taghelper pass + public override int Order => IntermediateNodePassBase.DefaultFeatureOrder + 2000; + + private static readonly string[] PublicModifiers = new[] { "public" }; + + protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) + { + var @namespace = documentNode.FindPrimaryNamespace(); + var @class = documentNode.FindPrimaryClass(); + if (@namespace == null || @class == null) + { + // Nothing to do, bail. We can't function without the standard structure. + return; + } + + var context = new Context(@namespace, @class); + + // For each VCTH *usage* we need to rewrite the tag helper node to use the tag helper runtime to construct + // and set properties on the the correct field, and using the name of the type we will generate. + var nodes = documentNode.FindDescendantNodes(); + for (var i = 0; i < nodes.Count; i++) + { + var node = nodes[i]; + foreach (var tagHelper in node.TagHelpers) + { + RewriteUsage(context, node, tagHelper); + } + } + + // Then for each VCTH *definition* that we've seen we need to generate the class that implements + // ITagHelper and the field that will hold it. + foreach (var tagHelper in context.TagHelpers) + { + AddField(context, tagHelper); + AddTagHelperClass(context, tagHelper); + } + } + + private void RewriteUsage(Context context, TagHelperIntermediateNode node, TagHelperDescriptor tagHelper) + { + if (!tagHelper.IsViewComponentKind()) + { + return; + } + + context.Add(tagHelper); + + // Now we need to insert a create node using the default tag helper runtime. This is similar to + // code in DefaultTagHelperOptimizationPass. + // + // Find the body node. + var i = 0; + while (i < node.Children.Count && node.Children[i] is TagHelperBodyIntermediateNode) + { + i++; + } + while (i < node.Children.Count && node.Children[i] is DefaultTagHelperBodyIntermediateNode) + { + i++; + } + + // Now find the last create node. + while (i < node.Children.Count && node.Children[i] is DefaultTagHelperCreateIntermediateNode) + { + i++; + } + + // Now i has the right insertion point. + node.Children.Insert(i, new DefaultTagHelperCreateIntermediateNode() + { + FieldName = context.GetFieldName(tagHelper), + TagHelper = tagHelper, + TypeName = context.GetFullyQualifiedName(tagHelper), + }); + + // Now we need to rewrite any set property nodes to use the default runtime. + for (i = 0; i < node.Children.Count; i++) + { + if (node.Children[i] is TagHelperPropertyIntermediateNode propertyNode && + propertyNode.TagHelper == tagHelper) + { + // This is a set property for this VCTH - we need to replace it with a node + // that will use our field and property name. + node.Children[i] = new DefaultTagHelperPropertyIntermediateNode(propertyNode) + { + FieldName = context.GetFieldName(tagHelper), + PropertyName = propertyNode.BoundAttribute.GetPropertyName(), + }; + } + } + } + + private void AddField(Context context, TagHelperDescriptor tagHelper) + { + // We need to insert a node for the field that will hold the tag helper. We've already generated a field name + // at this time and use it for all uses of the same tag helper type. + // + // We also want to preserve the ordering of the nodes for testability. So insert at the end of any existing + // field nodes. + var i = 0; + while (i < context.Class.Children.Count && context.Class.Children[i] is DefaultTagHelperRuntimeIntermediateNode) + { + i++; + } + + while (i < context.Class.Children.Count && context.Class.Children[i] is FieldDeclarationIntermediateNode) + { + i++; + } + + context.Class.Children.Insert(i, new FieldDeclarationIntermediateNode() + { + Annotations = + { + { CommonAnnotations.DefaultTagHelperExtension.TagHelperField, bool.TrueString }, + }, + Modifiers = + { + "private", + }, + FieldName = context.GetFieldName(tagHelper), + FieldType = "global::" + context.GetFullyQualifiedName(tagHelper), + }); + } + + private void AddTagHelperClass(Context context, TagHelperDescriptor tagHelper) + { + var writer = new CodeWriter(); + WriteClass(context, writer, tagHelper); + + var code = new CSharpCodeIntermediateNode(); + code.Children.Add(new IntermediateToken() + { + Kind = TokenKind.CSharp, + Content = writer.GenerateCode() + }); + + context.Class.Children.Add(code); + } + + private void WriteClass(Context context, CodeWriter writer, TagHelperDescriptor tagHelper) + { + // Add target element. + BuildTargetElementString(writer, tagHelper); + + // Initialize declaration. + var tagHelperTypeName = "Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"; + var className = context.GetClassName(tagHelper); + + using (writer.BuildClassDeclaration(PublicModifiers, className, tagHelperTypeName, interfaces: null)) + { + // Add view component helper. + writer.WriteVariableDeclaration( + $"private readonly global::Microsoft.AspNetCore.Mvc.IViewComponentHelper", + "_helper", + value: null); + + // Add constructor. + BuildConstructorString(writer, className); + + // Add attributes. + BuildAttributeDeclarations(writer, tagHelper); + + // Add process method. + BuildProcessMethodString(writer, tagHelper); + } + } + + private void BuildConstructorString(CodeWriter writer, string className) + { + writer.Write("public ") + .Write(className) + .Write("(") + .Write("global::Microsoft.AspNetCore.Mvc.IViewComponentHelper helper") + .WriteLine(")"); + using (writer.BuildScope()) + { + writer.WriteStartAssignment("_helper") + .Write("helper") + .WriteLine(";"); + } + } + + private void BuildAttributeDeclarations(CodeWriter writer, TagHelperDescriptor tagHelper) + { + writer.Write("[") + .Write("Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNotBoundAttribute") + .WriteParameterSeparator() + .Write($"global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewContextAttribute") + .WriteLine("]"); + + writer.WriteAutoPropertyDeclaration( + PublicModifiers, + $"global::Microsoft.AspNetCore.Mvc.Rendering.ViewContext", + "ViewContext"); + + foreach (var attribute in tagHelper.BoundAttributes) + { + writer.WriteAutoPropertyDeclaration( + PublicModifiers, + attribute.TypeName, + attribute.GetPropertyName()); + + if (attribute.IndexerTypeName != null) + { + writer.Write(" = ") + .WriteStartNewObject(attribute.TypeName) + .WriteEndMethodInvocation(); + } + } + } + + private void BuildProcessMethodString(CodeWriter writer, TagHelperDescriptor tagHelper) + { + var contextVariable = "context"; + var outputVariable = "output"; + + using (writer.BuildMethodDeclaration( + $"public override async", + $"global::{typeof(Task).FullName}", + "ProcessAsync", + new Dictionary() + { + { "Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext", contextVariable }, + { "Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput", outputVariable } + })) + { + writer.WriteInstanceMethodInvocation( + $"(_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?", + "Contextualize", + new[] { "ViewContext" }); + + var methodParameters = GetMethodParameters(tagHelper); + var contentVariable = "content"; + writer.Write("var ") + .WriteStartAssignment(contentVariable) + .WriteInstanceMethodInvocation($"await _helper", "InvokeAsync", methodParameters); + writer.WriteStartAssignment($"{outputVariable}.TagName") + .WriteLine("null;"); + writer.WriteInstanceMethodInvocation( + $"{outputVariable}.Content", + "SetHtmlContent", + new[] { contentVariable }); + } + } + + private string[] GetMethodParameters(TagHelperDescriptor tagHelper) + { + var propertyNames = tagHelper.BoundAttributes.Select(attribute => attribute.GetPropertyName()); + var joinedPropertyNames = string.Join(", ", propertyNames); + var parametersString = $"new {{ { joinedPropertyNames } }}"; + var viewComponentName = tagHelper.GetViewComponentName(); + var methodParameters = new[] { $"\"{viewComponentName}\"", parametersString }; + return methodParameters; + } + + private void BuildTargetElementString(CodeWriter writer, TagHelperDescriptor tagHelper) + { + Debug.Assert(tagHelper.TagMatchingRules.Count() == 1); + + var rule = tagHelper.TagMatchingRules.First(); + + writer.Write("[") + .WriteStartMethodInvocation("Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute") + .WriteStringLiteral(rule.TagName) + .WriteLine(")]"); + } + + private struct Context + { + private Dictionary _tagHelpers; + + public Context(NamespaceDeclarationIntermediateNode @namespace, ClassDeclarationIntermediateNode @class) + { + Namespace = @namespace; + Class = @class; + + _tagHelpers = new Dictionary(); + } + + public ClassDeclarationIntermediateNode Class { get; } + + public NamespaceDeclarationIntermediateNode Namespace { get; } + + + public IEnumerable TagHelpers => _tagHelpers.Keys; + + public bool Add(TagHelperDescriptor tagHelper) + { + if (_tagHelpers.ContainsKey(tagHelper)) + { + return false; + } + + var className = $"__Generated__{tagHelper.GetViewComponentName()}ViewComponentTagHelper"; + var fullyQualifiedName = $"{Namespace.Content}.{Class.ClassName}.{className}"; + var fieldName = GenerateFieldName(tagHelper); + + _tagHelpers.Add(tagHelper, (className, fullyQualifiedName, fieldName)); + + return true; + } + + public string GetClassName(TagHelperDescriptor taghelper) + { + return _tagHelpers[taghelper].className; + } + + public string GetFullyQualifiedName(TagHelperDescriptor taghelper) + { + return _tagHelpers[taghelper].fullyQualifiedName; + } + + public string GetFieldName(TagHelperDescriptor taghelper) + { + return _tagHelpers[taghelper].fieldName; + } + + private static string GenerateFieldName(TagHelperDescriptor tagHelper) + { + return $"__{tagHelper.GetViewComponentName()}ViewComponentTagHelper"; + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTypeVisitor.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTypeVisitor.cs new file mode 100644 index 0000000000..fe70827712 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTypeVisitor.cs @@ -0,0 +1,117 @@ +// 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; +using Microsoft.CodeAnalysis; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + internal class ViewComponentTypeVisitor : SymbolVisitor + { + private static readonly Version SupportedVCTHMvcVersion = new Version(1, 1); + + private readonly INamedTypeSymbol _viewComponentAttribute; + private readonly INamedTypeSymbol _nonViewComponentAttribute; + private readonly List _results; + + public static ViewComponentTypeVisitor Create(Compilation compilation, List results) + { + var enabled = false; + foreach (var reference in compilation.References) + { + var symbol = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol; + if (symbol != null) + { + if (string.Equals(symbol.Identity.Name, ViewComponentTypes.Assembly, StringComparison.Ordinal) && + symbol.Identity.Version > ViewComponentTypes.AssemblyVersion) + { + enabled = true; + break; + } + } + } + + var vcAttribute = enabled ? compilation.GetTypeByMetadataName(ViewComponentTypes.ViewComponentAttribute) : null; + var nonVCAttribute = enabled ? compilation.GetTypeByMetadataName(ViewComponentTypes.NonViewComponentAttribute) : null; + return new ViewComponentTypeVisitor(vcAttribute, nonVCAttribute, results); + } + + public ViewComponentTypeVisitor( + INamedTypeSymbol viewComponentAttribute, + INamedTypeSymbol nonViewComponentAttribute, + List results) + { + _viewComponentAttribute = viewComponentAttribute; + _nonViewComponentAttribute = nonViewComponentAttribute; + _results = results; + + Enabled = _viewComponentAttribute != null; + } + + public bool Enabled { get; set; } + + public override void VisitNamedType(INamedTypeSymbol symbol) + { + if (IsViewComponent(symbol)) + { + _results.Add(symbol); + } + + if (symbol.DeclaredAccessibility != Accessibility.Public) + { + return; + } + + foreach (var member in symbol.GetTypeMembers()) + { + Visit(member); + } + } + + public override void VisitNamespace(INamespaceSymbol symbol) + { + foreach (var member in symbol.GetMembers()) + { + Visit(member); + } + } + + internal bool IsViewComponent(INamedTypeSymbol symbol) + { + if (!Enabled) + { + return false; + } + + if (symbol.DeclaredAccessibility != Accessibility.Public || + symbol.IsAbstract || + symbol.IsGenericType || + AttributeIsDefined(symbol, _nonViewComponentAttribute)) + { + return false; + } + + return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix) || + AttributeIsDefined(symbol, _viewComponentAttribute); + } + + private static bool AttributeIsDefined(INamedTypeSymbol type, INamedTypeSymbol queryAttribute) + { + if (type == null || queryAttribute == null) + { + return false; + } + + var attribute = type.GetAttributes().Where(a => a.AttributeClass == queryAttribute).FirstOrDefault(); + + if (attribute != null) + { + return true; + } + + return AttributeIsDefined(type.BaseType, queryAttribute); + } + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTypes.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTypes.cs new file mode 100644 index 0000000000..e9d8f598f8 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/ViewComponentTypes.cs @@ -0,0 +1,35 @@ +// 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; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + internal static class ViewComponentTypes + { + public const string Assembly = "Microsoft.AspNetCore.Mvc.ViewFeatures"; + + public static readonly Version AssemblyVersion = new Version(1, 1, 0, 0); + + public const string ViewComponentSuffix = "ViewComponent"; + + public const string ViewComponentAttribute = "Microsoft.AspNetCore.Mvc.ViewComponentAttribute"; + + public const string NonViewComponentAttribute = "Microsoft.AspNetCore.Mvc.NonViewComponentAttribute"; + + public const string GenericTask = "System.Threading.Tasks.Task`1"; + + public const string Task = "System.Threading.Tasks.Task"; + + public const string IDictionary = "System.Collections.Generic.IDictionary`2"; + + public const string AsyncMethodName = "InvokeAsync"; + + public const string SyncMethodName = "Invoke"; + + public static class ViewComponent + { + public const string Name = "Name"; + } + } +} diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionTargetExtension.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionTargetExtension.cs index b400790f2e..5e47ca17d7 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionTargetExtension.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionTargetExtension.cs @@ -7,32 +7,19 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { public sealed class SectionTargetExtension : ISectionTargetExtension { - private static readonly string DefaultWriterName = "__razor_section_writer"; - public static readonly string DefaultSectionMethodName = "DefineSection"; public string SectionMethodName { get; set; } = DefaultSectionMethodName; public void WriteSection(CodeRenderingContext context, SectionIntermediateNode node) { - // Quirk Alert! - // - // In 1.0.0 Razor/MVC the define section method took a parameter for a TextWriter - // that would be used for all of the output in the section. We simplified this API for - // 2.0.0 of MVC, but our design time codegen still needs to target 1.0.0. - // - // So the workaround is MVC 2.0.0 will define these methods with the TextWriter, but - // that method is never called. We still generate the call *with* the TextWriter for - // design time, at least until we have multi-targeting. - var writerName = context.Options.DesignTime ? DefaultWriterName : string.Empty; - context.CodeWriter .WriteStartMethodInvocation(SectionMethodName) .Write("\"") .Write(node.SectionName) .Write("\", "); - using (context.CodeWriter.BuildAsyncLambda(writerName)) + using (context.CodeWriter.BuildAsyncLambda()) { context.RenderChildren(node); } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Properties/AssemblyInfo.cs b/src/Microsoft.AspNetCore.Razor.Language/Properties/AssemblyInfo.cs index a94f741179..754fa9b97a 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Properties/AssemblyInfo.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Razor.Extensions.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Razor.Language.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Razor.Test.Common, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.CodeAnalysis.Razor, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTemplateEngineFactoryService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTemplateEngineFactoryService.cs index 8b37cffc1e..e97fe40e15 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTemplateEngineFactoryService.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTemplateEngineFactoryService.cs @@ -2,13 +2,24 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis.Host; +using Mvc1_X = Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X; +using MvcLatest = Microsoft.AspNetCore.Mvc.Razor.Extensions; namespace Microsoft.CodeAnalysis.Razor { internal class DefaultTemplateEngineFactoryService : RazorTemplateEngineFactoryService { + private static readonly Version LatestSupportedMvc = new Version(2, 1, 0); + + private readonly HostLanguageServices _services; + + public DefaultTemplateEngineFactoryService(HostLanguageServices services) + { + _services = services; + } + public override RazorTemplateEngine Create(string projectPath, Action configure) { if (projectPath == null) @@ -16,17 +27,51 @@ namespace Microsoft.CodeAnalysis.Razor throw new ArgumentNullException(nameof(projectPath)); } - var engine = RazorEngine.CreateDesignTime(b => + RazorEngine engine; + var mvcVersion = GetMvcVersion(projectPath); + if (mvcVersion?.Major == 1) { - configure?.Invoke(b); + engine = RazorEngine.CreateDesignTime(b => + { + configure?.Invoke(b); - // For now we're hardcoded to use MVC's extensibility. - RazorExtensions.Register(b); - }); + Mvc1_X.RazorExtensions.Register(b); - var templateEngine = new MvcRazorTemplateEngine(engine, RazorProject.Create(projectPath)); - templateEngine.Options.ImportsFileName = "_ViewImports.cshtml"; - return templateEngine; + if (mvcVersion?.Minor >= 1) + { + Mvc1_X.RazorExtensions.RegisterViewComponentTagHelpers(b); + } + }); + + var templateEngine = new Mvc1_X.MvcRazorTemplateEngine(engine, RazorProject.Create(projectPath)); + templateEngine.Options.ImportsFileName = "_ViewImports.cshtml"; + return templateEngine; + } + else + { + if (mvcVersion?.Major != LatestSupportedMvc.Major) + { + // TODO: Log unknown Mvc version. Something like + // Could not construct Razor engine for Mvc version '{mvcVersion}'. Falling back to Razor engine for Mvc '{LatestSupportedMvc}'. + } + + engine = RazorEngine.CreateDesignTime(b => + { + configure?.Invoke(b); + + MvcLatest.RazorExtensions.Register(b); + }); + + var templateEngine = new MvcLatest.MvcRazorTemplateEngine(engine, RazorProject.Create(projectPath)); + templateEngine.Options.ImportsFileName = "_ViewImports.cshtml"; + return templateEngine; + } + } + + private Version GetMvcVersion(string projectPath) + { + // TODO: Need to figure out the actual referenced Mvc version in the project. https://github.com/aspnet/Razor/issues/1183 + return null; } } } diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTemplateEngineFactoryServiceFactory.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTemplateEngineFactoryServiceFactory.cs index 21522b72ec..c08c665cd5 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTemplateEngineFactoryServiceFactory.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTemplateEngineFactoryServiceFactory.cs @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { - return new DefaultTemplateEngineFactoryService(); + return new DefaultTemplateEngineFactoryService(languageServices); } } } \ No newline at end of file diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj b/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj index c192c74b8d..c351759d2d 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj @@ -44,6 +44,7 @@ + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs index 531d1b1393..4b78caab05 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -106,6 +106,13 @@ public class MyModel RunRuntimeTest(references); } + [Fact] + public void Sections_Runtime() + { + var references = CreateCompilationReferences(CurrentMvcShim); + RunRuntimeTest(references); + } + [Fact] public void _ViewImports_Runtime() { @@ -341,6 +348,13 @@ public abstract class MyPageModel : Page RunDesignTimeTest(references); } + [Fact] + public void Sections_DesignTime() + { + var references = CreateCompilationReferences(CurrentMvcShim); + RunDesignTimeTest(references); + } + [Fact] public void _ViewImports_DesignTime() { diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml new file mode 100644 index 0000000000..81f73f2ca6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml @@ -0,0 +1,9 @@ +@{ + Layout = "_SectionTestLayout.cshtml"; +} + +
Some body
+ +@section Section1 { +
This is in Section 1
+} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs new file mode 100644 index 0000000000..72c84fbabc --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs @@ -0,0 +1,53 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object Section1 = null; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" + + Layout = "_SectionTestLayout.cshtml"; + +#line default +#line hidden + DefineSection("Section1", async() => { + } + ); + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.ir.txt new file mode 100644 index 0000000000..f6c25ee51c --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.ir.txt @@ -0,0 +1,53 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (729:13,14 [87] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (832:14,14 [87] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (86:6,9 [8] Sections.cshtml) - Section1 + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - (2:0,2 [46] Sections.cshtml) + IntermediateToken - (2:0,2 [46] Sections.cshtml) - CSharp - \n Layout = "_SectionTestLayout.cshtml";\n + HtmlContent - (51:3,0 [26] Sections.cshtml) + IntermediateToken - (51:3,0 [2] Sections.cshtml) - Html - \n + IntermediateToken - (53:4,0 [5] Sections.cshtml) - Html -
+ IntermediateToken - (58:4,5 [9] Sections.cshtml) - Html - Some body + IntermediateToken - (67:4,14 [6] Sections.cshtml) - Html -
+ IntermediateToken - (73:4,20 [4] Sections.cshtml) - Html - \n\n + Section - - Section1 + HtmlContent - (96:6,19 [39] Sections.cshtml) + IntermediateToken - (96:6,19 [6] Sections.cshtml) - Html - \n + IntermediateToken - (102:7,4 [5] Sections.cshtml) - Html -
+ IntermediateToken - (107:7,9 [20] Sections.cshtml) - Html - This is in Section 1 + IntermediateToken - (127:7,29 [6] Sections.cshtml) - Html -
+ IntermediateToken - (133:7,35 [2] Sections.cshtml) - Html - \n + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt new file mode 100644 index 0000000000..5a6cfe78f2 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt @@ -0,0 +1,14 @@ +Source Location: (86:6,9 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) +|Section1| +Generated Location: (697:18,22 [8] ) +|Section1| + +Source Location: (2:0,2 [46] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) +| + Layout = "_SectionTestLayout.cshtml"; +| +Generated Location: (1132:30,2 [46] ) +| + Layout = "_SectionTestLayout.cshtml"; +| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs new file mode 100644 index 0000000000..7221f0899a --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs @@ -0,0 +1,49 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "c7635d54fa83ccf10a29be2f0a7b56d1703398a7" +// +#pragma warning disable 1591 +[assembly:global::Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorViewAttribute(null, typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" + + Layout = "_SectionTestLayout.cshtml"; + +#line default +#line hidden + BeginContext(51, 26, true); + WriteLiteral("\r\n
Some body
\r\n\r\n"); + EndContext(); + DefineSection("Section1", async() => { + BeginContext(96, 39, true); + WriteLiteral("\r\n
This is in Section 1
\r\n"); + EndContext(); + } + ); + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.ir.txt new file mode 100644 index 0000000000..8e13c694a2 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.ir.txt @@ -0,0 +1,41 @@ +Document - + CSharpCode - + IntermediateToken - - CSharp - [assembly:global::Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorViewAttribute(null, typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml))] + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - (2:0,2 [46] Sections.cshtml) + IntermediateToken - (2:0,2 [46] Sections.cshtml) - CSharp - \n Layout = "_SectionTestLayout.cshtml";\n + CSharpCode - + IntermediateToken - - CSharp - BeginContext(51, 26, true); + HtmlContent - (51:3,0 [26] Sections.cshtml) + IntermediateToken - (51:3,0 [2] Sections.cshtml) - Html - \n + IntermediateToken - (53:4,0 [5] Sections.cshtml) - Html -
+ IntermediateToken - (58:4,5 [9] Sections.cshtml) - Html - Some body + IntermediateToken - (67:4,14 [6] Sections.cshtml) - Html -
+ IntermediateToken - (73:4,20 [4] Sections.cshtml) - Html - \n\n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + Section - - Section1 + CSharpCode - + IntermediateToken - - CSharp - BeginContext(96, 39, true); + HtmlContent - (96:6,19 [39] Sections.cshtml) + IntermediateToken - (96:6,19 [6] Sections.cshtml) - Html - \n + IntermediateToken - (102:7,4 [5] Sections.cshtml) - Html -
+ IntermediateToken - (107:7,9 [20] Sections.cshtml) - Html - This is in Section 1 + IntermediateToken - (127:7,29 [6] Sections.cshtml) - Html -
+ IntermediateToken - (133:7,35 [2] Sections.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/InjectDirectiveTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/InjectDirectiveTest.cs new file mode 100644 index 0000000000..81144b2265 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/InjectDirectiveTest.cs @@ -0,0 +1,225 @@ +// 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.Text; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class InjectDirectiveTest + { + [Fact] + public void InjectDirectivePass_Execute_DefinesProperty() + { + // Arrange + var codeDocument = CreateDocument(@" +@inject PropertyType PropertyName +"); + + var engine = CreateEngine(); + var pass = new InjectDirective.Pass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal(2, @class.Children.Count); + + var node = Assert.IsType(@class.Children[1]); + Assert.Equal("PropertyType", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + } + + [Fact] + public void InjectDirectivePass_Execute_DedupesPropertiesByName() + { + // Arrange + var codeDocument = CreateDocument(@" +@inject PropertyType PropertyName +@inject PropertyType2 PropertyName +"); + + var engine = CreateEngine(); + var pass = new InjectDirective.Pass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal(2, @class.Children.Count); + + var node = Assert.IsType(@class.Children[1]); + Assert.Equal("PropertyType2", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + } + + [Fact] + public void InjectDirectivePass_Execute_ExpandsTModel_WithDynamic() + { + // Arrange + var codeDocument = CreateDocument(@" +@inject PropertyType PropertyName +"); + + var engine = CreateEngine(); + var pass = new InjectDirective.Pass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal(2, @class.Children.Count); + + var node = Assert.IsType(@class.Children[1]); + Assert.Equal("PropertyType", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + } + + [Fact] + public void InjectDirectivePass_Execute_ExpandsTModel_WithModelTypeFirst() + { + // Arrange + var codeDocument = CreateDocument(@" +@model ModelType +@inject PropertyType PropertyName +"); + + var engine = CreateEngine(); + var pass = new InjectDirective.Pass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal(2, @class.Children.Count); + + var node = Assert.IsType(@class.Children[1]); + Assert.Equal("PropertyType", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + } + + [Fact] + public void InjectDirectivePass_Execute_ExpandsTModel_WithModelType() + { + // Arrange + var codeDocument = CreateDocument(@" +@inject PropertyType PropertyName +@model ModelType +"); + + var engine = CreateEngine(); + var pass = new InjectDirective.Pass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal(2, @class.Children.Count); + + var node = Assert.IsType(@class.Children[1]); + Assert.Equal("PropertyType", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + } + + private RazorCodeDocument CreateDocument(string content) + { + var source = RazorSourceDocument.Create(content, "test.cshtml"); + return RazorCodeDocument.Create(source); + } + + private ClassDeclarationIntermediateNode FindClassNode(IntermediateNode node) + { + var visitor = new ClassNodeVisitor(); + visitor.Visit(node); + return visitor.Node; + } + + private RazorEngine CreateEngine() + { + return RazorEngine.Create(b => + { + // Notice we're not registering the InjectDirective.Pass here so we can run it on demand. + b.AddDirective(InjectDirective.Directive); + b.AddDirective(ModelDirective.Directive); + }); + } + + private DocumentIntermediateNode CreateIRDocument(RazorEngine engine, RazorCodeDocument codeDocument) + { + for (var i = 0; i < engine.Phases.Count; i++) + { + var phase = engine.Phases[i]; + phase.Execute(codeDocument); + + if (phase is IRazorDocumentClassifierPhase) + { + break; + } + } + + return codeDocument.GetDocumentIntermediateNode(); + } + + private string GetCSharpContent(IntermediateNode node) + { + var builder = new StringBuilder(); + for (var i = 0; i < node.Children.Count; i++) + { + var child = node.Children[i] as IntermediateToken; + if (child.Kind == TokenKind.CSharp) + { + builder.Append(child.Content); + } + } + + return builder.ToString(); + } + + private class ClassNodeVisitor : IntermediateNodeWalker + { + public ClassDeclarationIntermediateNode Node { get; set; } + + public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node) + { + Node = node; + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/InjectTargetExtensionTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/InjectTargetExtensionTest.cs new file mode 100644 index 0000000000..fcc8b1123c --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/InjectTargetExtensionTest.cs @@ -0,0 +1,68 @@ +// 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 Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Microsoft.AspNetCore.Razor.Language.Legacy; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class InjectTargetExtensionTest + { + [Fact] + public void InjectDirectiveTargetExtension_WritesProperty() + { + // Arrange + var context = TestCodeRenderingContext.CreateRuntime(); + var target = new InjectTargetExtension(); + var node = new InjectIntermediateNode() + { + TypeName = "PropertyType", + MemberName = "PropertyName", + }; + + // Act + target.WriteInjectProperty(context, node); + + // Assert + Assert.Equal( + "[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]" + Environment.NewLine + + "public PropertyType PropertyName { get; private set; }" + Environment.NewLine, + context.CodeWriter.GenerateCode()); + } + + [Fact] + public void InjectDirectiveTargetExtension_WritesPropertyWithLinePragma_WhenSourceIsSet() + { + // Arrange + var context = TestCodeRenderingContext.CreateRuntime(); + var target = new InjectTargetExtension(); + var node = new InjectIntermediateNode() + { + TypeName = "PropertyType", + MemberName = "PropertyName", + Source = new SourceSpan( + filePath: "test-path", + absoluteIndex: 0, + lineIndex: 1, + characterIndex: 1, + length: 10) + }; + + // Act + target.WriteInjectProperty(context, node); + + // Assert + Assert.Equal( + "#line 2 \"test-path\"" + Environment.NewLine + + "[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]" + Environment.NewLine + + "public PropertyType PropertyName { get; private set; }" + Environment.NewLine + Environment.NewLine + + "#line default" + Environment.NewLine + + "#line hidden" + Environment.NewLine, + context.CodeWriter.GenerateCode()); + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/IntegrationTests/CodeGenerationIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/IntegrationTests/CodeGenerationIntegrationTest.cs new file mode 100644 index 0000000000..e7908a7346 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -0,0 +1,381 @@ +// 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.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.IntegrationTests; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Emit; +using Microsoft.CodeAnalysis.Razor; +using Microsoft.Extensions.DependencyModel; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.IntegrationTests +{ + public class CodeGenerationIntegrationTest : IntegrationTestBase + { + private const string CurrentMvcShim = "Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.dll"; + private static readonly RazorSourceDocument DefaultImports = MvcRazorTemplateEngine.GetDefaultImports(); + + [Fact] + public void InvalidNamespaceAtEOF_DesignTime() + { + var references = CreateCompilationReferences(CurrentMvcShim); + RunDesignTimeTest(references); + } + + [Fact] + public void IncompleteDirectives_DesignTime() + { + var appCode = @" +public class MyService +{ + public string Html { get; set; } +} +"; + + var references = CreateCompilationReferences(CurrentMvcShim, appCode); + RunDesignTimeTest(references); + } + + [Fact] + public void InheritsViewModel_DesignTime() + { + var appCode = @" +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Razor; + +public class MyBasePageForViews : RazorPage +{ + public override Task ExecuteAsync() + { + throw new System.NotImplementedException(); + } +} + +public class MyModel +{ + +} +"; + var references = CreateCompilationReferences(CurrentMvcShim, appCode); + RunDesignTimeTest(references); + } + + [Fact] + public void InheritsWithViewImports_DesignTime() + { + var appCode = @" +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Razor; + +public class MyBasePageForViews : RazorPage +{ + public override Task ExecuteAsync() + { + throw new System.NotImplementedException(); + } +} + +public class MyModel +{ + +} +"; + + var references = CreateCompilationReferences(CurrentMvcShim, appCode); + RunDesignTimeTest(references); + } + + [Fact] + public void Basic_DesignTime() + { + var references = CreateCompilationReferences(CurrentMvcShim); + RunDesignTimeTest(references); + } + + [Fact] + public void Sections_DesignTime() + { + var references = CreateCompilationReferences(CurrentMvcShim); + RunDesignTimeTest(references); + } + + [Fact] + public void _ViewImports_DesignTime() + { + var references = CreateCompilationReferences(CurrentMvcShim); + RunDesignTimeTest(references); + } + + [Fact] + public void Inject_DesignTime() + { + var appCode = @" +public class MyApp +{ + public string MyProperty { get; set; } +} +"; + var references = CreateCompilationReferences(CurrentMvcShim, appCode); + RunDesignTimeTest(references); + } + + [Fact] + public void InjectWithModel_DesignTime() + { + var appCode = @" +public class MyModel +{ + +} + +public class MyService +{ + public string Html { get; set; } +} + +public class MyApp +{ + public string MyProperty { get; set; } +} +"; + var references = CreateCompilationReferences(CurrentMvcShim, appCode); + RunDesignTimeTest(references); + } + + [Fact] + public void InjectWithSemicolon_DesignTime() + { + var appCode = @" +public class MyModel +{ + +} + +public class MyService +{ + public string Html { get; set; } +} + +public class MyApp +{ + public string MyProperty { get; set; } +} +"; + var references = CreateCompilationReferences(CurrentMvcShim, appCode); + RunDesignTimeTest(references); + } + + [Fact] + public void Model_DesignTime() + { + var references = CreateCompilationReferences(CurrentMvcShim); + RunDesignTimeTest(references); + } + + [Fact] + public void MultipleModels_DesignTime() + { + var appCode = @" +public class ThisShouldBeGenerated +{ + +}"; + + var references = CreateCompilationReferences(CurrentMvcShim, appCode); + RunDesignTimeTest(references); + } + + [Fact] + public void ModelExpressionTagHelper_DesignTime() + { + var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@" +using Microsoft.AspNetCore.Mvc.ViewFeatures; + +public class InputTestTagHelper : {typeof(TagHelper).FullName} +{{ + public ModelExpression For {{ get; set; }} +}} +"); + RunDesignTimeTest(references); + } + + [Fact] + public void ViewComponentTagHelper_DesignTime() + { + var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@" +public class TestViewComponent +{{ + public string Invoke(string firstName) + {{ + return firstName; + }} +}} + +[{typeof(HtmlTargetElementAttribute).FullName}] +public class AllTagHelper : {typeof(TagHelper).FullName} +{{ + public string Bar {{ get; set; }} +}} +"); + RunDesignTimeTest(references); + } + + private void RunDesignTimeTest( + IEnumerable compilationReferences, + IEnumerable expectedErrors = null) + { + // Arrange + var engine = CreateDesignTimeEngine(compilationReferences); + var document = CreateCodeDocument(); + + // Act + engine.Process(document); + + // Assert + AssertDocumentNodeMatchesBaseline(document.GetDocumentIntermediateNode()); + AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument()); + AssertSourceMappingsMatchBaseline(document); + AssertDocumentCompiles(document, compilationReferences, expectedErrors); + } + + private static IEnumerable CreateCompilationReferences(string mvcShimName, string appCode = null) + { + var shimReferences = CreateMvcShimReferences(mvcShimName); + return CreateAppCodeReferences(appCode, shimReferences); + } + + private void AssertDocumentCompiles( + RazorCodeDocument document, + IEnumerable compilationReferences, + IEnumerable expectedErrors = null) + { + var cSharp = document.GetCSharpDocument().GeneratedCode; + + var syntaxTree = CSharpSyntaxTree.ParseText(cSharp); + var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); + var compilation = CSharpCompilation.Create("CodeGenerationTestAssembly", new[] { syntaxTree }, compilationReferences, options); + + var diagnostics = compilation.GetDiagnostics(); + + var errors = diagnostics.Where(d => d.Severity >= DiagnosticSeverity.Warning); + + if (expectedErrors == null) + { + Assert.Empty(errors.Select(e => e.GetMessage())); + } + else + { + Assert.Equal(expectedErrors, errors.Select(e => e.GetMessage())); + } + } + + protected RazorEngine CreateDesignTimeEngine(IEnumerable references) + { + return RazorEngine.CreateDesignTime(b => + { + RazorExtensions.Register(b); + RazorExtensions.RegisterViewComponentTagHelpers(b); + + b.Features.Add(GetMetadataReferenceFeature(references)); + b.Features.Add(new CompilationTagHelperFeature()); + b.Features.Add(new DefaultTagHelperDescriptorProvider() { DesignTime = true }); + b.Features.Add(new ViewComponentTagHelperDescriptorProvider() { ForceEnabled = true }); + }); + } + + protected override void OnCreatingCodeDocument(ref RazorSourceDocument source, IList imports) + { + // It's important that we normalize the newlines in the default imports. The default imports will + // be created with Environment.NewLine, but we need to normalize to `\r\n` so that the indices + // are the same on xplat. + var buffer = new char[DefaultImports.Length]; + DefaultImports.CopyTo(0, buffer, 0, DefaultImports.Length); + + var text = new string(buffer); + text = Regex.Replace(text, "(? references, + string assemblyName) + { + var syntaxTree = new SyntaxTree[] { CSharpSyntaxTree.ParseText(text) }; + + var compilation = CSharpCompilation.Create( + assemblyName, + syntaxTree, + references, + options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + + var stream = new MemoryStream(); + var compilationResult = compilation.Emit(stream, options: new EmitOptions()); + stream.Position = 0; + + Assert.True(compilationResult.Success); + + return MetadataReference.CreateFromStream(stream); + } + + private static IRazorEngineFeature GetMetadataReferenceFeature(IEnumerable references) + { + return new DefaultMetadataReferenceFeature() + { + References = references.ToList() + }; + } + + private static IEnumerable CreateAppCodeReferences(string appCode, IEnumerable shimReferences) + { + var references = new List(shimReferences); + + if (appCode != null) + { + var appCodeSyntaxTrees = new List { CSharpSyntaxTree.ParseText(appCode) }; + + var compilation = CSharpCompilation.Create( + "AppCode", + appCodeSyntaxTrees, + shimReferences, + options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + var stream = new MemoryStream(); + var compilationResult = compilation.Emit(stream, options: new EmitOptions()); + stream.Position = 0; + + var diagString = string.Join(";", compilationResult.Diagnostics.Where(s => s.Severity == DiagnosticSeverity.Error).Select(s => s.ToString())); + Assert.True(compilationResult.Success, string.Format("Application code needed for tests didn't compile!: {0}", diagString)); + + references.Add(MetadataReference.CreateFromStream(stream)); + } + + return references; + } + + private static IEnumerable CreateMvcShimReferences(string mvcShimName) + { + var dllPath = Path.Combine(Directory.GetCurrentDirectory(), mvcShimName); + var assembly = Assembly.LoadFile(dllPath); + var assemblyDependencyContext = DependencyContext.Load(assembly); + + var assemblyReferencePaths = assemblyDependencyContext.CompileLibraries.SelectMany(l => l.ResolveReferencePaths()); + + var references = assemblyReferencePaths + .Select(assemblyPath => MetadataReference.CreateFromFile(assemblyPath)) + .ToList(); + + Assert.NotEmpty(references); + + return references; + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/LegacySectionTargetExtensionTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/LegacySectionTargetExtensionTest.cs new file mode 100644 index 0000000000..bef1d0718f --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/LegacySectionTargetExtensionTest.cs @@ -0,0 +1,46 @@ +// 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.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Xunit; + +namespace Microsoft.AspNetCore.Razor.Language.Extensions +{ + public class LegacySectionTargetExtensionTest + { + [Fact] + public void WriteSection_WritesSectionCode_DesignTime() + { + // Arrange + var node = new SectionIntermediateNode() + { + Children = + { + new CSharpExpressionIntermediateNode(), + }, + SectionName = "MySection" + }; + + var extension = new LegacySectionTargetExtension() + { + SectionMethodName = "CreateSection" + }; + + var context = TestCodeRenderingContext.CreateDesignTime(); + + // Act + extension.WriteSection(context, node); + + // Assert + var expected = @"CreateSection(""MySection"", async(__razor_section_writer) => { + Render Children +} +); +"; + + var output = context.CodeWriter.GenerateCode(); + Assert.Equal(expected, output); + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test.csproj b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test.csproj new file mode 100644 index 0000000000..d23e43f499 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test.csproj @@ -0,0 +1,55 @@ + + + + + + netcoreapp2.0;net461 + netcoreapp2.0 + true + $(DefaultItemExcludes);TestFiles\** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + Content + PreserveNewest + Build + + + + + + + + + + + + + + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ModelDirectiveTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ModelDirectiveTest.cs new file mode 100644 index 0000000000..c366918999 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ModelDirectiveTest.cs @@ -0,0 +1,307 @@ +// 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.Text; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class ModelDirectiveTest + { + [Fact] + public void ModelDirective_GetModelType_GetsTypeFromFirstWellFormedDirective() + { + // Arrange + var codeDocument = CreateDocument(@" +@model Type1 +@model Type2 +@model +"); + + var engine = CreateEngine(); + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + var result = ModelDirective.GetModelType(irDocument); + + // Assert + Assert.Equal("Type1", result); + } + + [Fact] + public void ModelDirective_GetModelType_DefaultsToDynamic() + { + // Arrange + var codeDocument = CreateDocument(@" "); + + var engine = CreateEngine(); + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + var result = ModelDirective.GetModelType(irDocument); + + // Assert + Assert.Equal("dynamic", result); + } + + [Fact] + public void ModelDirectivePass_Execute_ReplacesTModelInBaseType() + { + // Arrange + var codeDocument = CreateDocument(@" +@inherits BaseType +@model Type1 +"); + + var engine = CreateEngine(); + var pass = new ModelDirective.Pass(designTime: false) + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal("BaseType", @class.BaseType); + } + + [Fact] + public void ModelDirectivePass_Execute_ReplacesTModelInBaseType_DifferentOrdering() + { + // Arrange + var codeDocument = CreateDocument(@" +@model Type1 +@inherits BaseType +@model Type2 +"); + + var engine = CreateEngine(); + var pass = new ModelDirective.Pass(designTime: false) + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal("BaseType", @class.BaseType); + } + + [Fact] + public void ModelDirectivePass_Execute_NoOpWithoutTModel() + { + // Arrange + var codeDocument = CreateDocument(@" +@inherits BaseType +@model Type1 +"); + + var engine = CreateEngine(); + var pass = new ModelDirective.Pass(designTime: false) + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal("BaseType", @class.BaseType); + } + + [Fact] + public void ModelDirectivePass_Execute_ReplacesTModelInBaseType_DefaultDynamic() + { + // Arrange + var codeDocument = CreateDocument(@" +@inherits BaseType +"); + + var engine = CreateEngine(); + var pass = new ModelDirective.Pass(designTime: false) + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal("BaseType", @class.BaseType); + } + + [Fact] + public void ModelDirectivePass_DesignTime_AddsTModelUsingDirective() + { + // Arrange + var codeDocument = CreateDocument(@" +@inherits BaseType +"); + + var engine = CreateEngine(); + var pass = new ModelDirective.Pass(designTime: true) + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal("BaseType", @class.BaseType); + + var @namespace = FindNamespaceNode(irDocument); + var usingNode = Assert.IsType(@namespace.Children[0]); + Assert.Equal($"TModel = global::{typeof(object).FullName}", usingNode.Content); + } + + [Fact] + public void ModelDirectivePass_DesignTime_WithModel_AddsTModelUsingDirective() + { + // Arrange + var codeDocument = CreateDocument(@" +@inherits BaseType +@model SomeType +"); + + var engine = CreateEngine(); + var pass = new ModelDirective.Pass(designTime: true) + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.NotNull(@class); + Assert.Equal("BaseType", @class.BaseType); + + var @namespace = FindNamespaceNode(irDocument); + var usingNode = Assert.IsType(@namespace.Children[0]); + Assert.Equal($"TModel = global::System.Object", usingNode.Content); + } + + private RazorCodeDocument CreateDocument(string content) + { + var source = RazorSourceDocument.Create(content, "test.cshtml"); + return RazorCodeDocument.Create(source); + } + + private ClassDeclarationIntermediateNode FindClassNode(IntermediateNode node) + { + var visitor = new ClassNodeVisitor(); + visitor.Visit(node); + return visitor.Node; + } + + private NamespaceDeclarationIntermediateNode FindNamespaceNode(IntermediateNode node) + { + var visitor = new NamespaceNodeVisitor(); + visitor.Visit(node); + return visitor.Node; + } + + private RazorEngine CreateEngine() + { + return RazorEngine.Create(b => + { + // Notice we're not registering the ModelDirective.Pass here so we can run it on demand. + b.AddDirective(ModelDirective.Directive); + + // There's some special interaction with the inherits directive + InheritsDirective.Register(b); + }); + } + + private DocumentIntermediateNode CreateIRDocument(RazorEngine engine, RazorCodeDocument codeDocument) + { + for (var i = 0; i < engine.Phases.Count; i++) + { + var phase = engine.Phases[i]; + phase.Execute(codeDocument); + + if (phase is IRazorDocumentClassifierPhase) + { + break; + } + } + + // InheritsDirectivePass needs to run before ModelDirective. + var pass = new InheritsDirectivePass() + { + Engine = engine + }; + pass.Execute(codeDocument, codeDocument.GetDocumentIntermediateNode()); + + return codeDocument.GetDocumentIntermediateNode(); + } + + private string GetCSharpContent(IntermediateNode node) + { + var builder = new StringBuilder(); + for (var i = 0; i < node.Children.Count; i++) + { + var child = node.Children[i] as IntermediateToken; + if (child.Kind == TokenKind.CSharp) + { + builder.Append(child.Content); + } + } + + return builder.ToString(); + } + + private class ClassNodeVisitor : IntermediateNodeWalker + { + public ClassDeclarationIntermediateNode Node { get; set; } + + public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node) + { + Node = node; + } + } + + private class NamespaceNodeVisitor : IntermediateNodeWalker + { + public NamespaceDeclarationIntermediateNode Node { get; set; } + + public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node) + { + Node = node; + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ModelExpressionPassTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ModelExpressionPassTest.cs new file mode 100644 index 0000000000..604460c8f8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ModelExpressionPassTest.cs @@ -0,0 +1,208 @@ +// 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.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Microsoft.AspNetCore.Razor.Language.Legacy; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class ModelExpressionPassTest + { + [Fact] + public void ModelExpressionPass_NonModelExpressionProperty_Ignored() + { + // Arrange + var codeDocument = CreateDocument(@" +@addTagHelper TestTagHelper, TestAssembly +

"); + + var tagHelpers = new[] + { + TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly") + .BoundAttributeDescriptor(attribute => + attribute + .Name("Foo") + .TypeName("System.Int32")) + .TagMatchingRuleDescriptor(rule => + rule.RequireTagName("p")) + .Build() + }; + + var engine = CreateEngine(tagHelpers); + var pass = new ModelExpressionPass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var tagHelper = FindTagHelperNode(irDocument); + var setProperty = tagHelper.Children.OfType().Single(); + + var token = Assert.IsType(Assert.Single(setProperty.Children)); + Assert.True(token.IsCSharp); + Assert.Equal("17", token.Content); + } + + [Fact] + public void ModelExpressionPass_ModelExpressionProperty_SimpleExpression() + { + // Arrange + + // Using \r\n here because we verify line mappings + var codeDocument = CreateDocument( + "@addTagHelper TestTagHelper, TestAssembly\r\n

"); + + var tagHelpers = new[] + { + TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly") + .BoundAttributeDescriptor(attribute => + attribute + .Name("Foo") + .TypeName("Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression")) + .TagMatchingRuleDescriptor(rule => + rule.RequireTagName("p")) + .Build() + }; + + var engine = CreateEngine(tagHelpers); + var pass = new ModelExpressionPass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var tagHelper = FindTagHelperNode(irDocument); + var setProperty = tagHelper.Children.OfType().Single(); + + var expression = Assert.IsType(Assert.Single(setProperty.Children)); + Assert.Equal("ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Bar)", GetCSharpContent(expression)); + + var originalNode = Assert.IsType(expression.Children[2]); + Assert.Equal(TokenKind.CSharp, originalNode.Kind); + Assert.Equal("Bar", originalNode.Content); + Assert.Equal(new SourceSpan("test.cshtml", 51, 1, 8, 3), originalNode.Source.Value); + } + + [Fact] + public void ModelExpressionPass_ModelExpressionProperty_ComplexExpression() + { + // Arrange + + // Using \r\n here because we verify line mappings + var codeDocument = CreateDocument( + "@addTagHelper TestTagHelper, TestAssembly\r\n

"); + + var tagHelpers = new[] + { + TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly") + .BoundAttributeDescriptor(attribute => + attribute + .Name("Foo") + .TypeName("Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression")) + .TagMatchingRuleDescriptor(rule => + rule.RequireTagName("p")) + .Build() + }; + + var engine = CreateEngine(tagHelpers); + var pass = new ModelExpressionPass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var tagHelper = FindTagHelperNode(irDocument); + var setProperty = tagHelper.Children.OfType().Single(); + + var expression = Assert.IsType(Assert.Single(setProperty.Children)); + Assert.Equal("ModelExpressionProvider.CreateModelExpression(ViewData, __model => Bar)", GetCSharpContent(expression)); + + var originalNode = Assert.IsType(expression.Children[1]); + Assert.Equal(TokenKind.CSharp, originalNode.Kind); + Assert.Equal("Bar", originalNode.Content); + Assert.Equal(new SourceSpan("test.cshtml", 52, 1, 9, 3), originalNode.Source.Value); + } + + private RazorCodeDocument CreateDocument(string content) + { + var source = RazorSourceDocument.Create(content, "test.cshtml"); + return RazorCodeDocument.Create(source); + } + + private RazorEngine CreateEngine(params TagHelperDescriptor[] tagHelpers) + { + return RazorEngine.Create(b => + { + b.Features.Add(new TestTagHelperFeature(tagHelpers)); + }); + } + + private DocumentIntermediateNode CreateIRDocument(RazorEngine engine, RazorCodeDocument codeDocument) + { + for (var i = 0; i < engine.Phases.Count; i++) + { + var phase = engine.Phases[i]; + phase.Execute(codeDocument); + + if (phase is IRazorDirectiveClassifierPhase) + { + break; + } + } + + return codeDocument.GetDocumentIntermediateNode(); + } + + private TagHelperIntermediateNode FindTagHelperNode(IntermediateNode node) + { + var visitor = new TagHelperNodeVisitor(); + visitor.Visit(node); + return visitor.Node; + } + + private string GetCSharpContent(IntermediateNode node) + { + var builder = new StringBuilder(); + for (var i = 0; i < node.Children.Count; i++) + { + var child = node.Children[i] as IntermediateToken; + if (child.Kind == TokenKind.CSharp) + { + builder.Append(child.Content); + } + } + + return builder.ToString(); + } + + private class TagHelperNodeVisitor : IntermediateNodeWalker + { + public TagHelperIntermediateNode Node { get; set; } + + public override void VisitTagHelper(TagHelperIntermediateNode node) + { + Node = node; + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/MvcRazorTemplateEngineTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/MvcRazorTemplateEngineTest.cs new file mode 100644 index 0000000000..b4954469bc --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/MvcRazorTemplateEngineTest.cs @@ -0,0 +1,116 @@ +// 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; +using Microsoft.AspNetCore.Razor.Language; +using Moq; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class MvcRazorTemplateEngineTest + { + [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( + RazorEngine.Create(), + new TestRazorProject()); + + // 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 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( + RazorEngine.Create(), + new TestRazorProject()); + + // 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( + RazorEngine.Create(), + new TestRazorProject()); + + // 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); + } + + [Fact] + public void CreateCodeDocument_SetsRelativePathOnOutput() + { + // Arrange + var path = "/Views/Home/Index.cshtml"; + var item = new TestRazorProjectItem(path) + { + Content = "Hello world", + }; + var project = new TestRazorProject(new List() { item, }); + + var mvcRazorTemplateEngine = new MvcRazorTemplateEngine( + RazorEngine.Create(), + project); + + // Act + var codeDocument = mvcRazorTemplateEngine.CreateCodeDocument(path); + + // Assert + Assert.Equal(path, codeDocument.GetRelativePath()); + } + + private string GetContent(RazorSourceDocument imports) + { + var contentChars = new char[imports.Length]; + imports.CopyTo(0, contentChars, 0, imports.Length); + return new string(contentChars); + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/MvcViewDocumentClassifierPassTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/MvcViewDocumentClassifierPassTest.cs new file mode 100644 index 0000000000..d0b8361965 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/MvcViewDocumentClassifierPassTest.cs @@ -0,0 +1,242 @@ +// 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 Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class MvcViewDocumentClassifierPassTest + { + [Fact] + public void MvcViewDocumentClassifierPass_SetsDocumentKind() + { + // Arrange + var codeDocument = CreateDocument("some-content"); + var engine = CreateEngine(); + var irDocument = CreateIRDocument(engine, codeDocument); + var pass = new MvcViewDocumentClassifierPass + { + Engine = engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + Assert.Equal("mvc.1.0.view", irDocument.DocumentKind); + } + + [Fact] + public void MvcViewDocumentClassifierPass_NoOpsIfDocumentKindIsAlreadySet() + { + // Arrange + var codeDocument = CreateDocument("some-content"); + var engine = CreateEngine(); + var irDocument = CreateIRDocument(engine, codeDocument); + irDocument.DocumentKind = "some-value"; + var pass = new MvcViewDocumentClassifierPass + { + Engine = engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + Assert.Equal("some-value", irDocument.DocumentKind); + } + + [Fact] + public void MvcViewDocumentClassifierPass_SetsNamespace() + { + // Arrange + var codeDocument = CreateDocument("some-content"); + var engine = CreateEngine(); + var irDocument = CreateIRDocument(engine, codeDocument); + var pass = new MvcViewDocumentClassifierPass + { + Engine = engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal("AspNetCore", visitor.Namespace.Content); + } + + [Fact] + public void MvcViewDocumentClassifierPass_SetsClass() + { + // Arrange + var codeDocument = CreateDocument("some-content"); + var engine = CreateEngine(); + var irDocument = CreateIRDocument(engine, codeDocument); + var pass = new MvcViewDocumentClassifierPass + { + Engine = engine + }; + codeDocument.SetRelativePath("Test.cshtml"); + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); + Assert.Equal("Test_cshtml", visitor.Class.ClassName); + } + + [Theory] + [InlineData("/Views/Home/Index.cshtml", "_Views_Home_Index_cshtml")] + [InlineData("/Areas/MyArea/Views/Home/About.cshtml", "_Areas_MyArea_Views_Home_About_cshtml")] + public void MvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(string relativePath, string expected) + { + // Arrange + var codeDocument = CreateDocument("some-content"); + codeDocument.SetRelativePath(relativePath); + var engine = CreateEngine(); + var irDocument = CreateIRDocument(engine, codeDocument); + var pass = new MvcViewDocumentClassifierPass + { + Engine = engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal(expected, visitor.Class.ClassName); + } + + [Fact] + public void MvcViewDocumentClassifierPass_UsesAbsolutePath_IfRelativePathIsNotSet() + { + // Arrange + var expected = "x___application_Views_Home_Index_cshtml"; + var path = @"x::\application\Views\Home\Index.cshtml"; + var codeDocument = CreateDocument("some-content", path); + var engine = CreateEngine(); + var irDocument = CreateIRDocument(engine, codeDocument); + var pass = new MvcViewDocumentClassifierPass + { + Engine = engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal(expected, visitor.Class.ClassName); + } + + [Fact] + public void MvcViewDocumentClassifierPass_SanitizesClassName() + { + // Arrange + var expected = "path_with_invalid_chars"; + var codeDocument = CreateDocument("some-content"); + codeDocument.SetRelativePath("path.with+invalid-chars"); + var engine = CreateEngine(); + var irDocument = CreateIRDocument(engine, codeDocument); + var pass = new MvcViewDocumentClassifierPass + { + Engine = engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal(expected, visitor.Class.ClassName); + } + + [Fact] + public void MvcViewDocumentClassifierPass_SetsUpExecuteAsyncMethod() + { + // Arrange + var codeDocument = CreateDocument("some-content"); + var engine = CreateEngine(); + var irDocument = CreateIRDocument(engine, codeDocument); + var pass = new MvcViewDocumentClassifierPass + { + Engine = engine + }; + + // Act + pass.Execute(codeDocument, irDocument); + var visitor = new Visitor(); + visitor.Visit(irDocument); + + // Assert + Assert.Equal("ExecuteAsync", visitor.Method.MethodName); + Assert.Equal("global::System.Threading.Tasks.Task", visitor.Method.ReturnType); + Assert.Equal(new[] { "public", "async", "override" }, visitor.Method.Modifiers); + } + + private static RazorCodeDocument CreateDocument(string content, string filePath = null) + { + filePath = filePath ?? Path.Combine(Directory.GetCurrentDirectory(), "Test.cshtml"); + + var source = RazorSourceDocument.Create(content, filePath); + return RazorCodeDocument.Create(source); + } + + private static RazorEngine CreateEngine() => RazorEngine.Create(); + + private static DocumentIntermediateNode CreateIRDocument(RazorEngine engine, RazorCodeDocument codeDocument) + { + for (var i = 0; i < engine.Phases.Count; i++) + { + var phase = engine.Phases[i]; + phase.Execute(codeDocument); + + if (phase is IRazorIntermediateNodeLoweringPhase) + { + break; + } + } + + return codeDocument.GetDocumentIntermediateNode(); + } + + private class Visitor : IntermediateNodeWalker + { + public NamespaceDeclarationIntermediateNode Namespace { get; private set; } + + public ClassDeclarationIntermediateNode Class { get; private set; } + + public MethodDeclarationIntermediateNode Method { get; private set; } + + public override void VisitMethodDeclaration(MethodDeclarationIntermediateNode node) + { + Method = node; + } + + public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node) + { + Namespace = node; + base.VisitNamespaceDeclaration(node); + } + + public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node) + { + Class = node; + base.VisitClassDeclaration(node); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/Properties/AssemblyInfo.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..3337ebeac2 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// 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.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/SourceMappingsSerializer.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/SourceMappingsSerializer.cs new file mode 100644 index 0000000000..c081118d86 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/SourceMappingsSerializer.cs @@ -0,0 +1,54 @@ +// 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.Text; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public static class SourceMappingsSerializer + { + public static string Serialize(RazorCSharpDocument csharpDocument, RazorSourceDocument sourceDocument) + { + var builder = new StringBuilder(); + var sourceFilePath = sourceDocument.FilePath; + var charBuffer = new char[sourceDocument.Length]; + sourceDocument.CopyTo(0, charBuffer, 0, sourceDocument.Length); + var sourceContent = new string(charBuffer); + + for (var i = 0; i < csharpDocument.SourceMappings.Count; i++) + { + var sourceMapping = csharpDocument.SourceMappings[i]; + if (!string.Equals(sourceMapping.OriginalSpan.FilePath, sourceFilePath, StringComparison.Ordinal)) + { + continue; + } + + builder.Append("Source Location: "); + AppendMappingLocation(builder, sourceMapping.OriginalSpan, sourceContent); + + builder.Append("Generated Location: "); + AppendMappingLocation(builder, sourceMapping.GeneratedSpan, csharpDocument.GeneratedCode); + + builder.AppendLine(); + } + + return builder.ToString(); + } + + private static void AppendMappingLocation(StringBuilder builder, SourceSpan location, string content) + { + builder + .AppendLine(location.ToString()) + .Append("|"); + + for (var i = 0; i < location.Length; i++) + { + builder.Append(content[location.AbsoluteIndex + i]); + } + + builder.AppendLine("|"); + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TagHelperDescriptorExtensionsTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TagHelperDescriptorExtensionsTest.cs new file mode 100644 index 0000000000..f080719b5a --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TagHelperDescriptorExtensionsTest.cs @@ -0,0 +1,82 @@ +// 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; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class TagHelperDescriptorExtensionsTest + { + [Fact] + public void IsViewComponentKind_ReturnsFalse_ForNonVCTHDescriptor() + { + // Arrange + var tagHelper = CreateTagHelperDescriptor(); + + // Act + var result = tagHelper.IsViewComponentKind(); + + // Assert + Assert.False(result); + } + + [Fact] + public void IsViewComponentKind_ReturnsTrue_ForVCTHDescriptor() + { + // Arrange + var tagHelper = CreateViewComponentTagHelperDescriptor(); + + // Act + var result = tagHelper.IsViewComponentKind(); + + // Assert + Assert.True(result); + } + + [Fact] + public void GetViewComponentName_ReturnsNull_ForNonVCTHDescriptor() + { + //Arrange + var tagHelper = CreateTagHelperDescriptor(); + + // Act + var result = tagHelper.GetViewComponentName(); + + // Assert + Assert.Null(result); + } + + [Fact] + public void GetViewComponentName_ReturnsName_ForVCTHDescriptor() + { + // Arrange + var tagHelper = CreateViewComponentTagHelperDescriptor("ViewComponentName"); + + // Act + var result = tagHelper.GetViewComponentName(); + + // Assert + Assert.Equal("ViewComponentName", result); + } + + private static TagHelperDescriptor CreateTagHelperDescriptor() + { + var tagHelper = TagHelperDescriptorBuilder.Create("TypeName", "AssemblyName") + .TagMatchingRuleDescriptor(rule => rule.RequireTagName("tag-name")) + .Build(); + + return tagHelper; + } + + private static TagHelperDescriptor CreateViewComponentTagHelperDescriptor(string name = "ViewComponentName") + { + var tagHelper = TagHelperDescriptorBuilder.Create(ViewComponentTagHelperConventions.Kind, "TypeName", "AssemblyName") + .TagMatchingRuleDescriptor(rule => rule.RequireTagName("tag-name")) + .AddMetadata(ViewComponentTagHelperMetadata.Name, name) + .Build(); + + return tagHelper; + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml new file mode 100644 index 0000000000..a20b20dae8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml @@ -0,0 +1,8 @@ +

+ Hello world + @string.Format("{0}", "Hello") +
+@{ + var cls = "foo"; +} +

diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_DesignTime.codegen.cs new file mode 100644 index 0000000000..3edf343f5e --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_DesignTime.codegen.cs @@ -0,0 +1,71 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Basic_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml" + __o = this.ToString(); + +#line default +#line hidden +#line 3 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml" +__o = string.Format("{0}", "Hello"); + +#line default +#line hidden +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml" + + var cls = "foo"; + +#line default +#line hidden +#line 8 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml" + if(cls != null) { + +#line default +#line hidden +#line 8 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml" + __o = cls; + +#line default +#line hidden +#line 8 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml" + } + +#line default +#line hidden + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_DesignTime.ir.txt new file mode 100644 index 0000000000..ba42b7a0f4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_DesignTime.ir.txt @@ -0,0 +1,62 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Basic_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + HtmlContent - (0:0,0 [4] Basic.cshtml) + IntermediateToken - (0:0,0 [4] Basic.cshtml) - Html -

+ IntermediateToken - (30:0,30 [23] Basic.cshtml) - Html - \n Hello world\n + CSharpExpression - (54:2,5 [29] Basic.cshtml) + IntermediateToken - (54:2,5 [29] Basic.cshtml) - CSharp - string.Format("{0}", "Hello") + HtmlContent - (83:2,34 [10] Basic.cshtml) + IntermediateToken - (83:2,34 [2] Basic.cshtml) - Html - \n + IntermediateToken - (85:3,0 [6] Basic.cshtml) - Html -
+ IntermediateToken - (91:3,6 [2] Basic.cshtml) - Html - \n + CSharpCode - (95:4,2 [25] Basic.cshtml) + IntermediateToken - (95:4,2 [25] Basic.cshtml) - CSharp - \n var cls = "foo";\n + HtmlContent - (123:7,0 [2] Basic.cshtml) + IntermediateToken - (123:7,0 [2] Basic.cshtml) - Html -

+ IntermediateToken - (162:7,39 [2] Basic.cshtml) - Html - \n + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_DesignTime.mappings.txt new file mode 100644 index 0000000000..e25ebcea7e --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_DesignTime.mappings.txt @@ -0,0 +1,34 @@ +Source Location: (13:0,13 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml) +|this.ToString()| +Generated Location: (1037:26,13 [15] ) +|this.ToString()| + +Source Location: (54:2,5 [29] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml) +|string.Format("{0}", "Hello")| +Generated Location: (1173:31,6 [29] ) +|string.Format("{0}", "Hello")| + +Source Location: (95:4,2 [25] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml) +| + var cls = "foo"; +| +Generated Location: (1319:36,2 [25] ) +| + var cls = "foo"; +| + +Source Location: (134:7,11 [18] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml) +|if(cls != null) { | +Generated Location: (1467:42,11 [18] ) +|if(cls != null) { | + +Source Location: (153:7,30 [3] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml) +|cls| +Generated Location: (1629:47,30 [3] ) +|cls| + +Source Location: (156:7,33 [2] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml) +| }| +Generated Location: (1780:52,33 [2] ) +| }| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_Runtime.codegen.cs new file mode 100644 index 0000000000..b8ce28e05f --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic_Runtime.codegen.cs @@ -0,0 +1,92 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "4120ddad9d4353ed260e0585fe71080d78ff8ab3" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Basic_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + BeginContext(0, 4, true); + WriteLiteral("

+ IntermediateToken - (30:0,30 [19] Basic.cshtml) - Html - \n Hello world\n + IntermediateToken - (49:2,0 [4] Basic.cshtml) - Html - + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + CSharpCode - + IntermediateToken - - CSharp - BeginContext(54, 29, false); + CSharpExpression - (54:2,5 [29] Basic.cshtml) + IntermediateToken - (54:2,5 [29] Basic.cshtml) - CSharp - string.Format("{0}", "Hello") + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + CSharpCode - + IntermediateToken - - CSharp - BeginContext(83, 10, true); + HtmlContent - (83:2,34 [10] Basic.cshtml) + IntermediateToken - (83:2,34 [2] Basic.cshtml) - Html - \n + IntermediateToken - (85:3,0 [6] Basic.cshtml) - Html -
+ IntermediateToken - (91:3,6 [2] Basic.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + CSharpCode - (95:4,2 [25] Basic.cshtml) + IntermediateToken - (95:4,2 [25] Basic.cshtml) - CSharp - \n var cls = "foo";\n + CSharpCode - + IntermediateToken - - CSharp - BeginContext(123, 2, true); + HtmlContent - (123:7,0 [2] Basic.cshtml) + IntermediateToken - (123:7,0 [2] Basic.cshtml) - Html -

+ IntermediateToken - (162:7,39 [2] Basic.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml new file mode 100644 index 0000000000..ecc90de2d6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml @@ -0,0 +1,8 @@ +@* These test files validate that end-to-end, incomplete directives don't throw. *@ + +@model +@model + +@inject +@inject +@inject MyService diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.codegen.cs new file mode 100644 index 0000000000..f47ba2071e --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.codegen.cs @@ -0,0 +1,44 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_IncompleteDirectives_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +MyService __typeHelper = default(MyService); + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.diagnostics.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.diagnostics.txt new file mode 100644 index 0000000000..72a8fa589b --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.diagnostics.txt @@ -0,0 +1,6 @@ +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(3,7): Error RZ9999: The 'model' directive expects a type name. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(4,1): Error RZ9999: The 'model' directive may only occur once per document. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(4,8): Error RZ9999: The 'model' directive expects a type name. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(6,8): Error RZ9999: The 'inject' directive expects a type name. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(7,9): Error RZ9999: The 'inject' directive expects a type name. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,26): Error RZ9999: The 'inject' directive expects an identifier. diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.ir.txt new file mode 100644 index 0000000000..79491f3568 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.ir.txt @@ -0,0 +1,54 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_IncompleteDirectives_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (133:7,8 [17] IncompleteDirectives.cshtml) - MyService + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + HtmlContent - (83:0,83 [4] IncompleteDirectives.cshtml) + IntermediateToken - (83:0,83 [4] IncompleteDirectives.cshtml) - Html - \n\n + MalformedDirective - (87:2,0 [6] IncompleteDirectives.cshtml) - model + HtmlContent - (93:2,6 [2] IncompleteDirectives.cshtml) + IntermediateToken - (93:2,6 [2] IncompleteDirectives.cshtml) - Html - \n + MalformedDirective - (95:3,0 [7] IncompleteDirectives.cshtml) - model + HtmlContent - (102:3,7 [4] IncompleteDirectives.cshtml) + IntermediateToken - (102:3,7 [4] IncompleteDirectives.cshtml) - Html - \n\n + MalformedDirective - (106:5,0 [7] IncompleteDirectives.cshtml) - inject + HtmlContent - (113:5,7 [2] IncompleteDirectives.cshtml) + IntermediateToken - (113:5,7 [2] IncompleteDirectives.cshtml) - Html - \n + MalformedDirective - (115:6,0 [8] IncompleteDirectives.cshtml) - inject + HtmlContent - (123:6,8 [2] IncompleteDirectives.cshtml) + IntermediateToken - (123:6,8 [2] IncompleteDirectives.cshtml) - Html - \n + MalformedDirective - (125:7,0 [25] IncompleteDirectives.cshtml) - inject + DirectiveToken - (133:7,8 [17] IncompleteDirectives.cshtml) - MyService + HtmlContent - (150:7,25 [2] IncompleteDirectives.cshtml) + IntermediateToken - (150:7,25 [2] IncompleteDirectives.cshtml) - Html - \n + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.mappings.txt new file mode 100644 index 0000000000..a0f227e239 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_DesignTime.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (133:7,8 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml) +|MyService| +Generated Location: (687:18,0 [17] ) +|MyService| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_Runtime.codegen.cs new file mode 100644 index 0000000000..e9170ae11c --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_Runtime.codegen.cs @@ -0,0 +1,51 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "844eb91b909a14b78feddd5e6866563b5a75e021" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_IncompleteDirectives_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + BeginContext(83, 4, true); + WriteLiteral("\r\n\r\n"); + EndContext(); + BeginContext(93, 2, true); + WriteLiteral("\r\n"); + EndContext(); + BeginContext(102, 4, true); + WriteLiteral("\r\n\r\n"); + EndContext(); + BeginContext(113, 2, true); + WriteLiteral("\r\n"); + EndContext(); + BeginContext(123, 2, true); + WriteLiteral("\r\n"); + EndContext(); + BeginContext(150, 2, true); + WriteLiteral("\r\n"); + EndContext(); + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_Runtime.diagnostics.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_Runtime.diagnostics.txt new file mode 100644 index 0000000000..72a8fa589b --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_Runtime.diagnostics.txt @@ -0,0 +1,6 @@ +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(3,7): Error RZ9999: The 'model' directive expects a type name. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(4,1): Error RZ9999: The 'model' directive may only occur once per document. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(4,8): Error RZ9999: The 'model' directive expects a type name. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(6,8): Error RZ9999: The 'inject' directive expects a type name. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(7,9): Error RZ9999: The 'inject' directive expects a type name. +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml(8,26): Error RZ9999: The 'inject' directive expects an identifier. diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_Runtime.ir.txt new file mode 100644 index 0000000000..8bb3264f43 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives_Runtime.ir.txt @@ -0,0 +1,58 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_IncompleteDirectives_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - + IntermediateToken - - CSharp - BeginContext(83, 4, true); + HtmlContent - (83:0,83 [4] IncompleteDirectives.cshtml) + IntermediateToken - (83:0,83 [4] IncompleteDirectives.cshtml) - Html - \n\n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + MalformedDirective - (87:2,0 [6] IncompleteDirectives.cshtml) - model + CSharpCode - + IntermediateToken - - CSharp - BeginContext(93, 2, true); + HtmlContent - (93:2,6 [2] IncompleteDirectives.cshtml) + IntermediateToken - (93:2,6 [2] IncompleteDirectives.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + MalformedDirective - (95:3,0 [7] IncompleteDirectives.cshtml) - model + CSharpCode - + IntermediateToken - - CSharp - BeginContext(102, 4, true); + HtmlContent - (102:3,7 [4] IncompleteDirectives.cshtml) + IntermediateToken - (102:3,7 [4] IncompleteDirectives.cshtml) - Html - \n\n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + MalformedDirective - (106:5,0 [7] IncompleteDirectives.cshtml) - inject + CSharpCode - + IntermediateToken - - CSharp - BeginContext(113, 2, true); + HtmlContent - (113:5,7 [2] IncompleteDirectives.cshtml) + IntermediateToken - (113:5,7 [2] IncompleteDirectives.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + MalformedDirective - (115:6,0 [8] IncompleteDirectives.cshtml) - inject + CSharpCode - + IntermediateToken - - CSharp - BeginContext(123, 2, true); + HtmlContent - (123:6,8 [2] IncompleteDirectives.cshtml) + IntermediateToken - (123:6,8 [2] IncompleteDirectives.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + MalformedDirective - (125:7,0 [25] IncompleteDirectives.cshtml) - inject + DirectiveToken - (133:7,8 [17] IncompleteDirectives.cshtml) - MyService + CSharpCode - + IntermediateToken - - CSharp - BeginContext(150, 2, true); + HtmlContent - (150:7,25 [2] IncompleteDirectives.cshtml) + IntermediateToken - (150:7,25 [2] IncompleteDirectives.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml new file mode 100644 index 0000000000..38efd570da --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml @@ -0,0 +1,2 @@ +@inherits MyBasePageForViews +@model MyModel diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_DesignTime.codegen.cs new file mode 100644 index 0000000000..0c96a6c7e0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_DesignTime.codegen.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel_cshtml : MyBasePageForViews + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +MyBasePageForViews __typeHelper = default(MyBasePageForViews); + } + ))(); + ((System.Action)(() => { +MyModel __typeHelper = default(MyModel); + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_DesignTime.ir.txt new file mode 100644 index 0000000000..1fba17672d --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_DesignTime.ir.txt @@ -0,0 +1,37 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel_cshtml - MyBasePageForViews - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (10:0,10 [26] InheritsViewModel.cshtml) - MyBasePageForViews + DirectiveToken - (45:1,7 [7] InheritsViewModel.cshtml) - MyModel + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_DesignTime.mappings.txt new file mode 100644 index 0000000000..4f38bd7343 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_DesignTime.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (10:0,10 [26] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml) +|MyBasePageForViews| +Generated Location: (654:18,0 [26] ) +|MyBasePageForViews| + +Source Location: (45:1,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml) +|MyModel| +Generated Location: (794:22,0 [7] ) +|MyModel| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs new file mode 100644 index 0000000000..af9db74379 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs @@ -0,0 +1,33 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "91cf923452a86b2906083cb0236d6d5b3bc528ef" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel_cshtml : MyBasePageForViews + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.ir.txt new file mode 100644 index 0000000000..b18e254c9f --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.ir.txt @@ -0,0 +1,16 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel_cshtml - MyBasePageForViews - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml new file mode 100644 index 0000000000..c735e2e429 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml @@ -0,0 +1 @@ +@model MyModel diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_DesignTime.codegen.cs new file mode 100644 index 0000000000..a4a69f2b7f --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_DesignTime.codegen.cs @@ -0,0 +1,44 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports_cshtml : MyBasePageForViews + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +MyModel __typeHelper = default(MyModel); + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_DesignTime.ir.txt new file mode 100644 index 0000000000..2da50d158b --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_DesignTime.ir.txt @@ -0,0 +1,37 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports_cshtml - MyBasePageForViews - + DesignTimeDirective - + DirectiveToken - (10:0,10 [26] InheritsWithViewImports_Imports0.cshtml) - MyBasePageForViews + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (7:0,7 [7] InheritsWithViewImports.cshtml) - MyModel + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_DesignTime.mappings.txt new file mode 100644 index 0000000000..bd614d72eb --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_DesignTime.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml) +|MyModel| +Generated Location: (660:18,0 [7] ) +|MyModel| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Imports0.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Imports0.cshtml new file mode 100644 index 0000000000..4c14f15bad --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Imports0.cshtml @@ -0,0 +1 @@ +@inherits MyBasePageForViews diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs new file mode 100644 index 0000000000..5ede728cf8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs @@ -0,0 +1,33 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "cf2e52e7d1326775fe4ece983a7f8ee1f62235a0" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports_cshtml : MyBasePageForViews + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.ir.txt new file mode 100644 index 0000000000..0f47fce86b --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.ir.txt @@ -0,0 +1,16 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports_cshtml - MyBasePageForViews - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject.cshtml new file mode 100644 index 0000000000..0aa749dd3f --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject.cshtml @@ -0,0 +1 @@ +@inject MyApp MyPropertyName diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml new file mode 100644 index 0000000000..d699f1e754 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml @@ -0,0 +1,3 @@ +@model MyModel +@inject MyApp MyPropertyName +@inject MyService Html diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_DesignTime.codegen.cs new file mode 100644 index 0000000000..10050cba80 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_DesignTime.codegen.cs @@ -0,0 +1,62 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +MyModel __typeHelper = default(MyModel); + } + ))(); + ((System.Action)(() => { +MyApp __typeHelper = default(MyApp); + } + ))(); + ((System.Action)(() => { +global::System.Object MyPropertyName = null; + } + ))(); + ((System.Action)(() => { +MyService __typeHelper = default(MyService); + } + ))(); + ((System.Action)(() => { +global::System.Object Html = null; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyService Html { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName { get; private set; } + [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; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_DesignTime.ir.txt new file mode 100644 index 0000000000..e1d660ce8d --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_DesignTime.ir.txt @@ -0,0 +1,41 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (7:0,7 [7] InjectWithModel.cshtml) - MyModel + DirectiveToken - (24:1,8 [5] InjectWithModel.cshtml) - MyApp + DirectiveToken - (30:1,14 [14] InjectWithModel.cshtml) - MyPropertyName + DirectiveToken - (54:2,8 [17] InjectWithModel.cshtml) - MyService + DirectiveToken - (72:2,26 [4] InjectWithModel.cshtml) - Html + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_DesignTime.mappings.txt new file mode 100644 index 0000000000..64bb4804b3 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_DesignTime.mappings.txt @@ -0,0 +1,25 @@ +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +|MyModel| +Generated Location: (682:18,0 [7] ) +|MyModel| + +Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +|MyApp| +Generated Location: (784:22,0 [5] ) +|MyApp| + +Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +|MyPropertyName| +Generated Location: (904:26,22 [14] ) +|MyPropertyName| + +Source Location: (54:2,8 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +|MyService| +Generated Location: (988:30,0 [17] ) +|MyService| + +Source Location: (72:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +|Html| +Generated Location: (1132:34,22 [4] ) +|Html| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs new file mode 100644 index 0000000000..c3846121e1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs @@ -0,0 +1,35 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "a039b7091118c718dc3023b6ac58d9645cb58e59" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyService Html { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName { get; private set; } + [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; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.ir.txt new file mode 100644 index 0000000000..2e1c3deb3e --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.ir.txt @@ -0,0 +1,17 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml new file mode 100644 index 0000000000..8cd61913e4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml @@ -0,0 +1,5 @@ +@model MyModel +@inject MyApp MyPropertyName; +@inject MyService Html; +@inject MyApp MyPropertyName2 ; +@inject MyService Html2 ; diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.codegen.cs new file mode 100644 index 0000000000..2c3776aedd --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.codegen.cs @@ -0,0 +1,82 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +MyModel __typeHelper = default(MyModel); + } + ))(); + ((System.Action)(() => { +MyApp __typeHelper = default(MyApp); + } + ))(); + ((System.Action)(() => { +global::System.Object MyPropertyName = null; + } + ))(); + ((System.Action)(() => { +MyService __typeHelper = default(MyService); + } + ))(); + ((System.Action)(() => { +global::System.Object Html = null; + } + ))(); + ((System.Action)(() => { +MyApp __typeHelper = default(MyApp); + } + ))(); + ((System.Action)(() => { +global::System.Object MyPropertyName2 = null; + } + ))(); + ((System.Action)(() => { +MyService __typeHelper = default(MyService); + } + ))(); + ((System.Action)(() => { +global::System.Object Html2 = null; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyService Html2 { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName2 { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyService Html { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName { get; private set; } + [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; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.ir.txt new file mode 100644 index 0000000000..4c0240ef2d --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.ir.txt @@ -0,0 +1,47 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (7:0,7 [7] InjectWithSemicolon.cshtml) - MyModel + DirectiveToken - (24:1,8 [5] InjectWithSemicolon.cshtml) - MyApp + DirectiveToken - (30:1,14 [14] InjectWithSemicolon.cshtml) - MyPropertyName + DirectiveToken - (58:2,8 [17] InjectWithSemicolon.cshtml) - MyService + DirectiveToken - (76:2,26 [4] InjectWithSemicolon.cshtml) - Html + DirectiveToken - (93:3,8 [5] InjectWithSemicolon.cshtml) - MyApp + DirectiveToken - (99:3,14 [15] InjectWithSemicolon.cshtml) - MyPropertyName2 + DirectiveToken - (129:4,8 [17] InjectWithSemicolon.cshtml) - MyService + DirectiveToken - (147:4,26 [5] InjectWithSemicolon.cshtml) - Html2 + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.mappings.txt new file mode 100644 index 0000000000..fb80df37b7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.mappings.txt @@ -0,0 +1,45 @@ +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyModel| +Generated Location: (686:18,0 [7] ) +|MyModel| + +Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyApp| +Generated Location: (788:22,0 [5] ) +|MyApp| + +Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyPropertyName| +Generated Location: (908:26,22 [14] ) +|MyPropertyName| + +Source Location: (58:2,8 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyService| +Generated Location: (992:30,0 [17] ) +|MyService| + +Source Location: (76:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|Html| +Generated Location: (1136:34,22 [4] ) +|Html| + +Source Location: (93:3,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyApp| +Generated Location: (1210:38,0 [5] ) +|MyApp| + +Source Location: (99:3,14 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyPropertyName2| +Generated Location: (1330:42,22 [15] ) +|MyPropertyName2| + +Source Location: (129:4,8 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyService| +Generated Location: (1415:46,0 [17] ) +|MyService| + +Source Location: (147:4,26 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|Html2| +Generated Location: (1559:50,22 [5] ) +|Html2| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs new file mode 100644 index 0000000000..4dd7659e08 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs @@ -0,0 +1,39 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "5010aab35d235175dab517f8018e41aee9a2ac7f" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyService Html2 { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName2 { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyService Html { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName { get; private set; } + [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; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.ir.txt new file mode 100644 index 0000000000..b624d6b15c --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.ir.txt @@ -0,0 +1,19 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_DesignTime.codegen.cs new file mode 100644 index 0000000000..b8e43e2f76 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_DesignTime.codegen.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inject_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +MyApp __typeHelper = default(MyApp); + } + ))(); + ((System.Action)(() => { +global::System.Object MyPropertyName = null; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName { get; private set; } + [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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_DesignTime.ir.txt new file mode 100644 index 0000000000..e00df79298 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_DesignTime.ir.txt @@ -0,0 +1,38 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inject_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (8:0,8 [5] Inject.cshtml) - MyApp + DirectiveToken - (14:0,14 [14] Inject.cshtml) - MyPropertyName + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_DesignTime.mappings.txt new file mode 100644 index 0000000000..ec01d63774 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_DesignTime.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (8:0,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject.cshtml) +|MyApp| +Generated Location: (673:18,0 [5] ) +|MyApp| + +Source Location: (14:0,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject.cshtml) +|MyPropertyName| +Generated Location: (793:22,22 [14] ) +|MyPropertyName| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_Runtime.codegen.cs new file mode 100644 index 0000000000..941237e909 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_Runtime.codegen.cs @@ -0,0 +1,35 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "c711078454f5b0e8d2cb77d9cb7fa88cca32b884" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inject_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName { get; private set; } + [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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_Runtime.ir.txt new file mode 100644 index 0000000000..32a3c51ac7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject_Runtime.ir.txt @@ -0,0 +1,17 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inject_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF.cshtml new file mode 100644 index 0000000000..6dfb72bc31 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF.cshtml @@ -0,0 +1 @@ +@namespace Test. \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.codegen.cs new file mode 100644 index 0000000000..d4bee96fbd --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.codegen.cs @@ -0,0 +1,40 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InvalidNamespaceAtEOF_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.diagnostics.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.diagnostics.txt new file mode 100644 index 0000000000..cfbf688e18 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.diagnostics.txt @@ -0,0 +1 @@ +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF.cshtml(1,2): Error RZ9999: "namespace" is a reserved word and cannot be used in implicit expressions. An explicit expression ("@()") must be used. diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.ir.txt new file mode 100644 index 0000000000..59f3e7b070 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.ir.txt @@ -0,0 +1,37 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InvalidNamespaceAtEOF_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + HtmlContent - (10:0,10 [6] InvalidNamespaceAtEOF.cshtml) + IntermediateToken - (10:0,10 [6] InvalidNamespaceAtEOF.cshtml) - Html - Test. + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_DesignTime.mappings.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_Runtime.codegen.cs new file mode 100644 index 0000000000..d292eeebcc --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_Runtime.codegen.cs @@ -0,0 +1,36 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "de132bd3e2a46a0d2ec953a168427c01e5829cde" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InvalidNamespaceAtEOF_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + BeginContext(10, 6, true); + WriteLiteral(" Test."); + EndContext(); + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_Runtime.diagnostics.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_Runtime.diagnostics.txt new file mode 100644 index 0000000000..cfbf688e18 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_Runtime.diagnostics.txt @@ -0,0 +1 @@ +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF.cshtml(1,2): Error RZ9999: "namespace" is a reserved word and cannot be used in implicit expressions. An explicit expression ("@()") must be used. diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_Runtime.ir.txt new file mode 100644 index 0000000000..fb0bab7833 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InvalidNamespaceAtEOF_Runtime.ir.txt @@ -0,0 +1,22 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InvalidNamespaceAtEOF_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - + IntermediateToken - - CSharp - BeginContext(10, 6, true); + HtmlContent - (10:0,10 [6] InvalidNamespaceAtEOF.cshtml) + IntermediateToken - (10:0,10 [6] InvalidNamespaceAtEOF.cshtml) - Html - Test. + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model.cshtml new file mode 100644 index 0000000000..4b73b2dc53 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model.cshtml @@ -0,0 +1 @@ +@model System.Collections.IEnumerable diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml new file mode 100644 index 0000000000..c488b1e443 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml @@ -0,0 +1,6 @@ +@model DateTime + +@addTagHelper "InputTestTagHelper, AppCode" + + + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_DesignTime.codegen.cs new file mode 100644 index 0000000000..8dc9887854 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_DesignTime.codegen.cs @@ -0,0 +1,61 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + private global::InputTestTagHelper __InputTestTagHelper; + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +DateTime __typeHelper = default(DateTime); + } + ))(); + ((System.Action)(() => { +global::System.Object __typeHelper = "InputTestTagHelper, AppCode"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + __InputTestTagHelper = CreateTagHelper(); +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml" +__InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Date); + +#line default +#line hidden + __InputTestTagHelper = CreateTagHelper(); +#line 6 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml" +__InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => Model); + +#line default +#line hidden + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_DesignTime.ir.txt new file mode 100644 index 0000000000..c4bbcf7a73 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_DesignTime.ir.txt @@ -0,0 +1,66 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DefaultTagHelperRuntime - + FieldDeclaration - - private - global::InputTestTagHelper - __InputTestTagHelper + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (7:0,7 [8] ModelExpressionTagHelper.cshtml) - DateTime + DirectiveToken - (33:2,14 [29] ModelExpressionTagHelper.cshtml) - "InputTestTagHelper, AppCode" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + HtmlContent - (17:1,0 [2] ModelExpressionTagHelper.cshtml) + IntermediateToken - (17:1,0 [2] ModelExpressionTagHelper.cshtml) - Html - \n + HtmlContent - (62:2,43 [4] ModelExpressionTagHelper.cshtml) + IntermediateToken - (62:2,43 [4] ModelExpressionTagHelper.cshtml) - Html - \n\n + TagHelper - (66:4,0 [25] ModelExpressionTagHelper.cshtml) - input-test - TagMode.SelfClosing + DefaultTagHelperBody - + DefaultTagHelperCreate - - InputTestTagHelper + DefaultTagHelperProperty - (83:4,17 [4] ModelExpressionTagHelper.cshtml) - for - Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression InputTestTagHelper.For - HtmlAttributeValueStyle.DoubleQuotes + CSharpExpression - + IntermediateToken - - CSharp - ModelExpressionProvider.CreateModelExpression(ViewData, __model => + IntermediateToken - - CSharp - __model. + IntermediateToken - (83:4,17 [4] ModelExpressionTagHelper.cshtml) - CSharp - Date + IntermediateToken - - CSharp - ) + DefaultTagHelperExecute - + HtmlContent - (91:4,25 [2] ModelExpressionTagHelper.cshtml) + IntermediateToken - (91:4,25 [2] ModelExpressionTagHelper.cshtml) - Html - \n + TagHelper - (93:5,0 [27] ModelExpressionTagHelper.cshtml) - input-test - TagMode.SelfClosing + DefaultTagHelperBody - + DefaultTagHelperCreate - - InputTestTagHelper + DefaultTagHelperProperty - (110:5,17 [6] ModelExpressionTagHelper.cshtml) - for - Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression InputTestTagHelper.For - HtmlAttributeValueStyle.DoubleQuotes + CSharpExpression - + IntermediateToken - - CSharp - ModelExpressionProvider.CreateModelExpression(ViewData, __model => + IntermediateToken - (111:5,18 [5] ModelExpressionTagHelper.cshtml) - CSharp - Model + IntermediateToken - - CSharp - ) + DefaultTagHelperExecute - + HtmlContent - (120:5,27 [2] ModelExpressionTagHelper.cshtml) + IntermediateToken - (120:5,27 [2] ModelExpressionTagHelper.cshtml) - Html - \n + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_DesignTime.mappings.txt new file mode 100644 index 0000000000..0a0cb62f30 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_DesignTime.mappings.txt @@ -0,0 +1,20 @@ +Source Location: (7:0,7 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml) +|DateTime| +Generated Location: (758:19,0 [8] ) +|DateTime| + +Source Location: (33:2,14 [29] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml) +|"InputTestTagHelper, AppCode"| +Generated Location: (899:23,37 [29] ) +|"InputTestTagHelper, AppCode"| + +Source Location: (83:4,17 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml) +|Date| +Generated Location: (1547:36,102 [4] ) +|Date| + +Source Location: (111:5,18 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml) +|Model| +Generated Location: (1863:42,94 [5] ) +|Model| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs new file mode 100644 index 0000000000..8fb69e52ed --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs @@ -0,0 +1,104 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "0906a816db301fe624bbe5a96c4b3013071ea492" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #line hidden + #pragma warning disable 0169 + private string __tagHelperStringValueBuffer; + #pragma warning restore 0169 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext; + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner(); + 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::InputTestTagHelper __InputTestTagHelper; + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + BeginContext(17, 2, true); + WriteLiteral("\r\n"); + EndContext(); + BeginContext(64, 2, true); + WriteLiteral("\r\n"); + EndContext(); + BeginContext(66, 25, false); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, "test", async() => { + } + ); + __InputTestTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__InputTestTagHelper); +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml" +__InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Date); + +#line default +#line hidden + __tagHelperExecutionContext.AddTagHelperAttribute("for", __InputTestTagHelper.For, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + EndContext(); + BeginContext(91, 2, true); + WriteLiteral("\r\n"); + EndContext(); + BeginContext(93, 27, false); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, "test", async() => { + } + ); + __InputTestTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__InputTestTagHelper); +#line 6 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml" +__InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => Model); + +#line default +#line hidden + __tagHelperExecutionContext.AddTagHelperAttribute("for", __InputTestTagHelper.For, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + EndContext(); + BeginContext(120, 2, true); + WriteLiteral("\r\n"); + EndContext(); + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.ir.txt new file mode 100644 index 0000000000..b336b645b0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.ir.txt @@ -0,0 +1,69 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DefaultTagHelperRuntime - + FieldDeclaration - - private - global::InputTestTagHelper - __InputTestTagHelper + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - + IntermediateToken - - CSharp - BeginContext(17, 2, true); + HtmlContent - (17:1,0 [2] ModelExpressionTagHelper.cshtml) + IntermediateToken - (17:1,0 [2] ModelExpressionTagHelper.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + CSharpCode - + IntermediateToken - - CSharp - BeginContext(64, 2, true); + HtmlContent - (64:3,0 [2] ModelExpressionTagHelper.cshtml) + IntermediateToken - (64:3,0 [2] ModelExpressionTagHelper.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + CSharpCode - + IntermediateToken - - CSharp - BeginContext(66, 25, false); + TagHelper - (66:4,0 [25] ModelExpressionTagHelper.cshtml) - input-test - TagMode.SelfClosing + DefaultTagHelperBody - + DefaultTagHelperCreate - - InputTestTagHelper + DefaultTagHelperProperty - (83:4,17 [4] ModelExpressionTagHelper.cshtml) - for - Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression InputTestTagHelper.For - HtmlAttributeValueStyle.DoubleQuotes + CSharpExpression - + IntermediateToken - - CSharp - ModelExpressionProvider.CreateModelExpression(ViewData, __model => + IntermediateToken - - CSharp - __model. + IntermediateToken - (83:4,17 [4] ModelExpressionTagHelper.cshtml) - CSharp - Date + IntermediateToken - - CSharp - ) + DefaultTagHelperExecute - + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + CSharpCode - + IntermediateToken - - CSharp - BeginContext(91, 2, true); + HtmlContent - (91:4,25 [2] ModelExpressionTagHelper.cshtml) + IntermediateToken - (91:4,25 [2] ModelExpressionTagHelper.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + CSharpCode - + IntermediateToken - - CSharp - BeginContext(93, 27, false); + TagHelper - (93:5,0 [27] ModelExpressionTagHelper.cshtml) - input-test - TagMode.SelfClosing + DefaultTagHelperBody - + DefaultTagHelperCreate - - InputTestTagHelper + DefaultTagHelperProperty - (110:5,17 [6] ModelExpressionTagHelper.cshtml) - for - Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression InputTestTagHelper.For - HtmlAttributeValueStyle.DoubleQuotes + CSharpExpression - + IntermediateToken - - CSharp - ModelExpressionProvider.CreateModelExpression(ViewData, __model => + IntermediateToken - (111:5,18 [5] ModelExpressionTagHelper.cshtml) - CSharp - Model + IntermediateToken - - CSharp - ) + DefaultTagHelperExecute - + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + CSharpCode - + IntermediateToken - - CSharp - BeginContext(120, 2, true); + HtmlContent - (120:5,27 [2] ModelExpressionTagHelper.cshtml) + IntermediateToken - (120:5,27 [2] ModelExpressionTagHelper.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_DesignTime.codegen.cs new file mode 100644 index 0000000000..b12ca26651 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_DesignTime.codegen.cs @@ -0,0 +1,44 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Model_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +System.Collections.IEnumerable __typeHelper = default(System.Collections.IEnumerable); + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_DesignTime.ir.txt new file mode 100644 index 0000000000..75faeeb1ca --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_DesignTime.ir.txt @@ -0,0 +1,36 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Model_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (7:0,7 [30] Model.cshtml) - System.Collections.IEnumerable + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_DesignTime.mappings.txt new file mode 100644 index 0000000000..226138531b --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_DesignTime.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (7:0,7 [30] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model.cshtml) +|System.Collections.IEnumerable| +Generated Location: (695:18,0 [30] ) +|System.Collections.IEnumerable| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs new file mode 100644 index 0000000000..cd4f57b409 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs @@ -0,0 +1,33 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "31c5b047a450ac9f6dc4116626667d26bfb657ba" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Model_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.ir.txt new file mode 100644 index 0000000000..3f8d705381 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.ir.txt @@ -0,0 +1,16 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Model_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels.cshtml new file mode 100644 index 0000000000..350f93b776 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels.cshtml @@ -0,0 +1,2 @@ +@model ThisShouldBeGenerated +@model System.Collections.IEnumerable diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.codegen.cs new file mode 100644 index 0000000000..a766ae3900 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.codegen.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MultipleModels_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +ThisShouldBeGenerated __typeHelper = default(ThisShouldBeGenerated); + } + ))(); + ((System.Action)(() => { +System.Collections.IEnumerable __typeHelper = default(System.Collections.IEnumerable); + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.diagnostics.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.diagnostics.txt new file mode 100644 index 0000000000..b051568470 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.diagnostics.txt @@ -0,0 +1 @@ +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels.cshtml(2,1): Error RZ9999: The 'model' directive may only occur once per document. diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.ir.txt new file mode 100644 index 0000000000..d8bb1d6d9d --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.ir.txt @@ -0,0 +1,39 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MultipleModels_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (7:0,7 [21] MultipleModels.cshtml) - ThisShouldBeGenerated + DirectiveToken - (37:1,7 [30] MultipleModels.cshtml) - System.Collections.IEnumerable + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + MalformedDirective - (30:1,0 [39] MultipleModels.cshtml) - model + DirectiveToken - (37:1,7 [30] MultipleModels.cshtml) - System.Collections.IEnumerable + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.mappings.txt new file mode 100644 index 0000000000..65348abd7b --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels_DesignTime.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (7:0,7 [21] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels.cshtml) +|ThisShouldBeGenerated| +Generated Location: (695:18,0 [21] ) +|ThisShouldBeGenerated| + +Source Location: (37:1,7 [30] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MultipleModels.cshtml) +|System.Collections.IEnumerable| +Generated Location: (825:22,0 [30] ) +|System.Collections.IEnumerable| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml new file mode 100644 index 0000000000..81f73f2ca6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml @@ -0,0 +1,9 @@ +@{ + Layout = "_SectionTestLayout.cshtml"; +} + +

Some body
+ +@section Section1 { +
This is in Section 1
+} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs new file mode 100644 index 0000000000..771d845938 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs @@ -0,0 +1,53 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object Section1 = null; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" + + Layout = "_SectionTestLayout.cshtml"; + +#line default +#line hidden + DefineSection("Section1", async(__razor_section_writer) => { + } + ); + } + #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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.ir.txt new file mode 100644 index 0000000000..c4456d30ca --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.ir.txt @@ -0,0 +1,51 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (86:6,9 [8] Sections.cshtml) - Section1 + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - (2:0,2 [46] Sections.cshtml) + IntermediateToken - (2:0,2 [46] Sections.cshtml) - CSharp - \n Layout = "_SectionTestLayout.cshtml";\n + HtmlContent - (51:3,0 [26] Sections.cshtml) + IntermediateToken - (51:3,0 [2] Sections.cshtml) - Html - \n + IntermediateToken - (53:4,0 [5] Sections.cshtml) - Html -
+ IntermediateToken - (58:4,5 [9] Sections.cshtml) - Html - Some body + IntermediateToken - (67:4,14 [6] Sections.cshtml) - Html -
+ IntermediateToken - (73:4,20 [4] Sections.cshtml) - Html - \n\n + Section - - Section1 + HtmlContent - (96:6,19 [39] Sections.cshtml) + IntermediateToken - (96:6,19 [6] Sections.cshtml) - Html - \n + IntermediateToken - (102:7,4 [5] Sections.cshtml) - Html -
+ IntermediateToken - (107:7,9 [20] Sections.cshtml) - Html - This is in Section 1 + IntermediateToken - (127:7,29 [6] Sections.cshtml) - Html -
+ IntermediateToken - (133:7,35 [2] Sections.cshtml) - Html - \n + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt new file mode 100644 index 0000000000..5a6cfe78f2 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt @@ -0,0 +1,14 @@ +Source Location: (86:6,9 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) +|Section1| +Generated Location: (697:18,22 [8] ) +|Section1| + +Source Location: (2:0,2 [46] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) +| + Layout = "_SectionTestLayout.cshtml"; +| +Generated Location: (1132:30,2 [46] ) +| + Layout = "_SectionTestLayout.cshtml"; +| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml new file mode 100644 index 0000000000..0430ccfc69 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml @@ -0,0 +1,6 @@ +@addTagHelper "*, AppCode" +@{ + var foo = "Hello"; +} + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_DesignTime.codegen.cs new file mode 100644 index 0000000000..027acd82f3 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_DesignTime.codegen.cs @@ -0,0 +1,81 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + private global::AllTagHelper __AllTagHelper; + private global::AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml.__Generated__TestViewComponentTagHelper __TestViewComponentTagHelper; + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, AppCode"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml" + + var foo = "Hello"; + +#line default +#line hidden + __AllTagHelper = CreateTagHelper(); + __TestViewComponentTagHelper = CreateTagHelper(); +#line 6 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml" + __o = foo; + +#line default +#line hidden + __TestViewComponentTagHelper.firstName = string.Empty; + __AllTagHelper.Bar = " World"; + } + #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 Html { get; private set; } + [Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("vc:test")] +public class __Generated__TestViewComponentTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper +{ + private readonly global::Microsoft.AspNetCore.Mvc.IViewComponentHelper _helper = null; + public __Generated__TestViewComponentTagHelper(global::Microsoft.AspNetCore.Mvc.IViewComponentHelper helper) + { + _helper = helper; + } + [Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNotBoundAttribute, global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewContextAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.ViewContext ViewContext { get; set; } + public System.String firstName { get; set; } + public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) + { + (_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext); + var content = await _helper.InvokeAsync("Test", new { firstName }); + output.TagName = null; + output.Content.SetHtmlContent(content); + } +} + + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_DesignTime.ir.txt new file mode 100644 index 0000000000..11b8d7c99c --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_DesignTime.ir.txt @@ -0,0 +1,58 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DefaultTagHelperRuntime - + FieldDeclaration - - private - global::AllTagHelper - __AllTagHelper + FieldDeclaration - - private - global::AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml.__Generated__TestViewComponentTagHelper - __TestViewComponentTagHelper + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (14:0,14 [12] ViewComponentTagHelper.cshtml) - "*, AppCode" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + HtmlContent - (26:0,26 [2] ViewComponentTagHelper.cshtml) + IntermediateToken - (26:0,26 [2] ViewComponentTagHelper.cshtml) - Html - \n + CSharpCode - (30:1,2 [26] ViewComponentTagHelper.cshtml) + IntermediateToken - (30:1,2 [26] ViewComponentTagHelper.cshtml) - CSharp - \n var foo = "Hello";\n + HtmlContent - (59:4,0 [2] ViewComponentTagHelper.cshtml) + IntermediateToken - (59:4,0 [2] ViewComponentTagHelper.cshtml) - Html - \n + TagHelper - (61:5,0 [50] ViewComponentTagHelper.cshtml) - vc:test - TagMode.StartTagAndEndTag + DefaultTagHelperBody - + DefaultTagHelperCreate - - AllTagHelper + DefaultTagHelperCreate - - AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml.__Generated__TestViewComponentTagHelper + DefaultTagHelperProperty - (82:5,21 [4] ViewComponentTagHelper.cshtml) - first-name - string TestViewComponentTagHelper.firstName - HtmlAttributeValueStyle.DoubleQuotes + CSharpExpression - (83:5,22 [3] ViewComponentTagHelper.cshtml) + IntermediateToken - (83:5,22 [3] ViewComponentTagHelper.cshtml) - CSharp - foo + DefaultTagHelperProperty - (93:5,32 [6] ViewComponentTagHelper.cshtml) - bar - string AllTagHelper.Bar - HtmlAttributeValueStyle.DoubleQuotes + HtmlContent - (93:5,32 [6] ViewComponentTagHelper.cshtml) + IntermediateToken - (93:5,32 [6] ViewComponentTagHelper.cshtml) - Html - World + DefaultTagHelperExecute - + Inject - + Inject - + Inject - + Inject - + Inject - + CSharpCode - + IntermediateToken - - CSharp - [Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("vc:test")]\npublic class __Generated__TestViewComponentTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper\n{\n private readonly global::Microsoft.AspNetCore.Mvc.IViewComponentHelper _helper = null;\n public __Generated__TestViewComponentTagHelper(global::Microsoft.AspNetCore.Mvc.IViewComponentHelper helper)\n {\n _helper = helper;\n }\n [Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNotBoundAttribute, global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewContextAttribute]\n public global::Microsoft.AspNetCore.Mvc.Rendering.ViewContext ViewContext { get; set; }\n public System.String firstName { get; set; }\n public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output)\n {\n (_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext);\n var content = await _helper.InvokeAsync("Test", new { firstName });\n output.TagName = null;\n output.Content.SetHtmlContent(content);\n }\n}\n diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_DesignTime.mappings.txt new file mode 100644 index 0000000000..9344e08ed2 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_DesignTime.mappings.txt @@ -0,0 +1,19 @@ +Source Location: (14:0,14 [12] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml) +|"*, AppCode"| +Generated Location: (973:20,37 [12] ) +|"*, AppCode"| + +Source Location: (30:1,2 [26] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml) +| + var foo = "Hello"; +| +Generated Location: (1419:32,2 [26] ) +| + var foo = "Hello"; +| + +Source Location: (83:5,22 [3] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml) +|foo| +Generated Location: (1877:40,22 [3] ) +|foo| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_Runtime.codegen.cs new file mode 100644 index 0000000000..2c85bf513c --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_Runtime.codegen.cs @@ -0,0 +1,110 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "6a0ad3c59f3a87877c36928472f0508bd40cdd8c" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + private global::AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml.__Generated__TestViewComponentTagHelper __TestViewComponentTagHelper; + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_0 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("bar", " World", global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + #line hidden + #pragma warning disable 0169 + private string __tagHelperStringValueBuffer; + #pragma warning restore 0169 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext; + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner(); + 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; + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml" + + var foo = "Hello"; + +#line default +#line hidden + BeginContext(59, 2, true); + WriteLiteral("\r\n"); + EndContext(); + BeginContext(61, 50, false); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("vc:test", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + } + ); + __AllTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__AllTagHelper); + __TestViewComponentTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__TestViewComponentTagHelper); + BeginWriteTagHelperAttribute(); +#line 6 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper.cshtml" + WriteLiteral(foo); + +#line default +#line hidden + __tagHelperStringValueBuffer = EndWriteTagHelperAttribute(); + __TestViewComponentTagHelper.firstName = __tagHelperStringValueBuffer; + __tagHelperExecutionContext.AddTagHelperAttribute("first-name", __TestViewComponentTagHelper.firstName, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + __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(); + EndContext(); + } + #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 Html { get; private set; } + [Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("vc:test")] +public class __Generated__TestViewComponentTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper +{ + private readonly global::Microsoft.AspNetCore.Mvc.IViewComponentHelper _helper = null; + public __Generated__TestViewComponentTagHelper(global::Microsoft.AspNetCore.Mvc.IViewComponentHelper helper) + { + _helper = helper; + } + [Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNotBoundAttribute, global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewContextAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.ViewContext ViewContext { get; set; } + public System.String firstName { get; set; } + public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) + { + (_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext); + var content = await _helper.InvokeAsync("Test", new { firstName }); + output.TagName = null; + output.Content.SetHtmlContent(content); + } +} + + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_Runtime.ir.txt new file mode 100644 index 0000000000..a1678711eb --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelper_Runtime.ir.txt @@ -0,0 +1,43 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + FieldDeclaration - - private - global::AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml.__Generated__TestViewComponentTagHelper - __TestViewComponentTagHelper + PreallocatedTagHelperPropertyValue - - __tagHelperAttribute_0 - bar - World - HtmlAttributeValueStyle.DoubleQuotes + DefaultTagHelperRuntime - + FieldDeclaration - - private - global::AllTagHelper - __AllTagHelper + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - (30:1,2 [26] ViewComponentTagHelper.cshtml) + IntermediateToken - (30:1,2 [26] ViewComponentTagHelper.cshtml) - CSharp - \n var foo = "Hello";\n + CSharpCode - + IntermediateToken - - CSharp - BeginContext(59, 2, true); + HtmlContent - (59:4,0 [2] ViewComponentTagHelper.cshtml) + IntermediateToken - (59:4,0 [2] ViewComponentTagHelper.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + CSharpCode - + IntermediateToken - - CSharp - BeginContext(61, 50, false); + TagHelper - (61:5,0 [50] ViewComponentTagHelper.cshtml) - vc:test - TagMode.StartTagAndEndTag + DefaultTagHelperBody - + DefaultTagHelperCreate - - AllTagHelper + DefaultTagHelperCreate - - AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ViewComponentTagHelper_cshtml.__Generated__TestViewComponentTagHelper + DefaultTagHelperProperty - (82:5,21 [4] ViewComponentTagHelper.cshtml) - first-name - string TestViewComponentTagHelper.firstName - HtmlAttributeValueStyle.DoubleQuotes + CSharpExpression - (83:5,22 [3] ViewComponentTagHelper.cshtml) + IntermediateToken - (83:5,22 [3] ViewComponentTagHelper.cshtml) - CSharp - foo + PreallocatedTagHelperProperty - (93:5,32 [6] ViewComponentTagHelper.cshtml) - __tagHelperAttribute_0 - bar - Bar + DefaultTagHelperExecute - + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + Inject - + Inject - + Inject - + Inject - + Inject - + CSharpCode - + IntermediateToken - - CSharp - [Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("vc:test")]\npublic class __Generated__TestViewComponentTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper\n{\n private readonly global::Microsoft.AspNetCore.Mvc.IViewComponentHelper _helper = null;\n public __Generated__TestViewComponentTagHelper(global::Microsoft.AspNetCore.Mvc.IViewComponentHelper helper)\n {\n _helper = helper;\n }\n [Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNotBoundAttribute, global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewContextAttribute]\n public global::Microsoft.AspNetCore.Mvc.Rendering.ViewContext ViewContext { get; set; }\n public System.String firstName { get; set; }\n public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output)\n {\n (_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext);\n var content = await _helper.InvokeAsync("Test", new { firstName });\n output.TagName = null;\n output.Content.SetHtmlContent(content);\n }\n}\n diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports.cshtml new file mode 100644 index 0000000000..f4e110d289 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports.cshtml @@ -0,0 +1 @@ +@inject IHtmlHelper Helper \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_DesignTime.codegen.cs new file mode 100644 index 0000000000..2e09a42013 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_DesignTime.codegen.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable 1591 +namespace AspNetCore +{ + #line hidden + using TModel = global::System.Object; + 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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest__ViewImports_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +IHtmlHelper __typeHelper = default(IHtmlHelper); + } + ))(); + ((System.Action)(() => { +global::System.Object Helper = null; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public IHtmlHelper Helper { get; private set; } + [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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_DesignTime.ir.txt new file mode 100644 index 0000000000..d2def8694a --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_DesignTime.ir.txt @@ -0,0 +1,38 @@ +Document - + NamespaceDeclaration - - AspNetCore + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [12] ) - System + UsingDirective - (16:1,1 [32] ) - System.Collections.Generic + UsingDirective - (51:2,1 [17] ) - System.Linq + UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [30] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [40] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [43] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest__ViewImports_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (231:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (294:7,71 [4] ) - Html + DirectiveToken - (308:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (363:8,63 [4] ) - Json + DirectiveToken - (377:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (431:9,62 [9] ) - Component + DirectiveToken - (450:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (494:10,52 [3] ) - Url + DirectiveToken - (507:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (578:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (617:12,14 [96] ) - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (8:0,8 [19] _ViewImports.cshtml) - IHtmlHelper + DirectiveToken - (28:0,28 [6] _ViewImports.cshtml) - Helper + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_DesignTime.mappings.txt new file mode 100644 index 0000000000..287d4e0c05 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_DesignTime.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (8:0,8 [19] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports.cshtml) +|IHtmlHelper| +Generated Location: (679:18,0 [19] ) +|IHtmlHelper| + +Source Location: (28:0,28 [6] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports.cshtml) +|Helper| +Generated Location: (827:22,22 [6] ) +|Helper| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_Runtime.codegen.cs new file mode 100644 index 0000000000..2400a20b50 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_Runtime.codegen.cs @@ -0,0 +1,35 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "e57bbc3e746e8b13b4c33d8df0e022bd397d8caa" +// +#pragma warning disable 1591 +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; + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest__ViewImports_cshtml : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public IHtmlHelper Helper { get; private set; } + [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 Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_Runtime.ir.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_Runtime.ir.txt new file mode 100644 index 0000000000..3703d64a46 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports_Runtime.ir.txt @@ -0,0 +1,17 @@ +Document - + 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 + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest__ViewImports_cshtml - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTagHelperDescriptorFactoryTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTagHelperDescriptorFactoryTest.cs new file mode 100644 index 0000000000..d88f379542 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTagHelperDescriptorFactoryTest.cs @@ -0,0 +1,343 @@ +// 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.Collections.Generic; +using System.Reflection; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class ViewComponentTagHelperDescriptorFactoryTest + { + private static readonly Assembly _assembly = typeof(ViewComponentTagHelperDescriptorFactoryTest).GetTypeInfo().Assembly; + + [Fact] + public void CreateDescriptor_UnderstandsStringParameters() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(StringParameterViewComponent).FullName); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var expectedDescriptor = TagHelperDescriptorBuilder.Create( + ViewComponentTagHelperConventions.Kind, + "__Generated__StringParameterViewComponentTagHelper", + typeof(StringParameterViewComponent).GetTypeInfo().Assembly.GetName().Name) + .TypeName("__Generated__StringParameterViewComponentTagHelper") + .DisplayName("StringParameterViewComponentTagHelper") + .TagMatchingRuleDescriptor(rule => + rule + .RequireTagName("vc:string-parameter") + .RequireAttributeDescriptor(attribute => attribute.Name("foo")) + .RequireAttributeDescriptor(attribute => attribute.Name("bar"))) + .BoundAttributeDescriptor(attribute => + attribute + .Name("foo") + .PropertyName("foo") + .TypeName(typeof(string).FullName) + .DisplayName("string StringParameterViewComponentTagHelper.foo")) + .BoundAttributeDescriptor(attribute => + attribute + .Name("bar") + .PropertyName("bar") + .TypeName(typeof(string).FullName) + .DisplayName("string StringParameterViewComponentTagHelper.bar")) + .AddMetadata(ViewComponentTagHelperMetadata.Name, "StringParameter") + .Build(); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + Assert.Equal(expectedDescriptor, descriptor, TagHelperDescriptorComparer.CaseSensitive); + } + + [Fact] + public void CreateDescriptor_UnderstandsVariousParameterTypes() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(VariousParameterViewComponent).FullName); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var expectedDescriptor = TagHelperDescriptorBuilder.Create( + ViewComponentTagHelperConventions.Kind, + "__Generated__VariousParameterViewComponentTagHelper", + typeof(VariousParameterViewComponent).GetTypeInfo().Assembly.GetName().Name) + .TypeName("__Generated__VariousParameterViewComponentTagHelper") + .DisplayName("VariousParameterViewComponentTagHelper") + .TagMatchingRuleDescriptor(rule => + rule + .RequireTagName("vc:various-parameter") + .RequireAttributeDescriptor(attribute => attribute.Name("test-enum")) + .RequireAttributeDescriptor(attribute => attribute.Name("test-string")) + .RequireAttributeDescriptor(attribute => attribute.Name("baz"))) + .BoundAttributeDescriptor(attribute => + attribute + .Name("test-enum") + .PropertyName("testEnum") + .TypeName(typeof(VariousParameterViewComponent).FullName + "." + nameof(VariousParameterViewComponent.TestEnum)) + .AsEnum() + .DisplayName(typeof(VariousParameterViewComponent).FullName + "." + nameof(VariousParameterViewComponent.TestEnum) + " VariousParameterViewComponentTagHelper.testEnum")) + .BoundAttributeDescriptor(attribute => + attribute + .Name("test-string") + .PropertyName("testString") + .TypeName(typeof(string).FullName) + .DisplayName("string VariousParameterViewComponentTagHelper.testString")) + .BoundAttributeDescriptor(attribute => + attribute + .Name("baz") + .PropertyName("baz") + .TypeName(typeof(int).FullName) + .DisplayName("int VariousParameterViewComponentTagHelper.baz")) + .AddMetadata(ViewComponentTagHelperMetadata.Name, "VariousParameter") + .Build(); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + Assert.Equal(expectedDescriptor, descriptor, TagHelperDescriptorComparer.CaseSensitive); + } + + [Fact] + public void CreateDescriptor_UnderstandsGenericParameters() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(GenericParameterViewComponent).FullName); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var expectedDescriptor = TagHelperDescriptorBuilder.Create( + ViewComponentTagHelperConventions.Kind, + "__Generated__GenericParameterViewComponentTagHelper", + typeof(GenericParameterViewComponent).GetTypeInfo().Assembly.GetName().Name) + .TypeName("__Generated__GenericParameterViewComponentTagHelper") + .DisplayName("GenericParameterViewComponentTagHelper") + .TagMatchingRuleDescriptor(rule => + rule + .RequireTagName("vc:generic-parameter") + .RequireAttributeDescriptor(attribute => attribute.Name("foo"))) + .BoundAttributeDescriptor(attribute => + attribute + .Name("foo") + .PropertyName("Foo") + .TypeName("System.Collections.Generic.List") + .DisplayName("System.Collections.Generic.List GenericParameterViewComponentTagHelper.Foo")) + .BoundAttributeDescriptor(attribute => + attribute + .Name("bar") + .PropertyName("Bar") + .TypeName("System.Collections.Generic.Dictionary") + .AsDictionaryAttribute("bar-", typeof(int).FullName) + .DisplayName("System.Collections.Generic.Dictionary GenericParameterViewComponentTagHelper.Bar")) + .AddMetadata(ViewComponentTagHelperMetadata.Name, "GenericParameter") + .Build(); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + Assert.Equal(expectedDescriptor, descriptor, TagHelperDescriptorComparer.CaseSensitive); + } + + [Fact] + public void CreateDescriptor_AddsDiagnostic_ForViewComponentWithNoInvokeMethod() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(ViewComponentWithoutInvokeMethod).FullName); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + var diagnostic = Assert.Single(descriptor.GetAllDiagnostics()); + Assert.Equal(RazorExtensionsDiagnosticFactory.ViewComponent_CannotFindMethod.Id, diagnostic.Id); + } + + [Fact] + public void CreateDescriptor_ForViewComponentWithInvokeAsync_UnderstandsGenericTask() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithGenericTask).FullName); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + Assert.Empty(descriptor.GetAllDiagnostics()); + } + + [Fact] + public void CreateDescriptor_ForViewComponentWithInvokeAsync_UnderstandsNonGenericTask() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithNonGenericTask).FullName); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + Assert.Empty(descriptor.GetAllDiagnostics()); + } + + [Fact] + public void CreateDescriptor_ForViewComponentWithInvokeAsync_DoesNotUnderstandVoid() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithString).FullName); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + var diagnostic = Assert.Single(descriptor.GetAllDiagnostics()); + Assert.Equal(RazorExtensionsDiagnosticFactory.ViewComponent_AsyncMethod_ShouldReturnTask.Id, diagnostic.Id); + } + + [Fact] + public void CreateDescriptor_ForViewComponentWithInvokeAsync_DoesNotUnderstandString() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithString).FullName); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + var diagnostic = Assert.Single(descriptor.GetAllDiagnostics()); + Assert.Equal(RazorExtensionsDiagnosticFactory.ViewComponent_AsyncMethod_ShouldReturnTask.Id, diagnostic.Id); + } + + [Fact] + public void CreateDescriptor_ForViewComponentWithInvoke_DoesNotUnderstandVoid() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncViewComponentWithVoid).FullName); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + var diagnostic = Assert.Single(descriptor.GetAllDiagnostics()); + Assert.Equal(RazorExtensionsDiagnosticFactory.ViewComponent_SyncMethod_ShouldReturnValue.Id, diagnostic.Id); + } + + [Fact] + public void CreateDescriptor_ForViewComponentWithInvoke_DoesNotUnderstandNonGenericTask() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncViewComponentWithNonGenericTask).FullName); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + var diagnostic = Assert.Single(descriptor.GetAllDiagnostics()); + Assert.Equal(RazorExtensionsDiagnosticFactory.ViewComponent_SyncMethod_CannotReturnTask.Id, diagnostic.Id); + } + + [Fact] + public void CreateDescriptor_ForViewComponentWithInvoke_DoesNotUnderstandGenericTask() + { + // Arrange + var testCompilation = TestCompilation.Create(_assembly); + var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation); + + var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncViewComponentWithGenericTask).FullName); + + // Act + var descriptor = factory.CreateDescriptor(viewComponent); + + // Assert + var diagnostic = Assert.Single(descriptor.GetAllDiagnostics()); + Assert.Equal(RazorExtensionsDiagnosticFactory.ViewComponent_SyncMethod_CannotReturnTask.Id, diagnostic.Id); + } + } + + public class StringParameterViewComponent + { + public string Invoke(string foo, string bar) => null; + } + + public class VariousParameterViewComponent + { + public string Invoke(TestEnum testEnum, string testString, int baz = 5) => null; + + public enum TestEnum + { + A = 1, + B = 2, + C = 3 + } + } + + public class GenericParameterViewComponent + { + public string Invoke(List Foo, Dictionary Bar) => null; + } + + public class ViewComponentWithoutInvokeMethod + { + } + + public class AsyncViewComponentWithGenericTask + { + public Task InvokeAsync() => null; + } + + public class AsyncViewComponentWithNonGenericTask + { + public Task InvokeAsync() => null; + } + + public class AsyncViewComponentWithVoid + { + public void InvokeAsync() { } + } + + public class AsyncViewComponentWithString + { + public string InvokeAsync() => null; + } + + public class SyncViewComponentWithVoid + { + public void Invoke() { } + } + + public class SyncViewComponentWithNonGenericTask + { + public Task Invoke() => null; + } + + public class SyncViewComponentWithGenericTask + { + public Task Invoke() => null; + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTagHelperDescriptorProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTagHelperDescriptorProviderTest.cs new file mode 100644 index 0000000000..4689e7c3c5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTagHelperDescriptorProviderTest.cs @@ -0,0 +1,75 @@ +// 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; +using System.Reflection; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Razor; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + // This is just a basic integration test. There are detailed tests for the VCTH visitor and descriptor factory. + public class ViewComponentTagHelperDescriptorProviderTest + { + private static readonly Assembly _assembly = typeof(ViewComponentTagHelperDescriptorProviderTest).GetTypeInfo().Assembly; + + [Fact] + public void DescriptorProvider_FindsVCTH() + { + // Arrange + var code = @" + public class StringParameterViewComponent + { + public string Invoke(string foo, string bar) => null; + } +"; + + var testCompilation = TestCompilation.Create(_assembly, CSharpSyntaxTree.ParseText(code)); + + var context = TagHelperDescriptorProviderContext.Create(); + context.SetCompilation(testCompilation); + + var provider = new ViewComponentTagHelperDescriptorProvider() + { + Engine = RazorEngine.CreateEmpty(b => { }), + ForceEnabled = true, + }; + + var expectedDescriptor = TagHelperDescriptorBuilder.Create( + ViewComponentTagHelperConventions.Kind, + "__Generated__StringParameterViewComponentTagHelper", + TestCompilation.AssemblyName) + .TypeName("__Generated__StringParameterViewComponentTagHelper") + .DisplayName("StringParameterViewComponentTagHelper") + .TagMatchingRuleDescriptor(rule => + rule + .RequireTagName("vc:string-parameter") + .RequireAttributeDescriptor(attribute => attribute.Name("foo")) + .RequireAttributeDescriptor(attribute => attribute.Name("bar"))) + .BoundAttributeDescriptor(attribute => + attribute + .Name("foo") + .PropertyName("foo") + .TypeName(typeof(string).FullName) + .DisplayName("string StringParameterViewComponentTagHelper.foo")) + .BoundAttributeDescriptor(attribute => + attribute + .Name("bar") + .PropertyName("bar") + .TypeName(typeof(string).FullName) + .DisplayName("string StringParameterViewComponentTagHelper.bar")) + .AddMetadata(ViewComponentTagHelperMetadata.Name, "StringParameter") + .Build(); + + // Act + provider.Execute(context); + + // Assert + var descriptor = context.Results.FirstOrDefault(d => TagHelperDescriptorComparer.CaseSensitive.Equals(d, expectedDescriptor)); + Assert.NotNull(descriptor); + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTagHelperPassTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTagHelperPassTest.cs new file mode 100644 index 0000000000..a8c4e730f0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTagHelperPassTest.cs @@ -0,0 +1,367 @@ +// 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; +using System.Text; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class ViewComponentTagHelperPassTest + { + [Fact] + public void ViewComponentTagHelperPass_Execute_IgnoresRegularTagHelper() + { + // Arrange + var codeDocument = CreateDocument(@" +@addTagHelper TestTagHelper, TestAssembly +

"); + + var tagHelpers = new[] + { + TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly") + .TypeName("TestTagHelper") + .BoundAttributeDescriptor(attribute => attribute + .Name("Foo") + .TypeName("System.Int32")) + .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p")) + .Build() + }; + + var engine = CreateEngine(tagHelpers); + var pass = new ViewComponentTagHelperPass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var @class = FindClassNode(irDocument); + Assert.Equal(3, @class.Children.Count); // No class node created for a VCTH + for (var i = 0; i < @class.Children.Count; i++) + { + Assert.IsNotType(@class.Children[i]); + } + } + + [Fact] + public void ViewComponentTagHelperPass_Execute_CreatesViewComponentTagHelper() + { + // Arrange + var codeDocument = CreateDocument(@" +@addTagHelper TestTagHelper, TestAssembly +"); + + var tagHelpers = new[] + { + TagHelperDescriptorBuilder.Create(ViewComponentTagHelperConventions.Kind, "TestTagHelper", "TestAssembly") + .TypeName("__Generated__TagCloudViewComponentTagHelper") + .BoundAttributeDescriptor(attribute => attribute + .Name("Foo") + .TypeName("System.Int32") + .PropertyName("Foo")) + .TagMatchingRuleDescriptor(rule => rule.RequireTagName("tagcloud")) + .AddMetadata(ViewComponentTagHelperMetadata.Name, "TagCloud") + .Build() + }; + + var engine = CreateEngine(tagHelpers); + var pass = new ViewComponentTagHelperPass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + var vcthFullName = "AspNetCore.test_cshtml.__Generated__TagCloudViewComponentTagHelper"; + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var tagHelper = FindTagHelperNode(irDocument); + Assert.Equal(vcthFullName, Assert.IsType(tagHelper.Children[1]).TypeName); + Assert.Equal("Foo", Assert.IsType(tagHelper.Children[2]).PropertyName); + + + var @class = FindClassNode(irDocument); + Assert.Equal(4, @class.Children.Count); + + var vcthClass = Assert.IsType(@class.Children.Last()); + var tokenNode = vcthClass.Children[0] as IntermediateToken; + Assert.Equal( + @"[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute(""tagcloud"")] +public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper +{ + private readonly global::Microsoft.AspNetCore.Mvc.IViewComponentHelper _helper = null; + public __Generated__TagCloudViewComponentTagHelper(global::Microsoft.AspNetCore.Mvc.IViewComponentHelper helper) + { + _helper = helper; + } + [Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNotBoundAttribute, global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewContextAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.ViewContext ViewContext { get; set; } + public System.Int32 Foo { get; set; } + public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) + { + (_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext); + var content = await _helper.InvokeAsync(""TagCloud"", new { Foo }); + output.TagName = null; + output.Content.SetHtmlContent(content); + } +} +", + tokenNode.Content, + ignoreLineEndingDifferences: true); + Assert.Equal(TokenKind.CSharp, tokenNode.Kind); + } + + [Fact] + public void ViewComponentTagHelperPass_Execute_CreatesViewComponentTagHelper_WithIndexer() + { + // Arrange + var codeDocument = CreateDocument(@" +@addTagHelper TestTagHelper, TestAssembly +"); + + var tagHelpers = new[] + { + TagHelperDescriptorBuilder.Create(ViewComponentTagHelperConventions.Kind, "TestTagHelper", "TestAssembly") + .TypeName("__Generated__TagCloudViewComponentTagHelper") + .BoundAttributeDescriptor(attribute => attribute + .Name("Foo") + .TypeName("System.Collections.Generic.Dictionary") + .PropertyName("Tags") + .AsDictionaryAttribute("foo-", "System.Int32")) + .TagMatchingRuleDescriptor(rule => rule.RequireTagName("tagcloud")) + .AddMetadata(ViewComponentTagHelperMetadata.Name, "TagCloud") + .Build() + }; + + var engine = CreateEngine(tagHelpers); + var pass = new ViewComponentTagHelperPass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + var vcthFullName = "AspNetCore.test_cshtml.__Generated__TagCloudViewComponentTagHelper"; + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var tagHelper = FindTagHelperNode(irDocument); + Assert.Equal(vcthFullName, Assert.IsType(tagHelper.Children[1]).TypeName); + Assert.IsType(tagHelper.Children[2]); + + var @class = FindClassNode(irDocument); + Assert.Equal(4, @class.Children.Count); + + var vcthClass = Assert.IsType(@class.Children[3]); + var tokenNode = vcthClass.Children[0] as IntermediateToken; + Assert.Equal( + @"[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute(""tagcloud"")] +public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper +{ + private readonly global::Microsoft.AspNetCore.Mvc.IViewComponentHelper _helper = null; + public __Generated__TagCloudViewComponentTagHelper(global::Microsoft.AspNetCore.Mvc.IViewComponentHelper helper) + { + _helper = helper; + } + [Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNotBoundAttribute, global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewContextAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.ViewContext ViewContext { get; set; } + public System.Collections.Generic.Dictionary Tags { get; set; } + = new System.Collections.Generic.Dictionary(); + public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) + { + (_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext); + var content = await _helper.InvokeAsync(""TagCloud"", new { Tags }); + output.TagName = null; + output.Content.SetHtmlContent(content); + } +} +", + tokenNode.Content, + ignoreLineEndingDifferences: true); + Assert.Equal(TokenKind.CSharp, tokenNode.Kind); + } + + [Fact] + public void ViewComponentTagHelperPass_Execute_CreatesViewComponentTagHelper_Nested() + { + // Arrange + var codeDocument = CreateDocument(@" +@addTagHelper *, TestAssembly +

"); + + var tagHelpers = new[] + { + TagHelperDescriptorBuilder.Create("PTestTagHelper", "TestAssembly") + .TypeName("PTestTagHelper") + .BoundAttributeDescriptor(attribute => attribute + .PropertyName("Foo") + .Name("Foo") + .TypeName("System.Int32")) + .TagMatchingRuleDescriptor(rule => rule.RequireTagName("p")) + .Build(), + TagHelperDescriptorBuilder.Create(ViewComponentTagHelperConventions.Kind, "TestTagHelper", "TestAssembly") + .TypeName("__Generated__TagCloudViewComponentTagHelper") + .BoundAttributeDescriptor(attribute => attribute + .PropertyName("Foo") + .Name("Foo") + .TypeName("System.Int32")) + .TagMatchingRuleDescriptor(rule => rule.RequireTagName("tagcloud")) + .AddMetadata(ViewComponentTagHelperMetadata.Name, "TagCloud") + .Build() + }; + + var engine = CreateEngine(tagHelpers); + var pass = new ViewComponentTagHelperPass() + { + Engine = engine, + }; + + var irDocument = CreateIRDocument(engine, codeDocument); + + var vcthFullName = "AspNetCore.test_cshtml.__Generated__TagCloudViewComponentTagHelper"; + + // Act + pass.Execute(codeDocument, irDocument); + + // Assert + var outerTagHelper = FindTagHelperNode(irDocument); + Assert.Equal("PTestTagHelper", Assert.IsType(outerTagHelper.Children[1]).TypeName); + Assert.Equal("Foo", Assert.IsType(outerTagHelper.Children[2]).PropertyName); + + var vcth = FindTagHelperNode(outerTagHelper.Children[0]); + Assert.Equal(vcthFullName, Assert.IsType(vcth.Children[1]).TypeName); + Assert.Equal("Foo", Assert.IsType(vcth.Children[2]).PropertyName); + + + var @class = FindClassNode(irDocument); + Assert.Equal(5, @class.Children.Count); + + var vcthClass = Assert.IsType(@class.Children.Last()); + var tokenNode = vcthClass.Children[0] as IntermediateToken; + Assert.Equal( + @"[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute(""tagcloud"")] +public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper +{ + private readonly global::Microsoft.AspNetCore.Mvc.IViewComponentHelper _helper = null; + public __Generated__TagCloudViewComponentTagHelper(global::Microsoft.AspNetCore.Mvc.IViewComponentHelper helper) + { + _helper = helper; + } + [Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNotBoundAttribute, global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewContextAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.ViewContext ViewContext { get; set; } + public System.Int32 Foo { get; set; } + public override async global::System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) + { + (_helper as global::Microsoft.AspNetCore.Mvc.ViewFeatures.IViewContextAware)?.Contextualize(ViewContext); + var content = await _helper.InvokeAsync(""TagCloud"", new { Foo }); + output.TagName = null; + output.Content.SetHtmlContent(content); + } +} +", + tokenNode.Content, + ignoreLineEndingDifferences: true); + Assert.Equal(TokenKind.CSharp, tokenNode.Kind); + } + + private RazorCodeDocument CreateDocument(string content) + { + var source = RazorSourceDocument.Create(content, "test.cshtml"); + return RazorCodeDocument.Create(source); + } + + private RazorEngine CreateEngine(params TagHelperDescriptor[] tagHelpers) + { + return RazorEngine.Create(b => + { + b.Features.Add(new MvcViewDocumentClassifierPass()); + + b.Features.Add(new TestTagHelperFeature(tagHelpers)); + }); + } + + private DocumentIntermediateNode CreateIRDocument(RazorEngine engine, RazorCodeDocument codeDocument) + { + for (var i = 0; i < engine.Phases.Count; i++) + { + var phase = engine.Phases[i]; + phase.Execute(codeDocument); + + if (phase is IRazorDirectiveClassifierPhase) + { + break; + } + } + + // We also expect the default tag helper pass to run first. + var documentNode = codeDocument.GetDocumentIntermediateNode(); + + var defaultTagHelperPass = engine.Features.OfType().Single(); + defaultTagHelperPass.Execute(codeDocument, documentNode); + + return codeDocument.GetDocumentIntermediateNode(); + } + + private ClassDeclarationIntermediateNode FindClassNode(IntermediateNode node) + { + var visitor = new ClassDeclarationNodeVisitor(); + visitor.Visit(node); + return visitor.Node; + } + + private TagHelperIntermediateNode FindTagHelperNode(IntermediateNode node) + { + var visitor = new TagHelperNodeVisitor(); + visitor.Visit(node); + return visitor.Node; + } + + private string GetCSharpContent(IntermediateNode node) + { + var builder = new StringBuilder(); + for (var i = 0; i < node.Children.Count; i++) + { + var child = node.Children[i] as IntermediateToken; + if (child.Kind == TokenKind.CSharp) + { + builder.Append(child.Content); + } + } + + return builder.ToString(); + } + + private class ClassDeclarationNodeVisitor : IntermediateNodeWalker + { + public ClassDeclarationIntermediateNode Node { get; set; } + + public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node) + { + Node = node; + } + } + + private class TagHelperNodeVisitor : IntermediateNodeWalker + { + public TagHelperIntermediateNode Node { get; set; } + + public override void VisitTagHelper(TagHelperIntermediateNode node) + { + Node = node; + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTypeVisitorTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTypeVisitorTest.cs new file mode 100644 index 0000000000..96d879756c --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/ViewComponentTypeVisitorTest.cs @@ -0,0 +1,202 @@ +// 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.Reflection; +using Microsoft.CodeAnalysis; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X +{ + public class ViewComponentTypeVisitorTest + { + private static readonly Assembly _assembly = typeof(ViewComponentTypeVisitorTest).GetTypeInfo().Assembly; + + private static Compilation Compilation { get; } = TestCompilation.Create(_assembly); + + // In practice MVC will provide a marker attribute for ViewComponents. To prevent a circular reference between MVC and Razor + // we can use a test class as a marker. + private static INamedTypeSymbol TestViewComponentAttributeSymbol { get; } = Compilation.GetTypeByMetadataName(typeof(TestViewComponentAttribute).FullName); + private static INamedTypeSymbol TestNonViewComponentAttributeSymbol { get; } = Compilation.GetTypeByMetadataName(typeof(TestNonViewComponentAttribute).FullName); + + [Fact] + public void IsViewComponent_PlainViewComponent_ReturnsTrue() + { + // Arrange + var testVisitor = new ViewComponentTypeVisitor( + TestViewComponentAttributeSymbol, + TestNonViewComponentAttributeSymbol, + new List()); + var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Valid_PlainViewComponent).FullName); + + // Act + var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); + + // Assert + Assert.True(isViewComponent); + } + + [Fact] + public void IsViewComponent_DecoratedViewComponent_ReturnsTrue() + { + // Arrange + var testVisitor = new ViewComponentTypeVisitor( + TestViewComponentAttributeSymbol, + TestNonViewComponentAttributeSymbol, + new List()); + var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Valid_DecoratedVC).FullName); + + // Act + var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); + + // Assert + Assert.True(isViewComponent); + } + + [Fact] + public void IsViewComponent_InheritedViewComponent_ReturnsTrue() + { + // Arrange + var testVisitor = new ViewComponentTypeVisitor( + TestViewComponentAttributeSymbol, + TestNonViewComponentAttributeSymbol, + new List()); + var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Valid_InheritedVC).FullName); + + // Act + var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); + + // Assert + Assert.True(isViewComponent); + } + + [Fact] + public void IsViewComponent_AbstractViewComponent_ReturnsFalse() + { + // Arrange + var testVisitor = new ViewComponentTypeVisitor( + TestViewComponentAttributeSymbol, + TestNonViewComponentAttributeSymbol, + new List()); + var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Invalid_AbstractViewComponent).FullName); + + // Act + var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); + + // Assert + Assert.False(isViewComponent); + } + + [Fact] + public void IsViewComponent_GenericViewComponent_ReturnsFalse() + { + // Arrange + var testVisitor = new ViewComponentTypeVisitor( + TestViewComponentAttributeSymbol, + TestNonViewComponentAttributeSymbol, + new List()); + var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Invalid_GenericViewComponent<>).FullName); + + // Act + var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); + + // Assert + Assert.False(isViewComponent); + } + + [Fact] + public void IsViewComponent_InternalViewComponent_ReturnsFalse() + { + // Arrange + var testVisitor = new ViewComponentTypeVisitor( + TestViewComponentAttributeSymbol, + TestNonViewComponentAttributeSymbol, + new List()); + var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Invalid_InternalViewComponent).FullName); + + // Act + var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); + + // Assert + Assert.False(isViewComponent); + } + + [Fact] + public void IsViewComponent_DecoratedNonViewComponent_ReturnsFalse() + { + // Arrange + var testVisitor = new ViewComponentTypeVisitor( + TestViewComponentAttributeSymbol, + TestNonViewComponentAttributeSymbol, + new List()); + var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Invalid_DecoratedViewComponent).FullName); + + // Act + var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); + + // Assert + Assert.False(isViewComponent); + } + + [Fact] + public void IsViewComponent_InheritedNonViewComponent_ReturnsFalse() + { + // Arrange + var testVisitor = new ViewComponentTypeVisitor( + TestViewComponentAttributeSymbol, + TestNonViewComponentAttributeSymbol, + new List()); + var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Invalid_InheritedViewComponent).FullName); + + // Act + var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); + + // Assert + Assert.False(isViewComponent); + } + + public abstract class Invalid_AbstractViewComponent + { + } + + public class Invalid_GenericViewComponent + { + } + + internal class Invalid_InternalViewComponent + { + } + + public class Valid_PlainViewComponent + { + } + + [TestViewComponent] + public class Valid_DecoratedVC + { + } + + public class Valid_InheritedVC : Valid_DecoratedVC + { + } + + [TestNonViewComponent] + public class Invalid_DecoratedViewComponent + { + } + + [TestViewComponent] + public class Invalid_InheritedViewComponent : Invalid_DecoratedViewComponent + { + } + + public class TestViewComponentAttribute : Attribute + { + } + + public class TestNonViewComponentAttribute : Attribute + { + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/xunit.runner.json b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/xunit.runner.json new file mode 100644 index 0000000000..fcf172c8fc --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "methodDisplay": "method", + "shadowCopy": false +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Extensions/SectionTargetExtensionTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Extensions/SectionTargetExtensionTest.cs index 991fcce28e..c369432e3b 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Extensions/SectionTargetExtensionTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Extensions/SectionTargetExtensionTest.cs @@ -3,9 +3,7 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using Microsoft.AspNetCore.Razor.Language.Intermediate; -using Microsoft.AspNetCore.Razor.Language.Legacy; using Xunit; -using static Microsoft.AspNetCore.Razor.Language.Intermediate.IntermediateNodeAssert; namespace Microsoft.AspNetCore.Razor.Language.Extensions { @@ -69,7 +67,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions extension.WriteSection(context, node); // Assert - var expected = @"CreateSection(""MySection"", async(__razor_section_writer) => { + var expected = @"CreateSection(""MySection"", async() => { Render Children } ); diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs index d30aea4b02..0897ae157d 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs @@ -53,7 +53,7 @@ __o = Foo(item => new Template(async(__razor_template_writer) => { #line default #line hidden - DefineSection("Footer", async(__razor_section_writer) => { + DefineSection("Footer", async() => { #line 14 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime.cshtml" __o = bar; diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.mappings.txt index 87ab943dfc..a72db81cb6 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.mappings.txt +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.mappings.txt @@ -44,6 +44,6 @@ Generated Location: (1636:51,1 [1] ) Source Location: (204:13,5 [3] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime.cshtml) |bar| -Generated Location: (1836:57,6 [3] ) +Generated Location: (1814:57,6 [3] ) |bar| diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs index 556cf5e489..b610f02553 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs @@ -33,7 +33,7 @@ global::System.Object NestedDelegates = null; #line default #line hidden - DefineSection("Section2", async(__razor_section_writer) => { + DefineSection("Section2", async() => { #line 8 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" __o = thing; @@ -41,10 +41,10 @@ global::System.Object NestedDelegates = null; #line hidden } ); - DefineSection("Section1", async(__razor_section_writer) => { + DefineSection("Section1", async() => { } ); - DefineSection("NestedDelegates", async(__razor_section_writer) => { + DefineSection("NestedDelegates", async() => { #line 16 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" Func f = diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt index f6aedef836..ff1262a84a 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt @@ -24,21 +24,21 @@ Generated Location: (1024:30,2 [44] ) Source Location: (123:7,22 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) |thing| -Generated Location: (1279:37,22 [5] ) +Generated Location: (1257:37,22 [5] ) |thing| Source Location: (260:15,6 [27] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) | Func f = | -Generated Location: (1626:48,6 [27] ) +Generated Location: (1560:48,6 [27] ) | Func f = | Source Location: (295:15,41 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) |item| -Generated Location: (1886:54,41 [4] ) +Generated Location: (1820:54,41 [4] ) |item| Source Location: (306:15,52 [2] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) |; | -Generated Location: (2099:61,52 [2] ) +Generated Location: (2033:61,52 [2] ) |; | diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_DesignTime.codegen.cs index e1a96c0d30..49a1737a04 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_DesignTime.codegen.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_DesignTime.codegen.cs @@ -23,10 +23,10 @@ global::System.Object WriteLiteralsToInHereAlso = null; #pragma warning disable 1998 public async System.Threading.Tasks.Task ExecuteAsync() { - DefineSection("WriteLiteralsToInHere", async(__razor_section_writer) => { + DefineSection("WriteLiteralsToInHere", async() => { } ); - DefineSection("WriteLiteralsToInHereAlso", async(__razor_section_writer) => { + DefineSection("WriteLiteralsToInHereAlso", async() => { } ); } diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/HelperResult.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/HelperResult.cs new file mode 100644 index 0000000000..094a762152 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/HelperResult.cs @@ -0,0 +1,22 @@ +// 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.Text.Encodings.Web; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Html; + +namespace Microsoft.AspNetCore.Mvc.Razor +{ + public class HelperResult : IHtmlContent + { + public HelperResult(Func asyncAction) + { + } + + public void WriteTo(TextWriter writer, HtmlEncoder encoder) + { + } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/IRazorPage.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/IRazorPage.cs new file mode 100644 index 0000000000..34a1b208da --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/IRazorPage.cs @@ -0,0 +1,31 @@ +// 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.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Mvc.Rendering; + +namespace Microsoft.AspNetCore.Mvc.Razor +{ + public interface IRazorPage + { + ViewContext ViewContext { get; set; } + + IHtmlContent BodyContent { get; set; } + + bool IsLayoutBeingRendered { get; set; } + + string Path { get; set; } + + string Layout { get; set; } + + IDictionary PreviousSectionWriters { get; set; } + + IDictionary SectionWriters { get; } + + Task ExecuteAsync(); + + void EnsureRenderedBodyOrSections(); + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RazorInjectAttribute.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RazorInjectAttribute.cs new file mode 100644 index 0000000000..321129faea --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RazorInjectAttribute.cs @@ -0,0 +1,14 @@ +// 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; + +namespace Microsoft.AspNetCore.Mvc.Razor.Internal +{ + public class RazorInjectAttribute : Attribute + { + public RazorInjectAttribute () + { + } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RazorPage.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RazorPage.cs new file mode 100644 index 0000000000..b47d37d067 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RazorPage.cs @@ -0,0 +1,55 @@ +// 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.Threading.Tasks; +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.AspNetCore.Razor.TagHelpers; + +namespace Microsoft.AspNetCore.Mvc.Razor +{ + public abstract class RazorPage : IRazorPage + { + public ViewContext ViewContext { get; set; } + + public IHtmlContent BodyContent { get; set; } + + public bool IsLayoutBeingRendered { get; set; } + + public string Path { get; set; } + + public string Layout { get; set; } + + public IDictionary PreviousSectionWriters { get; set; } + + public IDictionary SectionWriters { get; } + + public ITempDataDictionary TempData { get; } + + public void EnsureRenderedBodyOrSections() + { + } + + public void DefineSection(string name, RenderAsyncDelegate section) + { + } + + public abstract Task ExecuteAsync(); + + public void BeginContext(int position, int length, bool isLiteral) + { + } + + public void EndContext() + { + } + + public TTagHelper CreateTagHelper() where TTagHelper : ITagHelper + { + throw new NotImplementedException(); + } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RazorPageOfT.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RazorPageOfT.cs new file mode 100644 index 0000000000..e1460a5f82 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RazorPageOfT.cs @@ -0,0 +1,14 @@ +// 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.Mvc.ViewFeatures; + +namespace Microsoft.AspNetCore.Mvc.Razor +{ + public abstract class RazorPage : RazorPage + { + public TModel Model { get; } + + public ViewDataDictionary ViewData { get; set; } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RenderAsyncDelegate.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RenderAsyncDelegate.cs new file mode 100644 index 0000000000..75f6fb3974 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Razor/RenderAsyncDelegate.cs @@ -0,0 +1,10 @@ +// 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.Threading.Tasks; + +namespace Microsoft.AspNetCore.Mvc.Razor +{ + public delegate Task RenderAsyncDelegate(TextWriter writer); +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Rendering/IHtmlHelperOfT.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Rendering/IHtmlHelperOfT.cs new file mode 100644 index 0000000000..32d8c06988 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Rendering/IHtmlHelperOfT.cs @@ -0,0 +1,9 @@ +// 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.Mvc.Rendering +{ + public interface IHtmlHelper + { + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Rendering/IJsonHelper.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Rendering/IJsonHelper.cs new file mode 100644 index 0000000000..acc44e7b61 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Rendering/IJsonHelper.cs @@ -0,0 +1,10 @@ +// 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.Mvc.Rendering +{ + public interface IJsonHelper + { + + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Rendering/ViewContext.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Rendering/ViewContext.cs new file mode 100644 index 0000000000..0f8a3b5bb6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.Rendering/ViewContext.cs @@ -0,0 +1,12 @@ +// 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.Mvc.ViewFeatures; + +namespace Microsoft.AspNetCore.Mvc.Rendering +{ + public class ViewContext + { + public ViewDataDictionary ViewData { get; set; } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/IModelExpressionProvider.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/IModelExpressionProvider.cs new file mode 100644 index 0000000000..508b0cbda7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/IModelExpressionProvider.cs @@ -0,0 +1,15 @@ +// 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.Expressions; + +namespace Microsoft.AspNetCore.Mvc.ViewFeatures +{ + public interface IModelExpressionProvider + { + ModelExpression CreateModelExpression( + ViewDataDictionary viewData, + Expression> expression); + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ITempDataDictionary.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ITempDataDictionary.cs new file mode 100644 index 0000000000..2cfa53744b --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ITempDataDictionary.cs @@ -0,0 +1,9 @@ +// 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.Mvc.ViewFeatures +{ + public interface ITempDataDictionary + { + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/IViewContextAware.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/IViewContextAware.cs new file mode 100644 index 0000000000..0090cf91b1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/IViewContextAware.cs @@ -0,0 +1,12 @@ +// 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.Mvc.Rendering; + +namespace Microsoft.AspNetCore.Mvc.ViewFeatures +{ + public interface IViewContextAware + { + void Contextualize(ViewContext viewContext); + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ModelExpression.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ModelExpression.cs new file mode 100644 index 0000000000..3ee8ddc801 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ModelExpression.cs @@ -0,0 +1,9 @@ +// 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.Mvc.ViewFeatures +{ + public sealed class ModelExpression + { + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewContextAttribute.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewContextAttribute.cs new file mode 100644 index 0000000000..8a97b136cf --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewContextAttribute.cs @@ -0,0 +1,11 @@ +// 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; + +namespace Microsoft.AspNetCore.Mvc.ViewFeatures +{ + public class ViewContextAttribute : Attribute + { + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewDataDictionary.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewDataDictionary.cs new file mode 100644 index 0000000000..fa4a7d7c60 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewDataDictionary.cs @@ -0,0 +1,92 @@ +// 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; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Mvc.ViewFeatures +{ + public class ViewDataDictionary : IDictionary + { + #region IDictionary properties + public object this[string index] + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public int Count { get; } + + public bool IsReadOnly { get; } + + public ICollection Keys { get; } + + public ICollection Values { get; } + #endregion + + #region IDictionary methods + public void Add(string key, object value) + { + } + + public bool ContainsKey(string key) + { + throw new NotImplementedException(); + } + + public bool Remove(string key) + { + throw new NotImplementedException(); + } + + public bool TryGetValue(string key, out object value) + { + throw new NotImplementedException(); + } + + public void Add(KeyValuePair item) + { + } + + public void Clear() + { + } + + public bool Contains(KeyValuePair item) + { + throw new NotImplementedException(); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + } + + public bool Remove(KeyValuePair item) + { + throw new NotImplementedException(); + } + + IEnumerator> IEnumerable>.GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + #endregion + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewDataDictionaryOfT.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewDataDictionaryOfT.cs new file mode 100644 index 0000000000..f96eb55805 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewDataDictionaryOfT.cs @@ -0,0 +1,7 @@ +namespace Microsoft.AspNetCore.Mvc.ViewFeatures +{ + public class ViewDataDictionary : ViewDataDictionary + { + public TModel Model { get; set; } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc/IUrlHelper.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc/IUrlHelper.cs new file mode 100644 index 0000000000..049f20183c --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc/IUrlHelper.cs @@ -0,0 +1,10 @@ +// 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.Mvc +{ + public interface IUrlHelper + { + + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc/IViewComponentHelper.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc/IViewComponentHelper.cs new file mode 100644 index 0000000000..75f23a78aa --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Mvc/IViewComponentHelper.cs @@ -0,0 +1,16 @@ +// 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.Threading.Tasks; +using Microsoft.AspNetCore.Html; + +namespace Microsoft.AspNetCore.Mvc +{ + public interface IViewComponentHelper + { + Task InvokeAsync(string name, object arguments); + + Task InvokeAsync(Type componentType, object arguments); + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.csproj b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.csproj new file mode 100644 index 0000000000..8cbd6c7501 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.csproj @@ -0,0 +1,18 @@ + + + + + + net461;netcoreapp2.0 + true + + + + + + + + + + + diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/xunit.runner.json b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/xunit.runner.json new file mode 100644 index 0000000000..1c72a421ad --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X/xunit.runner.json @@ -0,0 +1,3 @@ +{ + "shadowCopy": false +}