Fix `DesignTimeDescriptorFactory.CreateDescriptor` call to properly retrieve type from `TypeInfo`.
- Added `TagHelperDescriptorFactory` level tests to validate correct information is being pased to the `TagHelperDesignTimeDescriptorFactory`. #457
This commit is contained in:
parent
c87dd8d9de
commit
3ab6f56284
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
||||||
#if !DNXCORE50
|
#if !DNXCORE50
|
||||||
if (designTime)
|
if (designTime)
|
||||||
{
|
{
|
||||||
typeDesignTimeDescriptor = TagHelperDesignTimeDescriptorFactory.CreateDescriptor(typeInfo.GetType());
|
typeDesignTimeDescriptor = TagHelperDesignTimeDescriptorFactory.CreateDescriptor(typeInfo.AsType());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,91 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
||||||
private static readonly string AssemblyName =
|
private static readonly string AssemblyName =
|
||||||
typeof(TagHelperDescriptorFactoryTest).GetTypeInfo().Assembly.GetName().Name;
|
typeof(TagHelperDescriptorFactoryTest).GetTypeInfo().Assembly.GetName().Name;
|
||||||
|
|
||||||
|
// TagHelperDesignTimeDescriptors are not created in CoreCLR.
|
||||||
|
#if !DNXCORE50
|
||||||
|
public static TheoryData OutputElementHintData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// tagHelperType, expectedDescriptors
|
||||||
|
return new TheoryData<Type, TagHelperDescriptor[]>
|
||||||
|
{
|
||||||
|
{
|
||||||
|
typeof(OutputElementHintTagHelper),
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
new TagHelperDescriptor(
|
||||||
|
prefix: string.Empty,
|
||||||
|
tagName: "output-element-hint",
|
||||||
|
typeName: typeof(OutputElementHintTagHelper).FullName,
|
||||||
|
assemblyName: AssemblyName,
|
||||||
|
attributes: Enumerable.Empty<TagHelperAttributeDescriptor>(),
|
||||||
|
requiredAttributes: Enumerable.Empty<string>(),
|
||||||
|
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<TagHelperAttributeDescriptor>(),
|
||||||
|
requiredAttributes: Enumerable.Empty<string>(),
|
||||||
|
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<TagHelperAttributeDescriptor>(),
|
||||||
|
requiredAttributes: Enumerable.Empty<string>(),
|
||||||
|
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
|
public static TheoryData EditorBrowsableData
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -2134,5 +2219,17 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
||||||
private class GenericDictionarySubclass<TValue> : Dictionary<string, TValue>
|
private class GenericDictionarySubclass<TValue> : Dictionary<string, TValue>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[OutputElementHint("strong")]
|
||||||
|
private class OutputElementHintTagHelper : TagHelper
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[TargetElement("a")]
|
||||||
|
[TargetElement("p")]
|
||||||
|
[OutputElementHint("div")]
|
||||||
|
private class MulitpleDescriptorTagHelperWithOutputElementHint : TagHelper
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
||||||
return descriptorX != null &&
|
return descriptorX != null &&
|
||||||
descriptorY != null &&
|
descriptorY != null &&
|
||||||
string.Equals(descriptorX.Summary, descriptorY.Summary, StringComparison.Ordinal) &&
|
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)
|
public int GetHashCode(TagHelperDesignTimeDescriptor descriptor)
|
||||||
|
|
@ -36,6 +37,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
||||||
.Start()
|
.Start()
|
||||||
.Add(descriptor.Summary, StringComparer.Ordinal)
|
.Add(descriptor.Summary, StringComparer.Ordinal)
|
||||||
.Add(descriptor.Remarks, StringComparer.Ordinal)
|
.Add(descriptor.Remarks, StringComparer.Ordinal)
|
||||||
|
.Add(descriptor.OutputElementHint, StringComparer.Ordinal)
|
||||||
.CombinedHash;
|
.CombinedHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue