Use Basic.Reference.Assemblies in Mvc Extension tests (#10888)

* Use Basic.Reference.Assemblies in Mvc Extension tests

* Remove unused shim projects
This commit is contained in:
Jan Jones 2024-09-17 09:52:55 +02:00 коммит произвёл GitHub
Родитель c38fc3b9d2
Коммит 4467256ff7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
13 изменённых файлов: 256 добавлений и 310 удалений

Просмотреть файл

@ -15,7 +15,6 @@
"src\\Compiler\\Microsoft.Net.Compilers.Razor.Toolset\\Microsoft.Net.Compilers.Razor.Toolset.csproj",
"src\\Compiler\\test\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.Compiler.csproj",
"src\\Compiler\\test\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X.Compiler.csproj",
"src\\Compiler\\test\\Microsoft.AspNetCore.Razor.Test.MvcShim\\Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler.csproj",
"src\\Compiler\\test\\Microsoft.NET.Sdk.Razor.SourceGenerators.Tests\\Microsoft.NET.Sdk.Razor.SourceGenerators.Test.csproj",
"src\\Compiler\\tools\\Microsoft.AspNetCore.Mvc.Razor.Extensions.Tooling.Internal\\Microsoft.AspNetCore.Mvc.Razor.Extensions.Tooling.Internal.csproj",
"src\\Compiler\\tools\\Microsoft.CodeAnalysis.Razor.Tooling.Internal\\Microsoft.CodeAnalysis.Razor.Tooling.Internal.csproj",

Просмотреть файл

@ -100,10 +100,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.Razor.Sou
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.Razor.SourceGenerators.Test", "src\Compiler\test\Microsoft.NET.Sdk.Razor.SourceGenerators.Tests\Microsoft.NET.Sdk.Razor.SourceGenerators.Test.csproj", "{BD96BB0F-84DE-4A5F-8832-C8EADA36F43A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler", "src\Compiler\test\Microsoft.AspNetCore.Razor.Test.MvcShim\Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler.csproj", "{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.Compiler", "src\Compiler\test\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.Compiler.csproj", "{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.Compiler", "src\Compiler\test\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.Compiler.csproj", "{A0867F6B-3DBB-4743-B241-F59878BFA15D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X.Compiler", "src\Compiler\test\Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X\Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X.Compiler.csproj", "{B040B919-D8E3-4656-BD85-88A541AA893D}"
@ -410,22 +406,6 @@ Global
{BD96BB0F-84DE-4A5F-8832-C8EADA36F43A}.Release|Any CPU.Build.0 = Release|Any CPU
{BD96BB0F-84DE-4A5F-8832-C8EADA36F43A}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{BD96BB0F-84DE-4A5F-8832-C8EADA36F43A}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7}.Release|Any CPU.Build.0 = Release|Any CPU
{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A}.Release|Any CPU.Build.0 = Release|Any CPU
{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{A0867F6B-3DBB-4743-B241-F59878BFA15D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0867F6B-3DBB-4743-B241-F59878BFA15D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0867F6B-3DBB-4743-B241-F59878BFA15D}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
@ -660,8 +640,6 @@ Global
{FB7C870E-A173-4F75-BE63-4EF39C79A759} = {5B60F564-4AD7-4B70-A887-7D91496799A2}
{F5017FD5-EA78-4CD2-A1B6-F534910683F8} = {AA4EE974-E765-4B97-AF35-F734BF9830F6}
{BD96BB0F-84DE-4A5F-8832-C8EADA36F43A} = {AA4EE974-E765-4B97-AF35-F734BF9830F6}
{2CB7D554-49CE-45AC-97DF-7F8C597BDFA7} = {A5E2E4FA-6087-4C16-BB7A-89E23AA0F4E3}
{9FE4A38F-F0E7-45BD-94C1-1DC6FA55BB4A} = {A5E2E4FA-6087-4C16-BB7A-89E23AA0F4E3}
{A0867F6B-3DBB-4743-B241-F59878BFA15D} = {A5E2E4FA-6087-4C16-BB7A-89E23AA0F4E3}
{B040B919-D8E3-4656-BD85-88A541AA893D} = {A5E2E4FA-6087-4C16-BB7A-89E23AA0F4E3}
{907EDA43-B4D9-40DA-BA07-8E00DD89FA33} = {FB7C870E-A173-4F75-BE63-4EF39C79A759}

Просмотреть файл

@ -119,7 +119,7 @@ target the broadest set of frameworks.
- Microsoft.AspNetCore.Razor.Test.MvcShim (`net8.0`;`net472`)
- Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib (`netstandard2.0`)
- Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X (`net8.0`;`net472`)
- Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X (`net8.0`;`net4720`)
- Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X (`net8.0`;`net472`)
### Tooling Core Tests

Просмотреть файл

@ -6,7 +6,6 @@
using System.Linq;
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.Test.Utilities;
@ -17,7 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.IntegrationTests;
public class CodeGenerationIntegrationTest : IntegrationTestBase
{
private static readonly CSharpCompilation DefaultBaseCompilation = MvcShim.BaseCompilation.WithAssemblyName("AppCode");
private static readonly CSharpCompilation DefaultBaseCompilation = TestCompilation.Create().WithAssemblyName("AppCode");
private RazorConfiguration _configuration;
@ -239,11 +238,11 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void Sections_Runtime()
{
// Arrange
AddCSharpSyntaxTree($$"""
AddCSharpSyntaxTree("""
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class InputTestTagHelper : {{typeof(TagHelper).FullName}}
public class InputTestTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
public ModelExpression For { get; set; }
}
@ -389,10 +388,10 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void ModelExpressionTagHelper_Runtime()
{
// Arrange
AddCSharpSyntaxTree($$"""
AddCSharpSyntaxTree("""
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class InputTestTagHelper : {{typeof(TagHelper).FullName}}
public class InputTestTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
public ModelExpression For { get; set; }
}
@ -413,8 +412,8 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void RazorPages_Runtime()
{
// Arrange
AddCSharpSyntaxTree($$"""
public class DivTagHelper : {{typeof(TagHelper).FullName}}
AddCSharpSyntaxTree("""
public class DivTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
}
@ -450,8 +449,8 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void RazorPagesWithoutModel_Runtime()
{
// Arrange
AddCSharpSyntaxTree($$"""
public class DivTagHelper : {{typeof(TagHelper).FullName}}
AddCSharpSyntaxTree("""
public class DivTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
}
@ -502,7 +501,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void ViewComponentTagHelper_Runtime()
{
// Arrange
AddCSharpSyntaxTree($$"""
AddCSharpSyntaxTree("""
public class TestViewComponent
{
public string Invoke(string firstName)
@ -511,8 +510,8 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
}
}
[{{typeof(HtmlTargetElementAttribute).FullName}}]
public class AllTagHelper : {{typeof(TagHelper).FullName}}
[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute]
public class AllTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
public string Bar { get; set; }
}
@ -599,15 +598,15 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void RazorPage_WithCssScope()
{
// Arrange
AddCSharpSyntaxTree($$"""
[{{typeof(HtmlTargetElementAttribute).FullName}}("all")]
public class AllTagHelper : {{typeof(TagHelper).FullName}}
AddCSharpSyntaxTree("""
[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("all")]
public class AllTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
public string Bar { get; set; }
}
[{{typeof(HtmlTargetElementAttribute).FullName}}("form")]
public class FormTagHelper : {{typeof(TagHelper).FullName}}
[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("form")]
public class FormTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
}
""");
@ -643,15 +642,15 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void RazorView_WithCssScope()
{
// Arrange
AddCSharpSyntaxTree($$"""
[{{typeof(HtmlTargetElementAttribute).FullName}}("all")]
public class AllTagHelper : {{typeof(TagHelper).FullName}}
AddCSharpSyntaxTree("""
[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("all")]
public class AllTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
public string Bar { get; set; }
}
[{{typeof(HtmlTargetElementAttribute).FullName}}("form")]
public class FormTagHelper : {{typeof(TagHelper).FullName}}
[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("form")]
public class FormTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
}
""");
@ -686,14 +685,14 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void RazorView_Layout_WithCssScope()
{
// Arrange
AddCSharpSyntaxTree($$"""
[{{typeof(HtmlTargetElementAttribute).FullName}}("all")]
public class AllTagHelper : {{typeof(TagHelper).FullName}}
AddCSharpSyntaxTree("""
[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("all")]
public class AllTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
public string Bar { get; set; }
}
[{{typeof(HtmlTargetElementAttribute).FullName}}("form")]
public class FormTagHelper : {{typeof(TagHelper).FullName}}
[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute("form")]
public class FormTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
}
""");
@ -1109,10 +1108,10 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void Sections_DesignTime()
{
// Arrange
AddCSharpSyntaxTree($$"""
AddCSharpSyntaxTree("""
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class InputTestTagHelper : {{typeof(TagHelper).FullName}}
public class InputTestTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
public ModelExpression For { get; set; }
}
@ -1294,10 +1293,10 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void ModelExpressionTagHelper_DesignTime()
{
// Arrange
AddCSharpSyntaxTree($$"""
AddCSharpSyntaxTree("""
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class InputTestTagHelper : {{typeof(TagHelper).FullName}}
public class InputTestTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
public ModelExpression For { get; set; }
}
@ -1320,8 +1319,8 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void RazorPages_DesignTime()
{
// Arrange
AddCSharpSyntaxTree($$"""
public class DivTagHelper : {{typeof(TagHelper).FullName}}
AddCSharpSyntaxTree("""
public class DivTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
}
@ -1361,8 +1360,8 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void RazorPagesWithoutModel_DesignTime()
{
// Arrange
AddCSharpSyntaxTree($$"""
public class DivTagHelper : {{typeof(TagHelper).FullName}}
AddCSharpSyntaxTree("""
public class DivTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
}
@ -1419,7 +1418,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
public void ViewComponentTagHelper_DesignTime()
{
// Arrange
AddCSharpSyntaxTree($$"""
AddCSharpSyntaxTree("""
public class TestViewComponent
{
public string Invoke(string firstName)
@ -1428,8 +1427,8 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase
}
}
[{{typeof(HtmlTargetElementAttribute).FullName}}]
public class AllTagHelper : {{typeof(TagHelper).FullName}}
[Microsoft.AspNetCore.Razor.TagHelpers.HtmlTargetElementAttribute]
public class AllTagHelper : Microsoft.AspNetCore.Razor.TagHelpers.TagHelper
{
public string Bar { get; set; }
}

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(DefaultNetCoreTargetFrameworks)</TargetFrameworks>
@ -18,7 +18,6 @@
<ItemGroup>
<ProjectReference Include="..\..\Microsoft.CodeAnalysis.Razor.Compiler\src\Microsoft.CodeAnalysis.Razor.Compiler.csproj" />
<ProjectReference Include="..\..\..\Shared\Microsoft.AspNetCore.Razor.Test.Common\Microsoft.AspNetCore.Razor.Test.Common.csproj" />
<ProjectReference Include="..\..\test\Microsoft.AspNetCore.Razor.Test.MvcShim\Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler.csproj" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisCommonPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(MicrosoftCodeAnalysisCSharpPackageVersion)" />
@ -30,20 +29,4 @@
<ItemGroup>
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" Key="$(MoqPublicKey)" />
</ItemGroup>
<Target Name="CopyDepsFromShims_Build" AfterTargets="Build">
<ItemGroup>
<MvcShim Condition="$(TargetFramework) != ''" Include="$(ArtifactsBinDir)\Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler\$(Configuration)\$(TargetFramework)\Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler.deps.json" />
</ItemGroup>
<Copy SourceFiles="@(MvcShim)" DestinationFolder="$(OutputPath)" />
</Target>
<Target Name="CopyDepsFromShims_Publish" AfterTargets="Publish">
<ItemGroup>
<MvcShim Condition="$(TargetFramework) != ''" Include="$(ArtifactsBinDir)\Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler\$(Configuration)\$(TargetFramework)\Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler.deps.json" />
</ItemGroup>
<Copy SourceFiles="@(MvcShim)" DestinationFolder="$(PublishDir)" Condition="Exists($(PublishDir))" />
</Target>
</Project>

Просмотреть файл

@ -1,46 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable disable
using System.IO;
using System.Reflection;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions;
internal static class MvcShim
{
public static readonly string AssemblyName = "Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler";
private static Assembly _assembly;
private static CSharpCompilation _baseCompilation;
public static Assembly Assembly
{
get
{
if (_assembly == null)
{
var filePath = Path.Combine(Directory.GetCurrentDirectory(), AssemblyName + ".dll");
_assembly = Assembly.LoadFrom(filePath);
}
return _assembly;
}
}
public static CSharpCompilation BaseCompilation
{
get
{
if (_baseCompilation == null)
{
_baseCompilation = TestCompilation.Create(Assembly);
}
return _baseCompilation;
}
}
}

Просмотреть файл

@ -21,11 +21,35 @@ namespace AspNetCoreGeneratedDocument
internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<dynamic>
#nullable disable
{
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
#pragma warning disable 0169
private string __tagHelperStringValueBuffer;
#pragma warning restore 0169
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager
{
get
{
if (__backed__tagHelperScopeManager == null)
{
__backed__tagHelperScopeManager = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager(StartTagHelperWritingScope, EndTagHelperWritingScope);
}
return __backed__tagHelperScopeManager;
}
}
private global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper __Microsoft_AspNetCore_Mvc_Razor_TagHelpers_HeadTagHelper;
private global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper __Microsoft_AspNetCore_Mvc_Razor_TagHelpers_BodyTagHelper;
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
WriteLiteral("\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"utf-8\" />\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\r\n <title>");
Write(
WriteLiteral("\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("head", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "__UniqueIdSuppressedForTesting__", async() => {
WriteLiteral("\r\n <meta charset=\"utf-8\" />\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\r\n <title>");
Write(
#nullable restore
#line (7,13)-(7,30) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml"
ViewData["Title"]
@ -33,8 +57,34 @@ ViewData["Title"]
#line default
#line hidden
#nullable disable
);
WriteLiteral(" - Test layout component</title>\r\n");
}
);
WriteLiteral(" - Test layout component</title>\r\n</head>\r\n<body TestCssScope>\r\n <p TestCssScope>This is a body.</p>\r\n</body>\r\n</html>\r\n");
__Microsoft_AspNetCore_Mvc_Razor_TagHelpers_HeadTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper>();
__tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_Razor_TagHelpers_HeadTagHelper);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
if (!__tagHelperExecutionContext.Output.IsContentModified)
{
await __tagHelperExecutionContext.SetOutputContentAsync();
}
Write(__tagHelperExecutionContext.Output);
__tagHelperExecutionContext = __tagHelperScopeManager.End();
WriteLiteral("\r\n");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("body", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "__UniqueIdSuppressedForTesting__", async() => {
WriteLiteral("\r\n <p TestCssScope>This is a body.</p>\r\n");
}
);
__Microsoft_AspNetCore_Mvc_Razor_TagHelpers_BodyTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper>();
__tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_Razor_TagHelpers_BodyTagHelper);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
if (!__tagHelperExecutionContext.Output.IsContentModified)
{
await __tagHelperExecutionContext.SetOutputContentAsync();
}
Write(__tagHelperExecutionContext.Output);
__tagHelperExecutionContext = __tagHelperScopeManager.End();
WriteLiteral("\r\n</html>\r\n");
}
#pragma warning restore 1998
#nullable restore

Просмотреть файл

@ -12,49 +12,57 @@
RazorCompiledItemMetadataAttribute -
CreateNewOnMetadataUpdateAttribute -
ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<dynamic> -
DefaultTagHelperRuntime -
FieldDeclaration - - private - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper - __Microsoft_AspNetCore_Mvc_Razor_TagHelpers_HeadTagHelper
FieldDeclaration - - private - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper - __Microsoft_AspNetCore_Mvc_Razor_TagHelpers_BodyTagHelper
MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [164] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
HtmlContent - (0:0,0 [37] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (0:0,0 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (2:1,0 [17] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <!DOCTYPE html>\n
LazyIntermediateToken - (19:2,0 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <html
LazyIntermediateToken - (24:2,5 [10] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - lang="en"
LazyIntermediateToken - (34:2,15 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
LazyIntermediateToken - (35:2,16 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (37:3,0 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <head
LazyIntermediateToken - (42:3,5 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
LazyIntermediateToken - (43:3,6 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (49:4,4 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <meta
LazyIntermediateToken - (54:4,9 [16] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - charset="utf-8"
LazyIntermediateToken - (70:4,25 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
LazyIntermediateToken - (71:4,26 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - />
LazyIntermediateToken - (73:4,28 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (79:5,4 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <meta
LazyIntermediateToken - (84:5,9 [16] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - name="viewport"
LazyIntermediateToken - (100:5,25 [48] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - content="width=device-width, initial-scale=1.0"
LazyIntermediateToken - (148:5,73 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
LazyIntermediateToken - (149:5,74 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - />
LazyIntermediateToken - (151:5,76 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (157:6,4 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <title
LazyIntermediateToken - (163:6,10 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
CSharpExpression - (165:6,12 [17] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (165:6,12 [17] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - ViewData["Title"]
HtmlContent - (182:6,29 [97] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (182:6,29 [24] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \-Test layout component
LazyIntermediateToken - (206:6,53 [8] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </title>
LazyIntermediateToken - (214:6,61 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (216:7,0 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </head>
TagHelper - (37:3,0 [186] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - head - TagMode.StartTagAndEndTag
DefaultTagHelperBody -
HtmlContent - (43:3,6 [121] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (43:3,6 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (49:4,4 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <meta
LazyIntermediateToken - (54:4,9 [16] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - charset="utf-8"
LazyIntermediateToken - (70:4,25 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
LazyIntermediateToken - (71:4,26 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - />
LazyIntermediateToken - (73:4,28 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (79:5,4 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <meta
LazyIntermediateToken - (84:5,9 [16] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - name="viewport"
LazyIntermediateToken - (100:5,25 [48] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - content="width=device-width, initial-scale=1.0"
LazyIntermediateToken - (148:5,73 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
LazyIntermediateToken - (149:5,74 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - />
LazyIntermediateToken - (151:5,76 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (157:6,4 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <title
LazyIntermediateToken - (163:6,10 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
CSharpExpression - (165:6,12 [17] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (165:6,12 [17] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - ViewData["Title"]
HtmlContent - (182:6,29 [34] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (182:6,29 [24] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \-Test layout component
LazyIntermediateToken - (206:6,53 [8] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </title>
LazyIntermediateToken - (214:6,61 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
DefaultTagHelperCreate - - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper
DefaultTagHelperExecute -
HtmlContent - (223:7,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (223:7,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (225:8,0 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <body
IntermediateToken - - Html - TestCssScope
LazyIntermediateToken - (230:8,5 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
LazyIntermediateToken - (231:8,6 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (237:9,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <p
IntermediateToken - - Html - TestCssScope
LazyIntermediateToken - (239:9,6 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
LazyIntermediateToken - (240:9,7 [15] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - This is a body.
LazyIntermediateToken - (255:9,22 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </p>
LazyIntermediateToken - (259:9,26 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (261:10,0 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </body>
TagHelper - (225:8,0 [43] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - body - TagMode.StartTagAndEndTag
DefaultTagHelperBody -
HtmlContent - (231:8,6 [30] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (231:8,6 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (237:9,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - <p
IntermediateToken - - Html - TestCssScope
LazyIntermediateToken - (239:9,6 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - >
LazyIntermediateToken - (240:9,7 [15] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - This is a body.
LazyIntermediateToken - (255:9,22 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </p>
LazyIntermediateToken - (259:9,26 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
DefaultTagHelperCreate - - Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper
DefaultTagHelperExecute -
HtmlContent - (268:10,7 [11] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml)
LazyIntermediateToken - (268:10,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n
LazyIntermediateToken - (270:11,0 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - </html>
LazyIntermediateToken - (277:11,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n

Просмотреть файл

@ -3,11 +3,9 @@
#nullable disable
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Xunit;
using static Microsoft.AspNetCore.Razor.Language.CommonMetadata;
@ -15,20 +13,20 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions;
public class ViewComponentTagHelperDescriptorFactoryTest
{
private static readonly Assembly _assembly = typeof(ViewComponentTagHelperDescriptorFactoryTest).GetTypeInfo().Assembly;
private static readonly Compilation _compilation = TestCompilation.Create(syntaxTrees: [CSharpSyntaxTree.ParseText(AdditionalCode)], references: []);
[Fact]
public void CreateDescriptor_UnderstandsStringParameters()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(StringParameterViewComponent).FullName);
var testCompilation = _compilation;
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.StringParameterViewComponent");
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
ViewComponentTagHelperConventions.Kind,
"__Generated__StringParameterViewComponentTagHelper",
typeof(StringParameterViewComponent).GetTypeInfo().Assembly.GetName().Name)
TestCompilation.AssemblyName)
.Metadata(
TypeName("__Generated__StringParameterViewComponentTagHelper"),
new(ViewComponentTagHelperMetadata.Name, "StringParameter"))
@ -63,14 +61,14 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_UnderstandsVariousParameterTypes()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(VariousParameterViewComponent).FullName);
var testCompilation = _compilation;
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.VariousParameterViewComponent");
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
ViewComponentTagHelperConventions.Kind,
"__Generated__VariousParameterViewComponentTagHelper",
typeof(VariousParameterViewComponent).GetTypeInfo().Assembly.GetName().Name)
TestCompilation.AssemblyName)
.Metadata(
TypeName("__Generated__VariousParameterViewComponentTagHelper"),
new(ViewComponentTagHelperMetadata.Name, "VariousParameter"))
@ -84,9 +82,9 @@ public class ViewComponentTagHelperDescriptorFactoryTest
attribute
.Name("test-enum")
.Metadata(PropertyName("testEnum"))
.TypeName(typeof(VariousParameterViewComponent).FullName + "." + nameof(VariousParameterViewComponent.TestEnum))
.TypeName("TestNamespace.VariousParameterViewComponent.TestEnum")
.AsEnum()
.DisplayName(typeof(VariousParameterViewComponent).FullName + "." + nameof(VariousParameterViewComponent.TestEnum) + " VariousParameterViewComponentTagHelper.testEnum"))
.DisplayName("TestNamespace.VariousParameterViewComponent.TestEnum VariousParameterViewComponentTagHelper.testEnum"))
.BoundAttributeDescriptor(attribute =>
attribute
.Name("test-string")
@ -112,14 +110,14 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_UnderstandsGenericParameters()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(GenericParameterViewComponent).FullName);
var testCompilation = _compilation;
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.GenericParameterViewComponent");
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
ViewComponentTagHelperConventions.Kind,
"__Generated__GenericParameterViewComponentTagHelper",
typeof(GenericParameterViewComponent).GetTypeInfo().Assembly.GetName().Name)
TestCompilation.AssemblyName)
.Metadata(
TypeName("__Generated__GenericParameterViewComponentTagHelper"),
new(ViewComponentTagHelperMetadata.Name, "GenericParameter"))
@ -154,13 +152,13 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForSyncViewComponentWithInvokeInBaseType_Works()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
ViewComponentTagHelperConventions.Kind,
"__Generated__SyncDerivedViewComponentTagHelper",
typeof(SyncDerivedViewComponent).GetTypeInfo().Assembly.GetName().Name)
TestCompilation.AssemblyName)
.Metadata(
TypeName("__Generated__SyncDerivedViewComponentTagHelper"),
new(ViewComponentTagHelperMetadata.Name, "SyncDerived"))
@ -184,7 +182,7 @@ public class ViewComponentTagHelperDescriptorFactoryTest
.DisplayName("string SyncDerivedViewComponentTagHelper.bar"))
.Build();
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncDerivedViewComponent).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.SyncDerivedViewComponent");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -197,13 +195,13 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForAsyncViewComponentWithInvokeInBaseType_Works()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
ViewComponentTagHelperConventions.Kind,
"__Generated__AsyncDerivedViewComponentTagHelper",
typeof(AsyncDerivedViewComponent).Assembly.GetName().Name)
TestCompilation.AssemblyName)
.Metadata(
TypeName("__Generated__AsyncDerivedViewComponentTagHelper"),
new(ViewComponentTagHelperMetadata.Name, "AsyncDerived"))
@ -211,7 +209,7 @@ public class ViewComponentTagHelperDescriptorFactoryTest
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("vc:async-derived"))
.Build();
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncDerivedViewComponent).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.AsyncDerivedViewComponent");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -224,10 +222,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_AddsDiagnostic_ForViewComponentWithNoInvokeMethod()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(ViewComponentWithoutInvokeMethod).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.ViewComponentWithoutInvokeMethod");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -241,10 +239,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_AddsDiagnostic_ForViewComponentWithNoInstanceInvokeMethod()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(StaticInvokeAsyncViewComponent).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.StaticInvokeAsyncViewComponent");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -258,10 +256,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_AddsDiagnostic_ForViewComponentWithNoPublicInvokeMethod()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(NonPublicInvokeAsyncViewComponent).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.NonPublicInvokeAsyncViewComponent");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -275,10 +273,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForViewComponentWithInvokeAsync_UnderstandsGenericTask()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithGenericTask).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.AsyncViewComponentWithGenericTask");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -291,10 +289,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForViewComponentWithInvokeAsync_UnderstandsNonGenericTask()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithNonGenericTask).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.AsyncViewComponentWithNonGenericTask");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -307,10 +305,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForViewComponentWithInvokeAsync_DoesNotUnderstandVoid()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithString).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.AsyncViewComponentWithString");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -324,10 +322,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForViewComponentWithInvokeAsync_DoesNotUnderstandString()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(AsyncViewComponentWithString).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.AsyncViewComponentWithString");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -341,10 +339,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForViewComponentWithInvoke_DoesNotUnderstandVoid()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncViewComponentWithVoid).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.SyncViewComponentWithVoid");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -358,10 +356,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForViewComponentWithInvoke_DoesNotUnderstandNonGenericTask()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncViewComponentWithNonGenericTask).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.SyncViewComponentWithNonGenericTask");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -375,10 +373,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForViewComponentWithInvoke_DoesNotUnderstandGenericTask()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(SyncViewComponentWithGenericTask).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.SyncViewComponentWithGenericTask");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -392,10 +390,10 @@ public class ViewComponentTagHelperDescriptorFactoryTest
public void CreateDescriptor_ForViewComponent_WithAmbiguousMethods()
{
// Arrange
var testCompilation = TestCompilation.Create(_assembly);
var testCompilation = _compilation;
var factory = new ViewComponentTagHelperDescriptorFactory(testCompilation);
var viewComponent = testCompilation.GetTypeByMetadataName(typeof(DerivedViewComponentWithAmbiguity).FullName);
var viewComponent = testCompilation.GetTypeByMetadataName("TestNamespace.DerivedViewComponentWithAmbiguity");
// Act
var descriptor = factory.CreateDescriptor(viewComponent);
@ -404,88 +402,96 @@ public class ViewComponentTagHelperDescriptorFactoryTest
var diagnostic = Assert.Single(descriptor.GetAllDiagnostics());
Assert.Equal(RazorExtensionsDiagnosticFactory.ViewComponent_AmbiguousMethods.Id, diagnostic.Id);
}
}
public class StringParameterViewComponent
{
public string Invoke(string foo, string bar) => null;
}
public const string AdditionalCode = """
using System.Collections.Generic;
using System.Threading.Tasks;
public class VariousParameterViewComponent
{
public string Invoke(TestEnum testEnum, string testString, int baz = 5) => null;
namespace TestNamespace
{
public class StringParameterViewComponent
{
public string Invoke(string foo, string bar) => null;
}
public enum TestEnum
{
A = 1,
B = 2,
C = 3
}
}
public class VariousParameterViewComponent
{
public string Invoke(TestEnum testEnum, string testString, int baz = 5) => null;
public class GenericParameterViewComponent
{
public string Invoke(List<string> Foo, Dictionary<string, int> Bar) => null;
}
public enum TestEnum
{
A = 1,
B = 2,
C = 3
}
}
public class ViewComponentWithoutInvokeMethod
{
}
public class GenericParameterViewComponent
{
public string Invoke(List<string> Foo, Dictionary<string, int> Bar) => null;
}
public class AsyncViewComponentWithGenericTask
{
public Task<string> InvokeAsync() => null;
}
public class ViewComponentWithoutInvokeMethod
{
}
public class AsyncViewComponentWithNonGenericTask
{
public Task InvokeAsync() => null;
}
public class AsyncViewComponentWithGenericTask
{
public Task<string> InvokeAsync() => null;
}
public class AsyncViewComponentWithVoid
{
public void InvokeAsync() { }
}
public class AsyncViewComponentWithNonGenericTask
{
public Task InvokeAsync() => null;
}
public class AsyncViewComponentWithString
{
public string InvokeAsync() => null;
}
public class AsyncViewComponentWithVoid
{
public void InvokeAsync() { }
}
public class SyncViewComponentWithVoid
{
public void Invoke() { }
}
public class AsyncViewComponentWithString
{
public string InvokeAsync() => null;
}
public class SyncViewComponentWithNonGenericTask
{
public Task Invoke() => null;
}
public class SyncViewComponentWithVoid
{
public void Invoke() { }
}
public class SyncViewComponentWithGenericTask
{
public Task<string> Invoke() => null;
}
public class SyncViewComponentWithNonGenericTask
{
public Task Invoke() => null;
}
public class SyncDerivedViewComponent : StringParameterViewComponent
{
}
public class SyncViewComponentWithGenericTask
{
public Task<string> Invoke() => null;
}
public class AsyncDerivedViewComponent : AsyncViewComponentWithNonGenericTask
{
}
public class SyncDerivedViewComponent : StringParameterViewComponent
{
}
public class DerivedViewComponentWithAmbiguity : AsyncViewComponentWithNonGenericTask
{
public string Invoke() => null;
}
public class AsyncDerivedViewComponent : AsyncViewComponentWithNonGenericTask
{
}
public class StaticInvokeAsyncViewComponent
{
public static Task<string> InvokeAsync() => null;
}
public class DerivedViewComponentWithAmbiguity : AsyncViewComponentWithNonGenericTask
{
public string Invoke() => null;
}
public class NonPublicInvokeAsyncViewComponent
{
protected Task<string> InvokeAsync() => null;
public class StaticInvokeAsyncViewComponent
{
public static Task<string> InvokeAsync() => null;
}
public class NonPublicInvokeAsyncViewComponent
{
protected Task<string> InvokeAsync() => null;
}
}
""";
}

Просмотреть файл

@ -25,7 +25,7 @@ public class ViewComponentTagHelperDescriptorProviderTest
}
";
var compilation = MvcShim.BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(code));
var compilation = TestCompilation.Create().AddSyntaxTrees(CSharpSyntaxTree.ParseText(code));
var context = new TagHelperDescriptorProviderContext(compilation);

Просмотреть файл

@ -1,18 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
<PackageReference Include="System.Text.Encodings.Web" />
<ProjectReference Include="..\..\..\Shared\Microsoft.AspNetCore.Razor.Test.ComponentShim\Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Microsoft.AspNetCore.Razor.Test.MvcShim\Microsoft.*\**\*.cs" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,15 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(DefaultNetCoreTargetFrameworks);$(DefaultNetFxTargetFramework)</TargetFrameworks>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
<PackageReference Include="System.Text.Encodings.Web" />
<ProjectReference Include="..\..\..\Shared\Microsoft.AspNetCore.Razor.Test.ComponentShim\Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj" />
</ItemGroup>
</Project>

Просмотреть файл

@ -60,7 +60,7 @@ public static class TestCompilation
public static string AssemblyName => "TestAssembly";
// When we use Basic.Reference.Assemblies everywhere, this overload should be removed.
// Tracked by https://github.com/dotnet/razor/issues/10343.
// See also https://github.com/dotnet/razor/issues/10343.
public static CSharpCompilation Create(Assembly assembly, SyntaxTree syntaxTree = null)
{
IEnumerable<SyntaxTree> syntaxTrees = null;
@ -83,6 +83,8 @@ public static class TestCompilation
return compilation;
}
public static CSharpCompilation Create() => Create(syntaxTrees: [], references: []);
public static CSharpCompilation Create(IEnumerable<SyntaxTree> syntaxTrees, IEnumerable<MetadataReference> references)
{
var compilation = CSharpCompilation.Create(