public void StringifyAttributes_MinimizedTagHelperAttribute() { // Arrange var tagHelper = TagHelperDescriptorBuilder.Create("WithBoundAttribute", "TestAssembly"); tagHelper.TagMatchingRule(rule => rule.TagName = "test"); tagHelper.BindAttribute(attribute => { attribute.Name = "bound"; attribute.SetPropertyName("Bound"); attribute.TypeName = typeof(bool).FullName; }); tagHelper.SetTypeName("WithBoundAttribute"); var codeDocument = DefaultTagHelperCompletionServiceTest.CreateCodeDocument($"@addTagHelper *, TestAssembly{Environment.NewLine}<test bound />", tagHelper.Build()); var syntaxTree = codeDocument.GetSyntaxTree(); var sourceSpan = new SourceSpan(30 + Environment.NewLine.Length, 0); var sourceChangeLocation = new SourceChange(sourceSpan, string.Empty); var startTag = (MarkupTagHelperStartTagSyntax)syntaxTree.Root.LocateOwner(sourceChangeLocation).Parent; // Act var attributes = TagHelperFactsService.StringifyAttributes(startTag.Attributes); // Assert Assert.Collection( attributes, attribute => { Assert.Equal("bound", attribute.Key); Assert.Equal(string.Empty, attribute.Value); }); }
public void StringifyAttributes_IgnoresMiscContent() { // Arrange var codeDocument = DefaultTagHelperCompletionServiceTest.CreateCodeDocument($"@addTagHelper *, TestAssembly{Environment.NewLine}<input unbound @DateTime.Now />", DefaultTagHelpers); var syntaxTree = codeDocument.GetSyntaxTree(); var sourceSpan = new SourceSpan(30 + Environment.NewLine.Length, 0); var sourceChangeLocation = new SourceChange(sourceSpan, string.Empty); var startTag = (MarkupStartTagSyntax)syntaxTree.Root.LocateOwner(sourceChangeLocation).Parent; // Act var attributes = TagHelperFactsService.StringifyAttributes(startTag.Attributes); // Assert Assert.Collection( attributes, attribute => { Assert.Equal("unbound", attribute.Key); Assert.Equal(string.Empty, attribute.Value); }); }