Allow null parent tag when calling `GetTagHelpersGivenParent`.

- A `null` parent tag in all of our other API represents "any" parent tag, or in this case "root". Prior to this change we'd expect the caller to do their own verification of the parent and then assume all `TagHelperDescriptor`s are valid; this isn't sufficient because only our code base should have that knowledge.

#1188
This commit is contained in:
N. Taylor Mullen 2017-04-06 16:51:03 -07:00
parent af3cf497a6
commit 96d97f65e9
2 changed files with 20 additions and 5 deletions

View File

@ -138,11 +138,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
throw new ArgumentNullException(nameof(documentContext));
}
if (parentTag == null)
{
throw new ArgumentNullException(nameof(parentTag));
}
var matchingDescriptors = new List<TagHelperDescriptor>();
var descriptors = documentContext?.TagHelpers;
if (descriptors?.Count == 0)

View File

@ -286,6 +286,26 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
Assert.Equal(expectedDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive);
}
[Fact]
public void GetTagHelpersGivenParent_AllowsRootParentTag()
{
// Arrange
var documentDescriptors = new[]
{
ITagHelperDescriptorBuilder.Create("TestType", "TestAssembly")
.TagMatchingRule(rule => rule.RequireTagName("div"))
.Build()
};
var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors);
var service = new DefaultTagHelperFactsService();
// Act
var descriptors = service.GetTagHelpersGivenParent(documentContext, parentTag: null /* root */);
// Assert
Assert.Equal(documentDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive);
}
[Fact]
public void GetTagHelpersGivenParent_AllowsUnspecifiedParentTagHelpers()
{