Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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.

Copy link
Contributor Author

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_WhenParameterHasNoAttributes and GetAttributesForParameter_NoAttributes the 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 that ParameterAttributes is empty (thats what I feel is the actual ASP.NET Core concern)

Copy link
Member

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.

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");
Copy link

Copilot AI Jul 23, 2025

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.

Copy link

Copilot AI Jul 23, 2025

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.

Suggested change
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));

Copilot uses AI. Check for mistakes.

Copy link

Copilot AI Jul 23, 2025

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.

Copy link

Copilot AI Jul 23, 2025

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.

}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link

Copilot AI Jul 23, 2025

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.

Suggested change
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));

Copilot uses AI. Check for mistakes.

Copy link

Copilot AI Jul 23, 2025

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.

Suggested change
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));

Copilot uses AI. Check for mistakes.

Copy link

Copilot AI Jul 23, 2025

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.

Suggested change
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));

Copilot uses AI. Check for mistakes.

Copy link

Copilot AI Jul 23, 2025

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.

Suggested change
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));

Copilot uses AI. Check for mistakes.

Assert.Empty(attributes.ParameterAttributes);
Assert.Null(attributes.PropertyAttributes);
Assert.Equal(attributes.Attributes, attributes.TypeAttributes);
Expand Down
Loading