-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix MVC Core tests for CoreCLR GetCustomAttributes consistency #62872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
2752b68
0222c7c
4eabce6
efd8183
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -211,8 +211,14 @@ public void GetMetadataForParameter_SuppliesEmptyAttributes_WhenParameterHasNoAt | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var defaultMetadata = Assert.IsType<DefaultModelMetadata>(metadata); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Not exactly "no attributes" due to SerializableAttribute on object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.IsType<SerializableAttribute>(Assert.Single(defaultMetadata.Attributes.Attributes)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Not exactly "no attributes" due to pseudo-attributes on object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // After CoreCLR consistency fix, object.GetCustomAttributes() returns all pseudo-attributes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(5, defaultMetadata.Attributes.Attributes.Count); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is SerializableAttribute); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is NullableContextAttribute); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is ClassInterfaceAttribute); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is ComVisibleAttribute); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is TypeForwardedFromAttribute); |
Outdated
Copilot
AI
Jul 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using string comparison with GetType().Name for attribute type checking is fragile and could break if the attribute type is renamed or moved to a different namespace. Consider using typeof() comparison or checking if the attribute is assignable from the expected type.
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType() == typeof(NullableContextAttribute)); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType() == typeof(ClassInterfaceAttribute)); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType() == typeof(ComVisibleAttribute)); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType() == typeof(TypeForwardedFromAttribute)); |
Outdated
Copilot
AI
Jul 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using string comparison with GetType().Name for attribute type checking is fragile and could break if the attribute type is renamed or moved to a different namespace. Consider using typeof() comparison or checking if the attribute is assignable from the expected type.
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is NullableContextAttribute); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is ClassInterfaceAttribute); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is ComVisibleAttribute); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is TypeForwardedFromAttribute); |
Outdated
Copilot
AI
Jul 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using string comparison with GetType().Name for attribute type checking is fragile and could break if the attribute type is renamed or moved to a different namespace. Consider using typeof() comparison or checking if the attribute is assignable from the expected type.
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is System.Runtime.CompilerServices.NullableContextAttribute); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is System.Runtime.InteropServices.ClassInterfaceAttribute); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is System.Runtime.InteropServices.ComVisibleAttribute); | |
| Assert.Contains(defaultMetadata.Attributes.Attributes, attr => attr is System.Runtime.CompilerServices.TypeForwardedFromAttribute); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -185,8 +185,14 @@ public void GetAttributesForParameter_NoAttributes() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .GetParameters()[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Not exactly "no attributes" due to SerializableAttribute on object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.IsType<SerializableAttribute>(Assert.Single(attributes.Attributes)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Not exactly "no attributes" due to pseudo-attributes on object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // After CoreCLR consistency fix, object.GetCustomAttributes() returns all pseudo-attributes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(5, attributes.Attributes.Count); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(attributes.Attributes, attr => attr is SerializableAttribute); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == Type.GetType("System.Runtime.CompilerServices.NullableContextAttribute")); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(System.Runtime.InteropServices.ClassInterfaceAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(System.Runtime.InteropServices.ComVisibleAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(System.Runtime.Serialization.TypeForwardedFromAttribute)); |
Outdated
Copilot
AI
Jul 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using string comparison with GetType().Name for attribute type checking is fragile and could break if the attribute type is renamed or moved to a different namespace. Consider using typeof() comparison or checking if the attribute is assignable from the expected type.
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(NullableContextAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(ClassInterfaceAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(ComVisibleAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(TypeForwardedFromAttribute)); |
Outdated
Copilot
AI
Jul 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using string comparison with GetType().Name for attribute type checking is fragile and could break if the attribute type is renamed or moved to a different namespace. Consider using typeof() comparison or checking if the attribute is assignable from the expected type.
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(NullableContextAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(ClassInterfaceAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(ComVisibleAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(TypeForwardedFromAttribute)); |
Outdated
Copilot
AI
Jul 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using string comparison with GetType().Name for attribute type checking is fragile and could break if the attribute type is renamed or moved to a different namespace. Consider using typeof() comparison or checking if the attribute is assignable from the expected type.
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "NullableContextAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ClassInterfaceAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "ComVisibleAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType().Name == "TypeForwardedFromAttribute"); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == Type.GetType("System.Runtime.CompilerServices.NullableContextAttribute")); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(System.Runtime.InteropServices.ClassInterfaceAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(System.Runtime.InteropServices.ComVisibleAttribute)); | |
| Assert.Contains(attributes.Attributes, attr => attr.GetType() == typeof(System.Runtime.CompilerServices.TypeForwardedFromAttribute)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this test be deleted instead? It does not make sense for ASP.NET to test internal implementation details of CoreCLR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but looking at the name of the testcase
GetMetadataForParameter_SuppliesEmptyAttributes_WhenParameterHasNoAttributesandGetAttributesForParameter_NoAttributesthe intent seems to be testing that a parameter with "no attributes" behaves correctly, so in this situation we either could just remove this testscase or Change the test to just verify thatParameterAttributesis empty (thats what I feel is the actual ASP.NET Core concern)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way sounds good to me.