diff --git a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperDescriptorFactory.cs b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperDescriptorFactory.cs index 4f97df03f1..33495036f1 100644 --- a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperDescriptorFactory.cs +++ b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperDescriptorFactory.cs @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers #if !DNXCORE50 if (designTime) { - typeDesignTimeDescriptor = TagHelperDesignTimeDescriptorFactory.CreateDescriptor(typeInfo.GetType()); + typeDesignTimeDescriptor = TagHelperDesignTimeDescriptorFactory.CreateDescriptor(typeInfo.AsType()); } #endif diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorFactoryTest.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorFactoryTest.cs index 8b0c68c8e2..392f0fac30 100644 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorFactoryTest.cs +++ b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorFactoryTest.cs @@ -16,6 +16,91 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers private static readonly string AssemblyName = typeof(TagHelperDescriptorFactoryTest).GetTypeInfo().Assembly.GetName().Name; + // TagHelperDesignTimeDescriptors are not created in CoreCLR. +#if !DNXCORE50 + public static TheoryData OutputElementHintData + { + get + { + // tagHelperType, expectedDescriptors + return new TheoryData + { + { + typeof(OutputElementHintTagHelper), + new[] + { + new TagHelperDescriptor( + prefix: string.Empty, + tagName: "output-element-hint", + typeName: typeof(OutputElementHintTagHelper).FullName, + assemblyName: AssemblyName, + attributes: Enumerable.Empty(), + requiredAttributes: Enumerable.Empty(), + designTimeDescriptor: new TagHelperDesignTimeDescriptor( + summary: null, + remarks: null, + outputElementHint: "strong")) + } + }, + { + typeof(MulitpleDescriptorTagHelperWithOutputElementHint), + new[] + { + new TagHelperDescriptor( + prefix: string.Empty, + tagName: "a", + typeName: typeof(MulitpleDescriptorTagHelperWithOutputElementHint).FullName, + assemblyName: AssemblyName, + attributes: Enumerable.Empty(), + requiredAttributes: Enumerable.Empty(), + designTimeDescriptor: new TagHelperDesignTimeDescriptor( + summary: null, + remarks: null, + outputElementHint: "div")), + new TagHelperDescriptor( + prefix: string.Empty, + tagName: "p", + typeName: typeof(MulitpleDescriptorTagHelperWithOutputElementHint).FullName, + assemblyName: AssemblyName, + attributes: Enumerable.Empty(), + requiredAttributes: Enumerable.Empty(), + designTimeDescriptor: new TagHelperDesignTimeDescriptor( + summary: null, + remarks: null, + outputElementHint: "div")) + } + } + }; + } + } + + [Theory] + [MemberData(nameof(OutputElementHintData))] + public void CreateDescriptors_CreatesDesignTimeDescriptorsWithOutputElementHint( + Type tagHelperType, + TagHelperDescriptor[] expectedDescriptors) + { + // Arrange + var errorSink = new ErrorSink(); + + // Act + var descriptors = TagHelperDescriptorFactory.CreateDescriptors( + AssemblyName, + tagHelperType, + designTime: true, + errorSink: errorSink); + + // Assert + Assert.Empty(errorSink.Errors); + + // We don't care about order. Mono returns reflected attributes differently so we need to ensure order + // doesn't matter by sorting. + descriptors = descriptors.OrderBy(descriptor => descriptor.TagName); + + Assert.Equal(expectedDescriptors, descriptors, CaseSensitiveTagHelperDescriptorComparer.Default); + } +#endif + public static TheoryData EditorBrowsableData { get @@ -2134,5 +2219,17 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers private class GenericDictionarySubclass : Dictionary { } + + [OutputElementHint("strong")] + private class OutputElementHintTagHelper : TagHelper + { + } + + [TargetElement("a")] + [TargetElement("p")] + [OutputElementHint("div")] + private class MulitpleDescriptorTagHelperWithOutputElementHint : TagHelper + { + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDesignTimeDescriptorComparer.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDesignTimeDescriptorComparer.cs index 72f25f1e50..cdf958ca93 100644 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDesignTimeDescriptorComparer.cs +++ b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDesignTimeDescriptorComparer.cs @@ -27,7 +27,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers return descriptorX != null && descriptorY != null && string.Equals(descriptorX.Summary, descriptorY.Summary, StringComparison.Ordinal) && - string.Equals(descriptorX.Remarks, descriptorY.Remarks, StringComparison.Ordinal); + string.Equals(descriptorX.Remarks, descriptorY.Remarks, StringComparison.Ordinal) && + string.Equals(descriptorX.OutputElementHint, descriptorY.OutputElementHint, StringComparison.Ordinal); } public int GetHashCode(TagHelperDesignTimeDescriptor descriptor) @@ -36,6 +37,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers .Start() .Add(descriptor.Summary, StringComparer.Ordinal) .Add(descriptor.Remarks, StringComparer.Ordinal) + .Add(descriptor.OutputElementHint, StringComparer.Ordinal) .CombinedHash; } }