Rename TagHelperDescriptorProvider => TagHelperBinder.
- Moved the type out of the Legacy namespace. - Renamed the types method to `GetBinding` since `TagHelper` is now inferred. - Updated test names to reflect new method/class name. - Updated product code variables to reflect new naming (provider => binder). #1289
This commit is contained in:
parent
a570139b08
commit
774aebaa01
|
|
@ -39,17 +39,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
private readonly string _tagHelperPrefix;
|
private readonly string _tagHelperPrefix;
|
||||||
private readonly List<KeyValuePair<string, string>> _htmlAttributeTracker;
|
private readonly List<KeyValuePair<string, string>> _htmlAttributeTracker;
|
||||||
private readonly StringBuilder _attributeValueBuilder;
|
private readonly StringBuilder _attributeValueBuilder;
|
||||||
private readonly TagHelperDescriptorProvider _provider;
|
private readonly TagHelperBinder _tagHelperBinder;
|
||||||
private readonly Stack<TagBlockTracker> _trackerStack;
|
private readonly Stack<TagBlockTracker> _trackerStack;
|
||||||
private readonly Stack<BlockBuilder> _blockStack;
|
private readonly Stack<BlockBuilder> _blockStack;
|
||||||
private TagHelperBlockTracker _currentTagHelperTracker;
|
private TagHelperBlockTracker _currentTagHelperTracker;
|
||||||
private BlockBuilder _currentBlock;
|
private BlockBuilder _currentBlock;
|
||||||
private string _currentParentTagName;
|
private string _currentParentTagName;
|
||||||
|
|
||||||
public TagHelperParseTreeRewriter(string tagHelperPrefix, TagHelperDescriptorProvider provider)
|
public TagHelperParseTreeRewriter(string tagHelperPrefix, IEnumerable<TagHelperDescriptor> descriptors)
|
||||||
{
|
{
|
||||||
_tagHelperPrefix = tagHelperPrefix;
|
_tagHelperPrefix = tagHelperPrefix;
|
||||||
_provider = provider;
|
_tagHelperBinder = new TagHelperBinder(tagHelperPrefix, descriptors);
|
||||||
_trackerStack = new Stack<TagBlockTracker>();
|
_trackerStack = new Stack<TagBlockTracker>();
|
||||||
_blockStack = new Stack<BlockBuilder>();
|
_blockStack = new Stack<BlockBuilder>();
|
||||||
_attributeValueBuilder = new StringBuilder();
|
_attributeValueBuilder = new StringBuilder();
|
||||||
|
|
@ -187,9 +187,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
if (!IsEndTag(tagBlock))
|
if (!IsEndTag(tagBlock))
|
||||||
{
|
{
|
||||||
// We're now in a start tag block, we first need to see if the tag block is a tag helper.
|
// We're now in a start tag block, we first need to see if the tag block is a tag helper.
|
||||||
var providedAttributes = GetAttributeNameValuePairs(tagBlock);
|
var elementAttributes = GetAttributeNameValuePairs(tagBlock);
|
||||||
|
|
||||||
tagHelperBinding = _provider.GetTagHelperBinding(tagName, providedAttributes, _currentParentTagName);
|
tagHelperBinding = _tagHelperBinder.GetBinding(tagName, elementAttributes, _currentParentTagName);
|
||||||
|
|
||||||
// If there aren't any TagHelperDescriptors registered then we aren't a TagHelper
|
// If there aren't any TagHelperDescriptors registered then we aren't a TagHelper
|
||||||
if (tagHelperBinding == null)
|
if (tagHelperBinding == null)
|
||||||
|
|
@ -254,7 +254,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tagHelperBinding = _provider.GetTagHelperBinding(
|
tagHelperBinding = _tagHelperBinder.GetBinding(
|
||||||
tagName,
|
tagName,
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: _currentParentTagName);
|
parentTagName: _currentParentTagName);
|
||||||
|
|
|
||||||
|
|
@ -4,23 +4,24 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.AspNetCore.Razor.Language.Legacy;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enables retrieval of <see cref="TagHelperDescriptor"/>'s.
|
/// Enables retrieval of <see cref="TagHelperBinding"/>'s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class TagHelperDescriptorProvider
|
internal class TagHelperBinder
|
||||||
{
|
{
|
||||||
private IDictionary<string, HashSet<TagHelperDescriptor>> _registrations;
|
private IDictionary<string, HashSet<TagHelperDescriptor>> _registrations;
|
||||||
private readonly string _tagHelperPrefix;
|
private readonly string _tagHelperPrefix;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instantiates a new instance of the <see cref="TagHelperDescriptorProvider"/>.
|
/// Instantiates a new instance of the <see cref="TagHelperBinder"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tagHelperPrefix">The tag helper prefix being used by the document.</param>
|
/// <param name="tagHelperPrefix">The tag helper prefix being used by the document.</param>
|
||||||
/// <param name="descriptors">The descriptors that the <see cref="TagHelperDescriptorProvider"/> will pull from.</param>
|
/// <param name="descriptors">The descriptors that the <see cref="TagHelperBinder"/> will pull from.</param>
|
||||||
public TagHelperDescriptorProvider(string tagHelperPrefix, IEnumerable<TagHelperDescriptor> descriptors)
|
public TagHelperBinder(string tagHelperPrefix, IEnumerable<TagHelperDescriptor> descriptors)
|
||||||
{
|
{
|
||||||
_tagHelperPrefix = tagHelperPrefix;
|
_tagHelperPrefix = tagHelperPrefix;
|
||||||
_registrations = new Dictionary<string, HashSet<TagHelperDescriptor>>(StringComparer.OrdinalIgnoreCase);
|
_registrations = new Dictionary<string, HashSet<TagHelperDescriptor>>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
@ -33,16 +34,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all tag helpers that match the given <paramref name="tagName"/>.
|
/// Gets all tag helpers that match the given HTML tag criteria.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tagName">The name of the HTML tag to match. Providing a '*' tag name
|
/// <param name="tagName">The name of the HTML tag to match. Providing a '*' tag name
|
||||||
/// retrieves catch-all <see cref="TagHelperDescriptor"/>s (descriptors that target every tag).</param>
|
/// retrieves catch-all <see cref="TagHelperDescriptor"/>s (descriptors that target every tag).</param>
|
||||||
/// <param name="attributes">Attributes the HTML element must contain to match.</param>
|
/// <param name="attributes">Attributes on the HTML tag.</param>
|
||||||
/// <param name="parentTagName">The parent tag name of the given <paramref name="tagName"/> tag.</param>
|
/// <param name="parentTagName">The parent tag name of the given <paramref name="tagName"/> tag.</param>
|
||||||
/// <returns><see cref="TagHelperDescriptor"/>s that apply to the given <paramref name="tagName"/>.
|
/// <returns><see cref="TagHelperDescriptor"/>s that apply to the given HTML tag criteria.
|
||||||
/// Will return an empty <see cref="Enumerable" /> if no <see cref="TagHelperDescriptor"/>s are
|
/// Will return <c>null</c> if no <see cref="TagHelperDescriptor"/>s are a match.</returns>
|
||||||
/// found.</returns>
|
public TagHelperBinding GetBinding(
|
||||||
public TagHelperBinding GetTagHelperBinding(
|
|
||||||
string tagName,
|
string tagName,
|
||||||
IEnumerable<KeyValuePair<string, string>> attributes,
|
IEnumerable<KeyValuePair<string, string>> attributes,
|
||||||
string parentTagName)
|
string parentTagName)
|
||||||
|
|
@ -68,8 +68,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(tagHelperPrefix, descriptors);
|
var rewriter = new TagHelperParseTreeRewriter(tagHelperPrefix, descriptors);
|
||||||
var rewriter = new TagHelperParseTreeRewriter(tagHelperPrefix, descriptorProvider);
|
|
||||||
root = rewriter.Rewrite(root, errorSink);
|
root = rewriter.Rewrite(root, errorSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
}
|
}
|
||||||
|
|
||||||
var prefix = documentContext.Prefix;
|
var prefix = documentContext.Prefix;
|
||||||
var provider = new TagHelperDescriptorProvider(prefix, descriptors);
|
var tagHelperBinder = new TagHelperBinder(prefix, descriptors);
|
||||||
var binding = provider.GetTagHelperBinding(tagName, attributes, parentTag);
|
var binding = tagHelperBinder.GetBinding(tagName, attributes, parentTag);
|
||||||
|
|
||||||
return binding;
|
return binding;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -148,10 +148,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TypeName(typeof(string).FullName))
|
.TypeName(typeof(string).FullName))
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData WithoutEndTagElementData
|
public static TheoryData WithoutEndTagElementData
|
||||||
|
|
@ -223,10 +222,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireTagStructure(TagStructure.WithoutEndTag))
|
.RequireTagStructure(TagStructure.WithoutEndTag))
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData TagStructureCompatibilityData
|
public static TheoryData TagStructureCompatibilityData
|
||||||
|
|
@ -328,10 +326,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireTagStructure(structure2))
|
.RequireTagStructure(structure2))
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData MalformedTagHelperAttributeBlockData
|
public static TheoryData MalformedTagHelperAttributeBlockData
|
||||||
|
|
@ -1212,13 +1209,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TypeName(typeof(string).FullName))
|
.TypeName(typeof(string).FullName))
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var providerContext = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(providerContext,
|
EvaluateData(
|
||||||
documentContent,
|
descriptors,
|
||||||
(MarkupBlock)expectedOutput,
|
documentContent,
|
||||||
expectedErrors: Enumerable.Empty<RazorError>());
|
(MarkupBlock)expectedOutput,
|
||||||
|
expectedErrors: Enumerable.Empty<RazorError>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> IncompleteHelperBlockData
|
public static IEnumerable<object[]> IncompleteHelperBlockData
|
||||||
|
|
@ -2245,10 +2242,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TypeName(typeof(string).FullName))
|
.TypeName(typeof(string).FullName))
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> ScriptBlockData
|
public static IEnumerable<object[]> ScriptBlockData
|
||||||
|
|
@ -3935,10 +3931,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TypeName(typeof(int).FullName))
|
.TypeName(typeof(int).FullName))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
var errorSink = new ErrorSink();
|
var errorSink = new ErrorSink();
|
||||||
var parseResult = ParseDocument(documentContent);
|
var parseResult = ParseDocument(documentContent);
|
||||||
var document = parseResult.Root;
|
var document = parseResult.Root;
|
||||||
var parseTreeRewriter = new TagHelperParseTreeRewriter(null, provider: null);
|
var parseTreeRewriter = new TagHelperParseTreeRewriter(null, Enumerable.Empty<TagHelperDescriptor>());
|
||||||
|
|
||||||
// Assert - Guard
|
// Assert - Guard
|
||||||
var rootBlock = Assert.IsType<Block>(document);
|
var rootBlock = Assert.IsType<Block>(document);
|
||||||
|
|
@ -171,10 +171,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TagMatchingRule(rule => rule.RequireTagName("p"))
|
.TagMatchingRule(rule => rule.RequireTagName("p"))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData NestedVoidSelfClosingRequiredParentData
|
public static TheoryData NestedVoidSelfClosingRequiredParentData
|
||||||
|
|
@ -278,10 +277,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TagMatchingRule(rule => rule.RequireTagName("p"))
|
.TagMatchingRule(rule => rule.RequireTagName("p"))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData NestedRequiredParentData
|
public static TheoryData NestedRequiredParentData
|
||||||
|
|
@ -354,10 +352,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TagMatchingRule(rule => rule.RequireTagName("p"))
|
.TagMatchingRule(rule => rule.RequireTagName("p"))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -378,11 +375,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TagMatchingRule(rule => rule.RequireTagName("strong"))
|
.TagMatchingRule(rule => rule.RequireTagName("strong"))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider("th:", descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(
|
EvaluateData(
|
||||||
descriptorProvider,
|
descriptors,
|
||||||
documentContent,
|
documentContent,
|
||||||
expectedOutput,
|
expectedOutput,
|
||||||
expectedErrors: Enumerable.Empty<RazorError>(),
|
expectedErrors: Enumerable.Empty<RazorError>(),
|
||||||
|
|
@ -687,10 +683,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.AllowChildTag("br")
|
.AllowChildTag("br")
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors);
|
EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -727,10 +722,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.AllowChildTag("br")
|
.AllowChildTag("br")
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors);
|
EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -764,10 +758,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireTagStructure(TagStructure.WithoutEndTag))
|
.RequireTagStructure(TagStructure.WithoutEndTag))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -801,10 +794,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireTagStructure(TagStructure.WithoutEndTag))
|
.RequireTagStructure(TagStructure.WithoutEndTag))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData AllowedChildrenData
|
public static TheoryData AllowedChildrenData
|
||||||
|
|
@ -1042,10 +1034,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireTagStructure(TagStructure.WithoutEndTag))
|
.RequireTagStructure(TagStructure.WithoutEndTag))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -1066,7 +1057,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
var expectedOutput = new MarkupBlock(
|
var expectedOutput = new MarkupBlock(
|
||||||
new MarkupTagHelperBlock("p",
|
new MarkupTagHelperBlock("p",
|
||||||
BlockFactory.MarkupTagBlock("</")));
|
BlockFactory.MarkupTagBlock("</")));
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
var expectedErrors = new[]
|
var expectedErrors = new[]
|
||||||
{
|
{
|
||||||
new RazorError(
|
new RazorError(
|
||||||
|
|
@ -1078,7 +1068,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors);
|
EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -1099,7 +1089,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
var expectedOutput = new MarkupBlock(
|
var expectedOutput = new MarkupBlock(
|
||||||
new MarkupTagHelperBlock("th:p",
|
new MarkupTagHelperBlock("th:p",
|
||||||
BlockFactory.MarkupTagBlock("</")));
|
BlockFactory.MarkupTagBlock("</")));
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider("th:", descriptors);
|
|
||||||
var expectedErrors = new[]
|
var expectedErrors = new[]
|
||||||
{
|
{
|
||||||
new RazorError(
|
new RazorError(
|
||||||
|
|
@ -1111,7 +1100,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors, "th:");
|
EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors, "th:");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -1129,10 +1118,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireTagStructure(TagStructure.WithoutEndTag))
|
.RequireTagStructure(TagStructure.WithoutEndTag))
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -1161,10 +1149,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireTagStructure(TagStructure.WithoutEndTag))
|
.RequireTagStructure(TagStructure.WithoutEndTag))
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors: new[] { expectedError });
|
EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new[] { expectedError });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -1200,10 +1187,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireTagStructure(TagStructure.NormalOrSelfClosing))
|
.RequireTagStructure(TagStructure.NormalOrSelfClosing))
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors: new[] { expectedError });
|
EvaluateData(descriptors, documentContent, expectedOutput, expectedErrors: new[] { expectedError });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData RequiredAttributeData
|
public static TheoryData RequiredAttributeData
|
||||||
|
|
@ -1630,10 +1616,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireAttribute(attribute => attribute.Name("catchAll")))
|
.RequireAttribute(attribute => attribute.Name("catchAll")))
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData NestedRequiredAttributeData
|
public static TheoryData NestedRequiredAttributeData
|
||||||
|
|
@ -1884,10 +1869,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireAttribute(attribute => attribute.Name("catchAll")))
|
.RequireAttribute(attribute => attribute.Name("catchAll")))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, expectedErrors: new RazorError[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData MalformedRequiredAttributeData
|
public static TheoryData MalformedRequiredAttributeData
|
||||||
|
|
@ -2100,10 +2084,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireAttribute(attribute => attribute.Name("class")))
|
.RequireAttribute(attribute => attribute.Name("class")))
|
||||||
.Build(),
|
.Build(),
|
||||||
};
|
};
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider(null, descriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(descriptorProvider, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorError[])expectedErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData PrefixedTagHelperBoundData
|
public static TheoryData PrefixedTagHelperBoundData
|
||||||
|
|
@ -2252,12 +2235,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
object expectedOutput,
|
object expectedOutput,
|
||||||
object availableDescriptors)
|
object availableDescriptors)
|
||||||
{
|
{
|
||||||
// Arrange
|
|
||||||
var descriptorProvider = new TagHelperDescriptorProvider("th:", (IEnumerable<TagHelperDescriptor>)availableDescriptors);
|
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
EvaluateData(
|
EvaluateData(
|
||||||
descriptorProvider,
|
(IEnumerable<TagHelperDescriptor>)availableDescriptors,
|
||||||
documentContent,
|
documentContent,
|
||||||
(MarkupBlock)expectedOutput,
|
(MarkupBlock)expectedOutput,
|
||||||
expectedErrors: Enumerable.Empty<RazorError>(),
|
expectedErrors: Enumerable.Empty<RazorError>(),
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
IEnumerable<RazorError> errors,
|
IEnumerable<RazorError> errors,
|
||||||
params string[] tagNames)
|
params string[] tagNames)
|
||||||
{
|
{
|
||||||
var providerContext = BuildProviderContext(tagNames);
|
var descriptors = BuildDescriptors(tagNames);
|
||||||
|
|
||||||
EvaluateData(providerContext, documentContent, expectedOutput, errors);
|
EvaluateData(descriptors, documentContent, expectedOutput, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal TagHelperDescriptorProvider BuildProviderContext(params string[] tagNames)
|
internal IEnumerable<TagHelperDescriptor> BuildDescriptors(params string[] tagNames)
|
||||||
{
|
{
|
||||||
var descriptors = new List<TagHelperDescriptor>();
|
var descriptors = new List<TagHelperDescriptor>();
|
||||||
|
|
||||||
|
|
@ -43,11 +43,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
descriptors.Add(descriptor);
|
descriptors.Add(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TagHelperDescriptorProvider(null, descriptors);
|
return descriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void EvaluateData(
|
internal void EvaluateData(
|
||||||
TagHelperDescriptorProvider provider,
|
IEnumerable<TagHelperDescriptor> descriptors,
|
||||||
string documentContent,
|
string documentContent,
|
||||||
MarkupBlock expectedOutput,
|
MarkupBlock expectedOutput,
|
||||||
IEnumerable<RazorError> expectedErrors,
|
IEnumerable<RazorError> expectedErrors,
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
var syntaxTree = ParseDocument(documentContent);
|
var syntaxTree = ParseDocument(documentContent);
|
||||||
var errorSink = new ErrorSink();
|
var errorSink = new ErrorSink();
|
||||||
var parseTreeRewriter = new TagHelperParseTreeRewriter(tagHelperPrefix, provider);
|
var parseTreeRewriter = new TagHelperParseTreeRewriter(tagHelperPrefix, descriptors);
|
||||||
var actualTree = parseTreeRewriter.Rewrite(syntaxTree.Root, errorSink);
|
var actualTree = parseTreeRewriter.Rewrite(syntaxTree.Root, errorSink);
|
||||||
|
|
||||||
var allErrors = syntaxTree.Diagnostics.Concat(errorSink.Errors.Select(error => RazorDiagnostic.Create(error)));
|
var allErrors = syntaxTree.Diagnostics.Concat(errorSink.Errors.Select(error => RazorDiagnostic.Create(error)));
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
namespace Microsoft.AspNetCore.Razor.Language
|
||||||
{
|
{
|
||||||
public class TagHelperDescriptorProviderTest
|
public class TagHelperBinderTest
|
||||||
{
|
{
|
||||||
public static TheoryData RequiredParentData
|
public static TheoryData RequiredParentData
|
||||||
{
|
{
|
||||||
|
|
@ -67,17 +67,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(RequiredParentData))]
|
[MemberData(nameof(RequiredParentData))]
|
||||||
public void GetTagHelperBinding_ReturnsBindingResultWithDescriptorsParentTags(
|
public void GetBinding_ReturnsBindingResultWithDescriptorsParentTags(
|
||||||
string tagName,
|
string tagName,
|
||||||
string parentTagName,
|
string parentTagName,
|
||||||
object availableDescriptors,
|
object availableDescriptors,
|
||||||
object expectedDescriptors)
|
object expectedDescriptors)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var provider = new TagHelperDescriptorProvider(null, (IEnumerable<TagHelperDescriptor>)availableDescriptors);
|
var tagHelperBinder = new TagHelperBinder(null, (IEnumerable<TagHelperDescriptor>)availableDescriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var bindingResult = provider.GetTagHelperBinding(
|
var bindingResult = tagHelperBinder.GetBinding(
|
||||||
tagName,
|
tagName,
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: parentTagName);
|
parentTagName: parentTagName);
|
||||||
|
|
@ -233,34 +233,34 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(RequiredAttributeData))]
|
[MemberData(nameof(RequiredAttributeData))]
|
||||||
public void GetTagHelperBinding_ReturnsBindingResultDescriptorsWithRequiredAttributes(
|
public void GetBinding_ReturnsBindingResultDescriptorsWithRequiredAttributes(
|
||||||
string tagName,
|
string tagName,
|
||||||
IEnumerable<KeyValuePair<string, string>> providedAttributes,
|
IEnumerable<KeyValuePair<string, string>> providedAttributes,
|
||||||
object availableDescriptors,
|
object availableDescriptors,
|
||||||
object expectedDescriptors)
|
object expectedDescriptors)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var provider = new TagHelperDescriptorProvider(null, (IEnumerable<TagHelperDescriptor>)availableDescriptors);
|
var tagHelperBinder = new TagHelperBinder(null, (IEnumerable<TagHelperDescriptor>)availableDescriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var bindingResult = provider.GetTagHelperBinding(tagName, providedAttributes, parentTagName: "p");
|
var bindingResult = tagHelperBinder.GetBinding(tagName, providedAttributes, parentTagName: "p");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal((IEnumerable<TagHelperDescriptor>)expectedDescriptors, bindingResult?.Descriptors, TagHelperDescriptorComparer.CaseSensitive);
|
Assert.Equal((IEnumerable<TagHelperDescriptor>)expectedDescriptors, bindingResult?.Descriptors, TagHelperDescriptorComparer.CaseSensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetTagHelperBinding_ReturnsNullBindingResultPrefixAsTagName()
|
public void GetBinding_ReturnsNullBindingResultPrefixAsTagName()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var catchAllDescriptor = TagHelperDescriptorBuilder.Create("foo1", "SomeAssembly")
|
var catchAllDescriptor = TagHelperDescriptorBuilder.Create("foo1", "SomeAssembly")
|
||||||
.TagMatchingRule(rule => rule.RequireTagName(TagHelperMatchingConventions.ElementCatchAllName))
|
.TagMatchingRule(rule => rule.RequireTagName(TagHelperMatchingConventions.ElementCatchAllName))
|
||||||
.Build();
|
.Build();
|
||||||
var descriptors = new[] { catchAllDescriptor };
|
var descriptors = new[] { catchAllDescriptor };
|
||||||
var provider = new TagHelperDescriptorProvider("th", descriptors);
|
var tagHelperBinder = new TagHelperBinder("th", descriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var bindingResult = provider.GetTagHelperBinding(
|
var bindingResult = tagHelperBinder.GetBinding(
|
||||||
tagName: "th",
|
tagName: "th",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
|
|
@ -270,21 +270,21 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetTagHelperBinding_ReturnsBindingResultCatchAllDescriptorsForPrefixedTags()
|
public void GetBinding_ReturnsBindingResultCatchAllDescriptorsForPrefixedTags()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var catchAllDescriptor = TagHelperDescriptorBuilder.Create("foo1", "SomeAssembly")
|
var catchAllDescriptor = TagHelperDescriptorBuilder.Create("foo1", "SomeAssembly")
|
||||||
.TagMatchingRule(rule => rule.RequireTagName(TagHelperMatchingConventions.ElementCatchAllName))
|
.TagMatchingRule(rule => rule.RequireTagName(TagHelperMatchingConventions.ElementCatchAllName))
|
||||||
.Build();
|
.Build();
|
||||||
var descriptors = new[] { catchAllDescriptor };
|
var descriptors = new[] { catchAllDescriptor };
|
||||||
var provider = new TagHelperDescriptorProvider("th:", descriptors);
|
var tagHelperBinder = new TagHelperBinder("th:", descriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var bindingResultDiv = provider.GetTagHelperBinding(
|
var bindingResultDiv = tagHelperBinder.GetBinding(
|
||||||
tagName: "th:div",
|
tagName: "th:div",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
var bindingResultSpan = provider.GetTagHelperBinding(
|
var bindingResultSpan = tagHelperBinder.GetBinding(
|
||||||
tagName: "th:span",
|
tagName: "th:span",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
|
|
@ -297,17 +297,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetTagHelperBinding_ReturnsBindingResultDescriptorsForPrefixedTags()
|
public void GetBinding_ReturnsBindingResultDescriptorsForPrefixedTags()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var divDescriptor = TagHelperDescriptorBuilder.Create("foo1", "SomeAssembly")
|
var divDescriptor = TagHelperDescriptorBuilder.Create("foo1", "SomeAssembly")
|
||||||
.TagMatchingRule(rule => rule.RequireTagName("div"))
|
.TagMatchingRule(rule => rule.RequireTagName("div"))
|
||||||
.Build();
|
.Build();
|
||||||
var descriptors = new[] { divDescriptor };
|
var descriptors = new[] { divDescriptor };
|
||||||
var provider = new TagHelperDescriptorProvider("th:", descriptors);
|
var tagHelperBinder = new TagHelperBinder("th:", descriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var bindingResult = provider.GetTagHelperBinding(
|
var bindingResult = tagHelperBinder.GetBinding(
|
||||||
tagName: "th:div",
|
tagName: "th:div",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
|
|
@ -320,17 +320,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("*")]
|
[InlineData("*")]
|
||||||
[InlineData("div")]
|
[InlineData("div")]
|
||||||
public void GetTagHelperBinding_ReturnsNullForUnprefixedTags(string tagName)
|
public void GetBinding_ReturnsNullForUnprefixedTags(string tagName)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var divDescriptor = TagHelperDescriptorBuilder.Create("foo1", "SomeAssembly")
|
var divDescriptor = TagHelperDescriptorBuilder.Create("foo1", "SomeAssembly")
|
||||||
.TagMatchingRule(rule => rule.RequireTagName(tagName))
|
.TagMatchingRule(rule => rule.RequireTagName(tagName))
|
||||||
.Build();
|
.Build();
|
||||||
var descriptors = new[] { divDescriptor };
|
var descriptors = new[] { divDescriptor };
|
||||||
var provider = new TagHelperDescriptorProvider("th:", descriptors);
|
var tagHelperBinder = new TagHelperBinder("th:", descriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var bindingResult = provider.GetTagHelperBinding(
|
var bindingResult = tagHelperBinder.GetBinding(
|
||||||
tagName: "div",
|
tagName: "div",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
|
|
@ -350,10 +350,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TagMatchingRule(rule => rule.RequireTagName("span"))
|
.TagMatchingRule(rule => rule.RequireTagName("span"))
|
||||||
.Build();
|
.Build();
|
||||||
var descriptors = new TagHelperDescriptor[] { divDescriptor, spanDescriptor };
|
var descriptors = new TagHelperDescriptor[] { divDescriptor, spanDescriptor };
|
||||||
var provider = new TagHelperDescriptorProvider(null, descriptors);
|
var tagHelperBinder = new TagHelperBinder(null, descriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var tagHelperBinding = provider.GetTagHelperBinding(
|
var tagHelperBinding = tagHelperBinder.GetBinding(
|
||||||
tagName: "foo",
|
tagName: "foo",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
|
|
@ -376,14 +376,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TagMatchingRule(rule => rule.RequireTagName(TagHelperMatchingConventions.ElementCatchAllName))
|
.TagMatchingRule(rule => rule.RequireTagName(TagHelperMatchingConventions.ElementCatchAllName))
|
||||||
.Build();
|
.Build();
|
||||||
var descriptors = new TagHelperDescriptor[] { divDescriptor, spanDescriptor, catchAllDescriptor };
|
var descriptors = new TagHelperDescriptor[] { divDescriptor, spanDescriptor, catchAllDescriptor };
|
||||||
var provider = new TagHelperDescriptorProvider(null, descriptors);
|
var tagHelperBinder = new TagHelperBinder(null, descriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var divBinding = provider.GetTagHelperBinding(
|
var divBinding = tagHelperBinder.GetBinding(
|
||||||
tagName: "div",
|
tagName: "div",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
var spanBinding = provider.GetTagHelperBinding(
|
var spanBinding = tagHelperBinder.GetBinding(
|
||||||
tagName: "span",
|
tagName: "span",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
|
|
@ -408,10 +408,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.TagMatchingRule(rule => rule.RequireTagName("div"))
|
.TagMatchingRule(rule => rule.RequireTagName("div"))
|
||||||
.Build();
|
.Build();
|
||||||
var descriptors = new TagHelperDescriptor[] { divDescriptor, divDescriptor };
|
var descriptors = new TagHelperDescriptor[] { divDescriptor, divDescriptor };
|
||||||
var provider = new TagHelperDescriptorProvider(null, descriptors);
|
var tagHelperBinder = new TagHelperBinder(null, descriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var bindingResult = provider.GetTagHelperBinding(
|
var bindingResult = tagHelperBinder.GetBinding(
|
||||||
tagName: "div",
|
tagName: "div",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
|
|
@ -422,7 +422,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetTagHelperBinding_DescriptorWithMultipleRules_CorrectlySelectsMatchingRules()
|
public void GetBinding_DescriptorWithMultipleRules_CorrectlySelectsMatchingRules()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var multiRuleDescriptor = TagHelperDescriptorBuilder.Create("foo", "SomeAssembly")
|
var multiRuleDescriptor = TagHelperDescriptorBuilder.Create("foo", "SomeAssembly")
|
||||||
|
|
@ -435,10 +435,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
.RequireTagName("span"))
|
.RequireTagName("span"))
|
||||||
.Build();
|
.Build();
|
||||||
var descriptors = new TagHelperDescriptor[] { multiRuleDescriptor };
|
var descriptors = new TagHelperDescriptor[] { multiRuleDescriptor };
|
||||||
var provider = new TagHelperDescriptorProvider(null, descriptors);
|
var tagHelperBinder = new TagHelperBinder(null, descriptors);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var binding = provider.GetTagHelperBinding(
|
var binding = tagHelperBinder.GetBinding(
|
||||||
tagName: "div",
|
tagName: "div",
|
||||||
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
attributes: Enumerable.Empty<KeyValuePair<string, string>>(),
|
||||||
parentTagName: "p");
|
parentTagName: "p");
|
||||||
Loading…
Reference in New Issue