Skip to content

Commit 60721d4

Browse files
Add test for BoundAttributDescriptor HashCode (#36679)
1 parent c4f330d commit 60721d4

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Razor/Microsoft.AspNetCore.Razor.Language/src/BoundAttributeDescriptorComparer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public int GetHashCode(BoundAttributeDescriptor descriptor)
6060
hash.Add(descriptor.Kind, StringComparer.Ordinal);
6161
hash.Add(descriptor.Name, StringComparer.Ordinal);
6262
hash.Add(descriptor.IsEditorRequired);
63+
hash.Add(descriptor.TypeName, StringComparer.Ordinal);
64+
hash.Add(descriptor.Documentation, StringComparer.Ordinal);
6365

6466
if (descriptor.BoundAttributeParameters != null)
6567
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Xunit;
5+
6+
namespace Microsoft.AspNetCore.Razor.Language.Test
7+
{
8+
public class BoundAttributeDescriptorTest
9+
{
10+
[Fact]
11+
public void BoundAttributeDescriptor_HashChangesWithType()
12+
{
13+
var expectedPropertyName = "PropertyName";
14+
15+
var tagHelperBuilder = new DefaultTagHelperDescriptorBuilder(TagHelperConventions.DefaultKind, "TestTagHelper", "Test");
16+
_ = tagHelperBuilder.TypeName("TestTagHelper");
17+
18+
var intBuilder = new DefaultBoundAttributeDescriptorBuilder(tagHelperBuilder, TagHelperConventions.DefaultKind);
19+
_ = intBuilder
20+
.Name("test")
21+
.PropertyName(expectedPropertyName)
22+
.TypeName(typeof(int).FullName);
23+
24+
var intDescriptor = intBuilder.Build();
25+
26+
var stringBuilder = new DefaultBoundAttributeDescriptorBuilder(tagHelperBuilder, TagHelperConventions.DefaultKind);
27+
_ = stringBuilder
28+
.Name("test")
29+
.PropertyName(expectedPropertyName)
30+
.TypeName(typeof(string).FullName);
31+
var stringDescriptor = stringBuilder.Build();
32+
33+
Assert.NotEqual(intDescriptor.GetHashCode(), stringDescriptor.GetHashCode());
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)