зеркало из https://github.com/dotnet/razor.git
Use Basic.Reference.Assemblies in MS.CA.Razor.Test (#10877)
* Use Basic.Reference.Assemblies in MS.CA.Razor.Test * Improve code style
This commit is contained in:
Родитель
120997fa75
Коммит
742f378c6a
|
@ -7,24 +7,39 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Microsoft.AspNetCore.Razor.Test.Common;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.Test.Utilities;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor;
|
||||
|
||||
public abstract class TagHelperDescriptorProviderTestBase
|
||||
{
|
||||
static TagHelperDescriptorProviderTestBase()
|
||||
protected TagHelperDescriptorProviderTestBase(string additionalCodeOpt = null)
|
||||
{
|
||||
BaseCompilation = TestCompilation.Create(typeof(ComponentTagHelperDescriptorProviderTest).Assembly);
|
||||
CSharpParseOptions = new CSharpParseOptions(LanguageVersion.CSharp7_3);
|
||||
var testTagHelpers = CSharpCompilation.Create(
|
||||
assemblyName: AssemblyName,
|
||||
syntaxTrees:
|
||||
[
|
||||
Parse(TagHelperDescriptorFactoryTagHelpers.Code),
|
||||
..(additionalCodeOpt != null ? [Parse(additionalCodeOpt)] : Enumerable.Empty<SyntaxTree>()),
|
||||
],
|
||||
references: ReferenceUtil.AspNetLatestAll,
|
||||
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
BaseCompilation = TestCompilation.Create(
|
||||
syntaxTrees: [],
|
||||
references: [testTagHelpers.VerifyDiagnostics().EmitToImageReference()]);
|
||||
}
|
||||
|
||||
protected static Compilation BaseCompilation { get; }
|
||||
protected Compilation BaseCompilation { get; }
|
||||
|
||||
protected static CSharpParseOptions CSharpParseOptions { get; }
|
||||
protected CSharpParseOptions CSharpParseOptions { get; }
|
||||
|
||||
protected static CSharpSyntaxTree Parse(string text)
|
||||
protected static string AssemblyName { get; } = "Microsoft.CodeAnalysis.Razor.Test";
|
||||
|
||||
protected CSharpSyntaxTree Parse(string text)
|
||||
{
|
||||
return (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(text, CSharpParseOptions);
|
||||
}
|
||||
|
@ -35,9 +50,7 @@ public abstract class TagHelperDescriptorProviderTestBase
|
|||
{
|
||||
var results =
|
||||
context.Results
|
||||
.Where(c => c.AssemblyName != "Microsoft.AspNetCore.Razor.Test.ComponentShim")
|
||||
.Where(c => !c.DisplayName.StartsWith("Microsoft.AspNetCore.Components.Web", StringComparison.Ordinal))
|
||||
.Where(c => c.GetTypeName() != "Microsoft.AspNetCore.Components.Bind")
|
||||
.Where(c => !c.DisplayName.StartsWith("Microsoft.AspNetCore.Components.", StringComparison.Ordinal))
|
||||
.OrderBy(c => c.Name)
|
||||
.ToArray();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
using Microsoft.AspNetCore.Razor.Test.Common;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
@ -20,8 +20,8 @@ public class CompilationTagHelperFeatureTest
|
|||
// Arrange
|
||||
var references = new[]
|
||||
{
|
||||
MetadataReference.CreateFromFile(typeof(string).Assembly.Location),
|
||||
};
|
||||
ReferenceUtil.NetLatestSystemRuntime,
|
||||
};
|
||||
var compilation = CSharpCompilation.Create("Test", references: references);
|
||||
|
||||
// Act
|
||||
|
@ -37,8 +37,8 @@ public class CompilationTagHelperFeatureTest
|
|||
// Arrange
|
||||
var references = new[]
|
||||
{
|
||||
MetadataReference.CreateFromFile(typeof(ITagHelper).Assembly.Location),
|
||||
};
|
||||
ReferenceUtil.AspNetLatestRazor,
|
||||
};
|
||||
var compilation = CSharpCompilation.Create("Test", references: references);
|
||||
|
||||
// Act
|
||||
|
@ -54,9 +54,9 @@ public class CompilationTagHelperFeatureTest
|
|||
// Arrange
|
||||
var references = new[]
|
||||
{
|
||||
MetadataReference.CreateFromFile(typeof(string).Assembly.Location),
|
||||
MetadataReference.CreateFromFile(typeof(ITagHelper).Assembly.Location),
|
||||
};
|
||||
ReferenceUtil.NetLatestSystemRuntime,
|
||||
ReferenceUtil.AspNetLatestRazor,
|
||||
};
|
||||
var compilation = CSharpCompilation.Create("Test", references: references);
|
||||
|
||||
// Act
|
||||
|
@ -104,9 +104,9 @@ public class CompilationTagHelperFeatureTest
|
|||
|
||||
var references = new[]
|
||||
{
|
||||
MetadataReference.CreateFromFile(typeof(string).Assembly.Location),
|
||||
MetadataReference.CreateFromFile(typeof(ITagHelper).Assembly.Location),
|
||||
};
|
||||
ReferenceUtil.NetLatestSystemRuntime,
|
||||
ReferenceUtil.AspNetLatestRazor,
|
||||
};
|
||||
|
||||
var engine = RazorProjectEngine.Create(
|
||||
configure =>
|
||||
|
|
|
@ -1620,7 +1620,7 @@ namespace Test
|
|||
Assert.Empty(compilation.GetDiagnostics());
|
||||
|
||||
var targetSymbol = (IAssemblySymbol)compilation.GetAssemblyOrModuleSymbol(
|
||||
compilation.References.First(static r => r.Display.Contains("Microsoft.CodeAnalysis.Razor.Test.dll")));
|
||||
compilation.References.First(static r => r.Display.Contains("Microsoft.CodeAnalysis.Razor.Test")));
|
||||
|
||||
var context = new TagHelperDescriptorProviderContext(compilation, targetSymbol);
|
||||
var provider = new ComponentTagHelperDescriptorProvider();
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -4,23 +4,19 @@
|
|||
#nullable disable
|
||||
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor;
|
||||
|
||||
public class DefaultTagHelperDescriptorProviderTest
|
||||
public class DefaultTagHelperDescriptorProviderTest : TagHelperDescriptorProviderTestBase
|
||||
{
|
||||
private static readonly Assembly _assembly = typeof(DefaultTagHelperDescriptorProviderTest).GetTypeInfo().Assembly;
|
||||
|
||||
[Fact]
|
||||
public void Execute_DoesNotAddEditorBrowsableNeverDescriptorsAtDesignTime()
|
||||
{
|
||||
// Arrange
|
||||
var editorBrowsableTypeName = "Microsoft.CodeAnalysis.Razor.Workspaces.Test.EditorBrowsableTagHelper";
|
||||
var compilation = TestCompilation.Create(_assembly);
|
||||
var editorBrowsableTypeName = "TestNamespace.EditorBrowsableTagHelper";
|
||||
var compilation = BaseCompilation;
|
||||
var descriptorProvider = new DefaultTagHelperDescriptorProvider();
|
||||
|
||||
var context = new TagHelperDescriptorProviderContext(compilation)
|
||||
|
@ -44,7 +40,7 @@ public class DefaultTagHelperDescriptorProviderTest
|
|||
{
|
||||
// Arrange
|
||||
var testTagHelper = "TestAssembly.TestTagHelper";
|
||||
var enumTagHelper = "Microsoft.CodeAnalysis.Razor.Workspaces.Test.EnumTagHelper";
|
||||
var enumTagHelper = "TestNamespace.EnumTagHelper";
|
||||
var csharp = @"
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
namespace TestAssembly
|
||||
|
@ -54,7 +50,7 @@ namespace TestAssembly
|
|||
public override void Process(TagHelperContext context, TagHelperOutput output) {}
|
||||
}
|
||||
}";
|
||||
var compilation = TestCompilation.Create(_assembly, CSharpSyntaxTree.ParseText(csharp));
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(Parse(csharp));
|
||||
var descriptorProvider = new DefaultTagHelperDescriptorProvider();
|
||||
|
||||
var context = new TagHelperDescriptorProviderContext(compilation);
|
||||
|
@ -74,7 +70,7 @@ namespace TestAssembly
|
|||
{
|
||||
// Arrange
|
||||
var testTagHelper = "TestAssembly.TestTagHelper";
|
||||
var enumTagHelper = "Microsoft.CodeAnalysis.Razor.Workspaces.Test.EnumTagHelper";
|
||||
var enumTagHelper = "TestNamespace.EnumTagHelper";
|
||||
var csharp = @"
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
namespace TestAssembly
|
||||
|
@ -84,11 +80,11 @@ namespace TestAssembly
|
|||
public override void Process(TagHelperContext context, TagHelperOutput output) {}
|
||||
}
|
||||
}";
|
||||
var compilation = TestCompilation.Create(_assembly, CSharpSyntaxTree.ParseText(csharp));
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(Parse(csharp));
|
||||
var descriptorProvider = new DefaultTagHelperDescriptorProvider();
|
||||
|
||||
var targetSymbol = (IAssemblySymbol)compilation.GetAssemblyOrModuleSymbol(
|
||||
compilation.References.First(static r => r.Display.Contains("Microsoft.CodeAnalysis.Razor.Test.dll")));
|
||||
compilation.References.First(static r => r.Display.Contains("Microsoft.CodeAnalysis.Razor.Test")));
|
||||
|
||||
var context = new TagHelperDescriptorProviderContext(compilation, targetSymbol);
|
||||
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisWorkspacesCommonPackageVersion)" />
|
||||
<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" />
|
||||
<!-- Included for definitions of Tag Helper types -->
|
||||
<ProjectReference Include="..\..\test\Microsoft.AspNetCore.Razor.Test.MvcShim\Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler.csproj" />
|
||||
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
|
||||
<PackageReference Include="Moq" />
|
||||
|
|
|
@ -3,462 +3,470 @@
|
|||
|
||||
#nullable disable
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor;
|
||||
|
||||
internal static class TagHelperDescriptorFactoryTagHelpers
|
||||
{
|
||||
public const string Code = """
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor.Workspaces.Test;
|
||||
|
||||
public enum CustomEnum
|
||||
namespace TestNamespace
|
||||
{
|
||||
FirstValue,
|
||||
SecondValue
|
||||
}
|
||||
|
||||
public class EnumTagHelper : TagHelper
|
||||
{
|
||||
public int NonEnumProperty { get; set; }
|
||||
|
||||
public CustomEnum EnumProperty { get; set; }
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("input")]
|
||||
public class MultiEnumTagHelper : EnumTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class NestedEnumTagHelper : EnumTagHelper
|
||||
{
|
||||
public NestedEnum NestedEnumProperty { get; set; }
|
||||
|
||||
public enum NestedEnum
|
||||
public enum CustomEnum
|
||||
{
|
||||
NestedOne,
|
||||
NestedTwo
|
||||
FirstValue,
|
||||
SecondValue
|
||||
}
|
||||
}
|
||||
|
||||
[HtmlTargetElement("input", ParentTag = "div")]
|
||||
public class RequiredParentTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
public class EnumTagHelper : TagHelper
|
||||
{
|
||||
public int NonEnumProperty { get; set; }
|
||||
|
||||
[HtmlTargetElement("p", ParentTag = "div")]
|
||||
[HtmlTargetElement("input", ParentTag = "section")]
|
||||
public class MultiSpecifiedRequiredParentTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
public CustomEnum EnumProperty { get; set; }
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("input", ParentTag = "div")]
|
||||
public class MultiWithUnspecifiedRequiredParentTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("input")]
|
||||
public class MultiEnumTagHelper : EnumTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class NestedEnumTagHelper : EnumTagHelper
|
||||
{
|
||||
public NestedEnum NestedEnumProperty { get; set; }
|
||||
|
||||
public enum NestedEnum
|
||||
{
|
||||
NestedOne,
|
||||
NestedTwo
|
||||
}
|
||||
}
|
||||
|
||||
[HtmlTargetElement("input", ParentTag = "div")]
|
||||
public class RequiredParentTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p", ParentTag = "div")]
|
||||
[HtmlTargetElement("input", ParentTag = "section")]
|
||||
public class MultiSpecifiedRequiredParentTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("input", ParentTag = "div")]
|
||||
public class MultiWithUnspecifiedRequiredParentTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[RestrictChildren("p")]
|
||||
public class RestrictChildrenTagHelper
|
||||
{
|
||||
}
|
||||
[RestrictChildren("p")]
|
||||
public class RestrictChildrenTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[RestrictChildren("p", "strong")]
|
||||
public class DoubleRestrictChildrenTagHelper
|
||||
{
|
||||
}
|
||||
[RestrictChildren("p", "strong")]
|
||||
public class DoubleRestrictChildrenTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("div")]
|
||||
[RestrictChildren("p", "strong")]
|
||||
public class MultiTargetRestrictChildrenTagHelper
|
||||
{
|
||||
}
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("div")]
|
||||
[RestrictChildren("p", "strong")]
|
||||
public class MultiTargetRestrictChildrenTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("input", TagStructure = TagStructure.WithoutEndTag)]
|
||||
public class TagStructureTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
[HtmlTargetElement("input", TagStructure = TagStructure.WithoutEndTag)]
|
||||
public class TagStructureTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p", TagStructure = TagStructure.NormalOrSelfClosing)]
|
||||
[HtmlTargetElement("input", TagStructure = TagStructure.WithoutEndTag)]
|
||||
public class MultiSpecifiedTagStructureTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
[HtmlTargetElement("p", TagStructure = TagStructure.NormalOrSelfClosing)]
|
||||
[HtmlTargetElement("input", TagStructure = TagStructure.WithoutEndTag)]
|
||||
public class MultiSpecifiedTagStructureTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("input", TagStructure = TagStructure.WithoutEndTag)]
|
||||
public class MultiWithUnspecifiedTagStructureTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("input", TagStructure = TagStructure.WithoutEndTag)]
|
||||
public class MultiWithUnspecifiedTagStructureTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Always)]
|
||||
public class DefaultEditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Always)]
|
||||
public int Property { get; set; }
|
||||
}
|
||||
public class DefaultEditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Always)]
|
||||
public int Property { get; set; }
|
||||
}
|
||||
|
||||
public class HiddenPropertyEditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public int Property { get; set; }
|
||||
}
|
||||
|
||||
public class MultiPropertyEditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public int Property { get; set; }
|
||||
|
||||
public virtual int Property2 { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenPropertyEditorBrowsableTagHelper : MultiPropertyEditorBrowsableTagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public override int Property2 { get; set; }
|
||||
}
|
||||
|
||||
public class HiddenPropertyEditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public int Property { get; set; }
|
||||
}
|
||||
public class EditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public virtual int Property { get; set; }
|
||||
}
|
||||
|
||||
public class MultiPropertyEditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public int Property { get; set; }
|
||||
public class InheritedEditorBrowsableTagHelper : EditorBrowsableTagHelper
|
||||
{
|
||||
public override int Property { get; set; }
|
||||
}
|
||||
|
||||
public virtual int Property2 { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenPropertyEditorBrowsableTagHelper : MultiPropertyEditorBrowsableTagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public override int Property2 { get; set; }
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public class EditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public virtual int Property { get; set; }
|
||||
}
|
||||
|
||||
public class InheritedEditorBrowsableTagHelper : EditorBrowsableTagHelper
|
||||
{
|
||||
public override int Property { get; set; }
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Advanced)]
|
||||
public class OverriddenEditorBrowsableTagHelper : EditorBrowsableTagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Advanced)]
|
||||
public override int Property { get; set; }
|
||||
}
|
||||
public class OverriddenEditorBrowsableTagHelper : EditorBrowsableTagHelper
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Advanced)]
|
||||
public override int Property { get; set; }
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("div")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public class MultiEditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement(Attributes = "class*")]
|
||||
public class AttributeWildcardTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement(Attributes = "class*,style*")]
|
||||
public class MultiAttributeWildcardTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement(Attributes = "class")]
|
||||
public class AttributeTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement(Attributes = "class,style")]
|
||||
public class MultiAttributeTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement(Attributes = "custom")]
|
||||
[HtmlTargetElement(Attributes = "class,style")]
|
||||
public class MultiAttributeAttributeTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement(Attributes = "style")]
|
||||
public class InheritedAttributeTargetingTagHelper : AttributeTargetingTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("input", Attributes = "class")]
|
||||
public class RequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("div", Attributes = "class")]
|
||||
public class InheritedRequiredAttributeTagHelper : RequiredAttributeTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("div", Attributes = "class")]
|
||||
[HtmlTargetElement("input", Attributes = "class")]
|
||||
public class MultiAttributeRequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("input", Attributes = "style")]
|
||||
[HtmlTargetElement("input", Attributes = "class")]
|
||||
public class MultiAttributeSameTagRequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("input", Attributes = "class,style")]
|
||||
public class MultiRequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("div", Attributes = "style")]
|
||||
public class InheritedMultiRequiredAttributeTagHelper : MultiRequiredAttributeTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("div", Attributes = "class,style")]
|
||||
[HtmlTargetElement("input", Attributes = "class,style")]
|
||||
public class MultiTagMultiRequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("div")]
|
||||
public class MultiTagTagHelper
|
||||
{
|
||||
public string ValidAttribute { get; set; }
|
||||
}
|
||||
|
||||
public class InheritedMultiTagTagHelper : MultiTagTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("div")]
|
||||
[HtmlTargetElement("div")]
|
||||
public class DuplicateTagNameTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("data-condition")]
|
||||
public class OverrideNameTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class InheritedSingleAttributeTagHelper : SingleAttributeTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class DuplicateAttributeNameTagHelper
|
||||
{
|
||||
public string MyNameIsLegion { get; set; }
|
||||
|
||||
[HtmlAttributeName("my-name-is-legion")]
|
||||
public string Fred { get; set; }
|
||||
}
|
||||
|
||||
public class NotBoundAttributeTagHelper
|
||||
{
|
||||
public object BoundProperty { get; set; }
|
||||
|
||||
[HtmlAttributeNotBound]
|
||||
public string NotBoundProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("unused")]
|
||||
[HtmlAttributeNotBound]
|
||||
public string NamedNotBoundProperty { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenAttributeTagHelper
|
||||
{
|
||||
[HtmlAttributeName("SomethingElse")]
|
||||
public virtual string ValidAttribute1 { get; set; }
|
||||
|
||||
[HtmlAttributeName("Something-Else")]
|
||||
public string ValidAttribute2 { get; set; }
|
||||
}
|
||||
|
||||
public class InheritedOverriddenAttributeTagHelper : OverriddenAttributeTagHelper
|
||||
{
|
||||
public override string ValidAttribute1 { get; set; }
|
||||
}
|
||||
|
||||
public class InheritedNotOverriddenAttributeTagHelper : OverriddenAttributeTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class ALLCAPSTAGHELPER : TagHelper
|
||||
{
|
||||
public int ALLCAPSATTRIBUTE { get; set; }
|
||||
}
|
||||
|
||||
public class CAPSOnOUTSIDETagHelper : TagHelper
|
||||
{
|
||||
public int CAPSOnOUTSIDEATTRIBUTE { get; set; }
|
||||
}
|
||||
|
||||
public class capsONInsideTagHelper : TagHelper
|
||||
{
|
||||
public int capsONInsideattribute { get; set; }
|
||||
}
|
||||
|
||||
public class One1Two2Three3TagHelper : TagHelper
|
||||
{
|
||||
public int One1Two2Three3Attribute { get; set; }
|
||||
}
|
||||
|
||||
public class ONE1TWO2THREE3TagHelper : TagHelper
|
||||
{
|
||||
public int ONE1TWO2THREE3Attribute { get; set; }
|
||||
}
|
||||
|
||||
public class First_Second_ThirdHiTagHelper : TagHelper
|
||||
{
|
||||
public int First_Second_ThirdAttribute { get; set; }
|
||||
}
|
||||
|
||||
public class UNSuffixedCLASS : TagHelper
|
||||
{
|
||||
public int UNSuffixedATTRIBUTE { get; set; }
|
||||
}
|
||||
|
||||
public class InvalidBoundAttribute : TagHelper
|
||||
{
|
||||
public string DataSomething { get; set; }
|
||||
}
|
||||
|
||||
public class InvalidBoundAttributeWithValid : SingleAttributeTagHelper
|
||||
{
|
||||
public string DataSomething { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenInvalidBoundAttributeWithValid : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-something")]
|
||||
public string DataSomething { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenValidBoundAttributeWithInvalid : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("data-something")]
|
||||
public string ValidSomething { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenValidBoundAttributeWithInvalidUpperCase : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("DATA-SOMETHING")]
|
||||
public string ValidSomething { get; set; }
|
||||
}
|
||||
|
||||
public class DefaultValidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
public IDictionary<string, string> DictionaryProperty { get; set; }
|
||||
}
|
||||
|
||||
public class SingleValidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-name")]
|
||||
public IDictionary<string, string> DictionaryProperty { get; set; }
|
||||
}
|
||||
|
||||
public class MultipleValidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-name1", DictionaryAttributePrefix = "valid-prefix1-")]
|
||||
public Dictionary<string, object> DictionaryProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name2", DictionaryAttributePrefix = "valid-prefix2-")]
|
||||
public DictionarySubclass DictionarySubclassProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name3", DictionaryAttributePrefix = "valid-prefix3-")]
|
||||
public DictionaryWithoutParameterlessConstructor DictionaryWithoutParameterlessConstructorProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name4", DictionaryAttributePrefix = "valid-prefix4-")]
|
||||
public GenericDictionarySubclass<object> GenericDictionarySubclassProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name5", DictionaryAttributePrefix = "valid-prefix5-")]
|
||||
public SortedDictionary<string, int> SortedDictionaryProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name6")]
|
||||
public string StringProperty { get; set; }
|
||||
|
||||
public IDictionary<string, int> GetOnlyDictionaryProperty { get; }
|
||||
|
||||
[HtmlAttributeName(DictionaryAttributePrefix = "valid-prefix6")]
|
||||
public IDictionary<string, string> GetOnlyDictionaryPropertyWithAttributePrefix { get; }
|
||||
}
|
||||
|
||||
public class SingleInvalidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-name", DictionaryAttributePrefix = "valid-prefix")]
|
||||
public string StringProperty { get; set; }
|
||||
}
|
||||
|
||||
public class MultipleInvalidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-name1")]
|
||||
public long LongProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name2", DictionaryAttributePrefix = "valid-prefix2-")]
|
||||
public Dictionary<int, string> DictionaryOfIntProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name3", DictionaryAttributePrefix = "valid-prefix3-")]
|
||||
public IReadOnlyDictionary<string, object> ReadOnlyDictionaryProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name4", DictionaryAttributePrefix = "valid-prefix4-")]
|
||||
public int IntProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name5", DictionaryAttributePrefix = "valid-prefix5-")]
|
||||
public DictionaryOfIntSubclass DictionaryOfIntSubclassProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName(DictionaryAttributePrefix = "valid-prefix6")]
|
||||
public IDictionary<int, string> GetOnlyDictionaryAttributePrefix { get; }
|
||||
|
||||
[HtmlAttributeName("invalid-name7")]
|
||||
public IDictionary<string, object> GetOnlyDictionaryPropertyWithAttributeName { get; }
|
||||
}
|
||||
|
||||
public class DictionarySubclass : Dictionary<string, string>
|
||||
{
|
||||
}
|
||||
|
||||
public class DictionaryWithoutParameterlessConstructor : Dictionary<string, string>
|
||||
{
|
||||
public DictionaryWithoutParameterlessConstructor(int count)
|
||||
: base()
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("div")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public class MultiEditorBrowsableTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class DictionaryOfIntSubclass : Dictionary<int, string>
|
||||
{
|
||||
}
|
||||
[HtmlTargetElement(Attributes = "class*")]
|
||||
public class AttributeWildcardTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class GenericDictionarySubclass<TValue> : Dictionary<string, TValue>
|
||||
{
|
||||
}
|
||||
[HtmlTargetElement(Attributes = "class*,style*")]
|
||||
public class MultiAttributeWildcardTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[OutputElementHint("strong")]
|
||||
public class OutputElementHintTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
[HtmlTargetElement(Attributes = "class")]
|
||||
public class AttributeTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("a")]
|
||||
[HtmlTargetElement("p")]
|
||||
[OutputElementHint("div")]
|
||||
public class MultipleDescriptorTagHelperWithOutputElementHint : TagHelper
|
||||
{
|
||||
}
|
||||
[HtmlTargetElement(Attributes = "class,style")]
|
||||
public class MultiAttributeTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class NonPublicAccessorTagHelper : TagHelper
|
||||
{
|
||||
public string ValidAttribute { get; set; }
|
||||
public string InvalidPrivateSetAttribute { get; private set; }
|
||||
public string InvalidPrivateGetAttribute { private get; set; }
|
||||
protected string InvalidProtectedAttribute { get; set; }
|
||||
internal string InvalidInternalAttribute { get; set; }
|
||||
protected internal string InvalidProtectedInternalAttribute { get; set; }
|
||||
}
|
||||
[HtmlTargetElement(Attributes = "custom")]
|
||||
[HtmlTargetElement(Attributes = "class,style")]
|
||||
public class MultiAttributeAttributeTargetingTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class SingleAttributeTagHelper : TagHelper
|
||||
{
|
||||
public int IntAttribute { get; set; }
|
||||
}
|
||||
[HtmlTargetElement(Attributes = "style")]
|
||||
public class InheritedAttributeTargetingTagHelper : AttributeTargetingTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class MissingAccessorTagHelper : TagHelper
|
||||
{
|
||||
public string ValidAttribute { get; set; }
|
||||
public string InvalidNoGetAttribute { set { } }
|
||||
public string InvalidNoSetAttribute { get { return string.Empty; } }
|
||||
[HtmlTargetElement("input", Attributes = "class")]
|
||||
public class RequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("div", Attributes = "class")]
|
||||
public class InheritedRequiredAttributeTagHelper : RequiredAttributeTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("div", Attributes = "class")]
|
||||
[HtmlTargetElement("input", Attributes = "class")]
|
||||
public class MultiAttributeRequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("input", Attributes = "style")]
|
||||
[HtmlTargetElement("input", Attributes = "class")]
|
||||
public class MultiAttributeSameTagRequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("input", Attributes = "class,style")]
|
||||
public class MultiRequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("div", Attributes = "style")]
|
||||
public class InheritedMultiRequiredAttributeTagHelper : MultiRequiredAttributeTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("div", Attributes = "class,style")]
|
||||
[HtmlTargetElement("input", Attributes = "class,style")]
|
||||
public class MultiTagMultiRequiredAttributeTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("div")]
|
||||
public class MultiTagTagHelper
|
||||
{
|
||||
public string ValidAttribute { get; set; }
|
||||
}
|
||||
|
||||
public class InheritedMultiTagTagHelper : MultiTagTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("p")]
|
||||
[HtmlTargetElement("div")]
|
||||
[HtmlTargetElement("div")]
|
||||
public class DuplicateTagNameTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("data-condition")]
|
||||
public class OverrideNameTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class InheritedSingleAttributeTagHelper : SingleAttributeTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class DuplicateAttributeNameTagHelper
|
||||
{
|
||||
public string MyNameIsLegion { get; set; }
|
||||
|
||||
[HtmlAttributeName("my-name-is-legion")]
|
||||
public string Fred { get; set; }
|
||||
}
|
||||
|
||||
public class NotBoundAttributeTagHelper
|
||||
{
|
||||
public object BoundProperty { get; set; }
|
||||
|
||||
[HtmlAttributeNotBound]
|
||||
public string NotBoundProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("unused")]
|
||||
[HtmlAttributeNotBound]
|
||||
public string NamedNotBoundProperty { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenAttributeTagHelper
|
||||
{
|
||||
[HtmlAttributeName("SomethingElse")]
|
||||
public virtual string ValidAttribute1 { get; set; }
|
||||
|
||||
[HtmlAttributeName("Something-Else")]
|
||||
public string ValidAttribute2 { get; set; }
|
||||
}
|
||||
|
||||
public class InheritedOverriddenAttributeTagHelper : OverriddenAttributeTagHelper
|
||||
{
|
||||
public override string ValidAttribute1 { get; set; }
|
||||
}
|
||||
|
||||
public class InheritedNotOverriddenAttributeTagHelper : OverriddenAttributeTagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class ALLCAPSTAGHELPER : TagHelper
|
||||
{
|
||||
public int ALLCAPSATTRIBUTE { get; set; }
|
||||
}
|
||||
|
||||
public class CAPSOnOUTSIDETagHelper : TagHelper
|
||||
{
|
||||
public int CAPSOnOUTSIDEATTRIBUTE { get; set; }
|
||||
}
|
||||
|
||||
public class capsONInsideTagHelper : TagHelper
|
||||
{
|
||||
public int capsONInsideattribute { get; set; }
|
||||
}
|
||||
|
||||
public class One1Two2Three3TagHelper : TagHelper
|
||||
{
|
||||
public int One1Two2Three3Attribute { get; set; }
|
||||
}
|
||||
|
||||
public class ONE1TWO2THREE3TagHelper : TagHelper
|
||||
{
|
||||
public int ONE1TWO2THREE3Attribute { get; set; }
|
||||
}
|
||||
|
||||
public class First_Second_ThirdHiTagHelper : TagHelper
|
||||
{
|
||||
public int First_Second_ThirdAttribute { get; set; }
|
||||
}
|
||||
|
||||
public class UNSuffixedCLASS : TagHelper
|
||||
{
|
||||
public int UNSuffixedATTRIBUTE { get; set; }
|
||||
}
|
||||
|
||||
public class InvalidBoundAttribute : TagHelper
|
||||
{
|
||||
public string DataSomething { get; set; }
|
||||
}
|
||||
|
||||
public class InvalidBoundAttributeWithValid : SingleAttributeTagHelper
|
||||
{
|
||||
public string DataSomething { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenInvalidBoundAttributeWithValid : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-something")]
|
||||
public string DataSomething { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenValidBoundAttributeWithInvalid : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("data-something")]
|
||||
public string ValidSomething { get; set; }
|
||||
}
|
||||
|
||||
public class OverriddenValidBoundAttributeWithInvalidUpperCase : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("DATA-SOMETHING")]
|
||||
public string ValidSomething { get; set; }
|
||||
}
|
||||
|
||||
public class DefaultValidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
public IDictionary<string, string> DictionaryProperty { get; set; }
|
||||
}
|
||||
|
||||
public class SingleValidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-name")]
|
||||
public IDictionary<string, string> DictionaryProperty { get; set; }
|
||||
}
|
||||
|
||||
public class MultipleValidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-name1", DictionaryAttributePrefix = "valid-prefix1-")]
|
||||
public Dictionary<string, object> DictionaryProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name2", DictionaryAttributePrefix = "valid-prefix2-")]
|
||||
public DictionarySubclass DictionarySubclassProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name3", DictionaryAttributePrefix = "valid-prefix3-")]
|
||||
public DictionaryWithoutParameterlessConstructor DictionaryWithoutParameterlessConstructorProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name4", DictionaryAttributePrefix = "valid-prefix4-")]
|
||||
public GenericDictionarySubclass<object> GenericDictionarySubclassProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name5", DictionaryAttributePrefix = "valid-prefix5-")]
|
||||
public SortedDictionary<string, int> SortedDictionaryProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name6")]
|
||||
public string StringProperty { get; set; }
|
||||
|
||||
public IDictionary<string, int> GetOnlyDictionaryProperty { get; }
|
||||
|
||||
[HtmlAttributeName(DictionaryAttributePrefix = "valid-prefix6")]
|
||||
public IDictionary<string, string> GetOnlyDictionaryPropertyWithAttributePrefix { get; }
|
||||
}
|
||||
|
||||
public class SingleInvalidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-name", DictionaryAttributePrefix = "valid-prefix")]
|
||||
public string StringProperty { get; set; }
|
||||
}
|
||||
|
||||
public class MultipleInvalidHtmlAttributePrefix : TagHelper
|
||||
{
|
||||
[HtmlAttributeName("valid-name1")]
|
||||
public long LongProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name2", DictionaryAttributePrefix = "valid-prefix2-")]
|
||||
public Dictionary<int, string> DictionaryOfIntProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name3", DictionaryAttributePrefix = "valid-prefix3-")]
|
||||
public IReadOnlyDictionary<string, object> ReadOnlyDictionaryProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name4", DictionaryAttributePrefix = "valid-prefix4-")]
|
||||
public int IntProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName("valid-name5", DictionaryAttributePrefix = "valid-prefix5-")]
|
||||
public DictionaryOfIntSubclass DictionaryOfIntSubclassProperty { get; set; }
|
||||
|
||||
[HtmlAttributeName(DictionaryAttributePrefix = "valid-prefix6")]
|
||||
public IDictionary<int, string> GetOnlyDictionaryAttributePrefix { get; }
|
||||
|
||||
[HtmlAttributeName("invalid-name7")]
|
||||
public IDictionary<string, object> GetOnlyDictionaryPropertyWithAttributeName { get; }
|
||||
}
|
||||
|
||||
public class DictionarySubclass : Dictionary<string, string>
|
||||
{
|
||||
}
|
||||
|
||||
public class DictionaryWithoutParameterlessConstructor : Dictionary<string, string>
|
||||
{
|
||||
public DictionaryWithoutParameterlessConstructor(int count)
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class DictionaryOfIntSubclass : Dictionary<int, string>
|
||||
{
|
||||
}
|
||||
|
||||
public class GenericDictionarySubclass<TValue> : Dictionary<string, TValue>
|
||||
{
|
||||
}
|
||||
|
||||
[OutputElementHint("strong")]
|
||||
public class OutputElementHintTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
[HtmlTargetElement("a")]
|
||||
[HtmlTargetElement("p")]
|
||||
[OutputElementHint("div")]
|
||||
public class MultipleDescriptorTagHelperWithOutputElementHint : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class NonPublicAccessorTagHelper : TagHelper
|
||||
{
|
||||
public string ValidAttribute { get; set; }
|
||||
public string InvalidPrivateSetAttribute { get; private set; }
|
||||
public string InvalidPrivateGetAttribute { private get; set; }
|
||||
protected string InvalidProtectedAttribute { get; set; }
|
||||
internal string InvalidInternalAttribute { get; set; }
|
||||
protected internal string InvalidProtectedInternalAttribute { get; set; }
|
||||
}
|
||||
|
||||
public class SingleAttributeTagHelper : TagHelper
|
||||
{
|
||||
public int IntAttribute { get; set; }
|
||||
}
|
||||
|
||||
public class MissingAccessorTagHelper : TagHelper
|
||||
{
|
||||
public string ValidAttribute { get; set; }
|
||||
public string InvalidNoGetAttribute { set { } }
|
||||
public string InvalidNoSetAttribute { get { return string.Empty; } }
|
||||
}
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
|
|
@ -4,26 +4,28 @@
|
|||
#nullable disable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
|
||||
|
||||
public class TagHelperTypeVisitorTest
|
||||
public class TagHelperTypeVisitorTest : TagHelperDescriptorProviderTestBase
|
||||
{
|
||||
private static readonly Assembly _assembly = typeof(TagHelperTypeVisitorTest).GetTypeInfo().Assembly;
|
||||
public TagHelperTypeVisitorTest() : base(AdditionalCode)
|
||||
{
|
||||
Compilation = BaseCompilation;
|
||||
ITagHelperSymbol = Compilation.GetTypeByMetadataName(TagHelperTypes.ITagHelper);
|
||||
}
|
||||
|
||||
private static Compilation Compilation { get; } = TestCompilation.Create(_assembly);
|
||||
private Compilation Compilation { get; }
|
||||
|
||||
private static INamedTypeSymbol ITagHelperSymbol { get; } = Compilation.GetTypeByMetadataName(TagHelperTypes.ITagHelper);
|
||||
private INamedTypeSymbol ITagHelperSymbol { get; }
|
||||
|
||||
[Fact]
|
||||
public void IsTagHelper_PlainTagHelper_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var testVisitor = new TagHelperTypeVisitor(ITagHelperSymbol, new List<INamedTypeSymbol>());
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Valid_PlainTagHelper).FullName);
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName("TestNamespace.Valid_PlainTagHelper");
|
||||
|
||||
// Act
|
||||
var isTagHelper = testVisitor.IsTagHelper(tagHelperSymbol);
|
||||
|
@ -37,7 +39,7 @@ public class TagHelperTypeVisitorTest
|
|||
{
|
||||
// Arrange
|
||||
var testVisitor = new TagHelperTypeVisitor(ITagHelperSymbol, new List<INamedTypeSymbol>());
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Valid_InheritedTagHelper).FullName);
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName("TestNamespace.Valid_InheritedTagHelper");
|
||||
|
||||
// Act
|
||||
var isTagHelper = testVisitor.IsTagHelper(tagHelperSymbol);
|
||||
|
@ -51,7 +53,7 @@ public class TagHelperTypeVisitorTest
|
|||
{
|
||||
// Arrange
|
||||
var testVisitor = new TagHelperTypeVisitor(ITagHelperSymbol, new List<INamedTypeSymbol>());
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Invalid_AbstractTagHelper).FullName);
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName("TestNamespace.Invalid_AbstractTagHelper");
|
||||
|
||||
// Act
|
||||
var isTagHelper = testVisitor.IsTagHelper(tagHelperSymbol);
|
||||
|
@ -65,7 +67,7 @@ public class TagHelperTypeVisitorTest
|
|||
{
|
||||
// Arrange
|
||||
var testVisitor = new TagHelperTypeVisitor(ITagHelperSymbol, new List<INamedTypeSymbol>());
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Invalid_GenericTagHelper<>).FullName);
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName("TestNamespace.Invalid_GenericTagHelper`1");
|
||||
|
||||
// Act
|
||||
var isTagHelper = testVisitor.IsTagHelper(tagHelperSymbol);
|
||||
|
@ -79,7 +81,7 @@ public class TagHelperTypeVisitorTest
|
|||
{
|
||||
// Arrange
|
||||
var testVisitor = new TagHelperTypeVisitor(ITagHelperSymbol, new List<INamedTypeSymbol>());
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Invalid_InternalTagHelper).FullName);
|
||||
var tagHelperSymbol = Compilation.GetTypeByMetadataName("TestNamespace.Invalid_InternalTagHelper");
|
||||
|
||||
// Act
|
||||
var isTagHelper = testVisitor.IsTagHelper(tagHelperSymbol);
|
||||
|
@ -88,32 +90,40 @@ public class TagHelperTypeVisitorTest
|
|||
Assert.False(isTagHelper);
|
||||
}
|
||||
|
||||
public class Invalid_NestedPublicTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
private const string AdditionalCode =
|
||||
"""
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
|
||||
public class Valid_NestedPublicViewComponent
|
||||
{
|
||||
public string Invoke(string foo) => null;
|
||||
}
|
||||
}
|
||||
namespace TestNamespace
|
||||
{
|
||||
public class Invalid_NestedPublicTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class Invalid_AbstractTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
public class Valid_NestedPublicViewComponent
|
||||
{
|
||||
public string Invoke(string foo) => null;
|
||||
}
|
||||
|
||||
public class Invalid_GenericTagHelper<T> : TagHelper
|
||||
{
|
||||
}
|
||||
public abstract class Invalid_AbstractTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
internal class Invalid_InternalTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
public class Invalid_GenericTagHelper<T> : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class Valid_PlainTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
internal class Invalid_InternalTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class Valid_InheritedTagHelper : Valid_PlainTagHelper
|
||||
{
|
||||
public class Valid_PlainTagHelper : TagHelper
|
||||
{
|
||||
}
|
||||
|
||||
public class Valid_InheritedTagHelper : Valid_PlainTagHelper
|
||||
{
|
||||
}
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.CodeAnalysis.Razor.Workspaces\Microsoft.CodeAnalysis.Razor.Workspaces.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Test.Common.Tooling\Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Test.MvcShim\Microsoft.AspNetCore.Razor.Test.MvcShim.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -12,5 +12,7 @@ internal static class ReferenceUtil
|
|||
{
|
||||
public static ImmutableArray<PortableExecutableReference> AspNetLatestAll { get; } = AspNetLatest.References.All;
|
||||
public static PortableExecutableReference AspNetLatestComponents { get; } = AspNetLatest.References.MicrosoftAspNetCoreComponents;
|
||||
public static PortableExecutableReference AspNetLatestRazor { get; } = AspNetLatest.References.MicrosoftAspNetCoreRazor;
|
||||
public static ImmutableArray<PortableExecutableReference> NetLatestAll { get; } = NetLatest.References.All;
|
||||
public static PortableExecutableReference NetLatestSystemRuntime { get; } = NetLatest.References.SystemRuntime;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Razor.Test.Common;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
using Xunit;
|
||||
|
@ -58,6 +59,8 @@ 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.
|
||||
public static CSharpCompilation Create(Assembly assembly, SyntaxTree syntaxTree = null)
|
||||
{
|
||||
IEnumerable<SyntaxTree> syntaxTrees = null;
|
||||
|
@ -80,6 +83,19 @@ public static class TestCompilation
|
|||
return compilation;
|
||||
}
|
||||
|
||||
public static CSharpCompilation Create(IEnumerable<SyntaxTree> syntaxTrees, IEnumerable<MetadataReference> references)
|
||||
{
|
||||
var compilation = CSharpCompilation.Create(
|
||||
AssemblyName,
|
||||
syntaxTrees,
|
||||
[..references, ..ReferenceUtil.AspNetLatestAll],
|
||||
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
|
||||
EnsureValidCompilation(compilation);
|
||||
|
||||
return compilation;
|
||||
}
|
||||
|
||||
private static void EnsureValidCompilation(CSharpCompilation compilation)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
|
|
Загрузка…
Ссылка в новой задаче