public void TagHelperDescriptorCache_TypeNameAffectsHash() { // Arrange var expectedPropertyName = "PropertyName"; var intTagHelperBuilder = new DefaultTagHelperDescriptorBuilder(TagHelperConventions.DefaultKind, "TestTagHelper", "Test"); _ = intTagHelperBuilder.TypeName("TestTagHelper"); intTagHelperBuilder.BoundAttributeDescriptor(intBuilder => intBuilder .Name("test") .PropertyName(expectedPropertyName) .TypeName(typeof(int).FullName) ); var intTagHelper = intTagHelperBuilder.Build(); var stringTagHelperBuilder = new DefaultTagHelperDescriptorBuilder(TagHelperConventions.DefaultKind, "TestTagHelper", "Test"); _ = stringTagHelperBuilder.TypeName("TestTagHelper"); stringTagHelperBuilder.BoundAttributeDescriptor(stringBuilder => stringBuilder .Name("test") .PropertyName(expectedPropertyName) .TypeName(typeof(string).FullName) ); var stringTagHelper = stringTagHelperBuilder.Build(); // Act TagHelperDescriptorCache.Set(intTagHelper.GetHashCode(), intTagHelper); // Assert Assert.False(TagHelperDescriptorCache.TryGetDescriptor(stringTagHelper.GetHashCode(), out var descriptor)); }
public void WriteSetPreallocatedTagHelperProperty_IndexerAttribute_MultipleValues() { // Arrange var extension = new PreallocatedAttributeTargetExtension(); var context = TestCodeRenderingContext.CreateRuntime(); var tagHelperBuilder = new DefaultTagHelperDescriptorBuilder(TagHelperConventions.DefaultKind, "FooTagHelper", "Test"); tagHelperBuilder.TypeName("FooTagHelper"); var builder = new DefaultBoundAttributeDescriptorBuilder(tagHelperBuilder, TagHelperConventions.DefaultKind); builder .Name("Foo") .TypeName("System.Collections.Generic.Dictionary<System.String, System.String>") .AsDictionaryAttribute("pre-", "System.String") .PropertyName("FooProp"); var boundAttribute = builder.Build(); var tagHelper = tagHelperBuilder.Build(); var tagHelperNode = new TagHelperIntermediateNode(); var node1 = new PreallocatedTagHelperPropertyIntermediateNode() { AttributeName = "pre-Bar", FieldName = "__FooTagHelper", VariableName = "_tagHelper0s", BoundAttribute = boundAttribute, IsIndexerNameMatch = true, PropertyName = "FooProp", TagHelper = tagHelper, }; var node2 = new PreallocatedTagHelperPropertyIntermediateNode() { AttributeName = "pre-Foo", FieldName = "__FooTagHelper", VariableName = "_tagHelper1", BoundAttribute = boundAttribute, IsIndexerNameMatch = true, PropertyName = "FooProp", TagHelper = tagHelper, }; tagHelperNode.Children.Add(node1); tagHelperNode.Children.Add(node2); Push(context, tagHelperNode); // Act extension.WriteTagHelperProperty(context, node2); // Assert var csharp = context.CodeWriter.GenerateCode(); Assert.Equal( @"__FooTagHelper.FooProp[""Foo""] = (string)_tagHelper1.Value; __tagHelperExecutionContext.AddTagHelperAttribute(_tagHelper1); ", csharp, ignoreLineEndingDifferences: true); }