From 2752b68d92beac4010254dea0ae03d5a7581fbe3 Mon Sep 17 00:00:00 2001 From: Medha Tiwari Date: Wed, 23 Jul 2025 07:05:33 +0200 Subject: [PATCH 1/4] Fixing ASP .NET test as discussed here https://github.com/dotnet/runtime/pull/117864 --- .../Metadata/DefaultModelMetadataProviderTest.cs | 10 ++++++++-- .../test/ModelBinding/Metadata/ModelAttributesTest.cs | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs index c4d8bafec62f..cf688c930bd3 100644 --- a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs +++ b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs @@ -211,8 +211,14 @@ public void GetMetadataForParameter_SuppliesEmptyAttributes_WhenParameterHasNoAt // Assert var defaultMetadata = Assert.IsType(metadata); - // Not exactly "no attributes" due to SerializableAttribute on object. - Assert.IsType(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"); } [Fact] diff --git a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs index 73dbd7f6c180..07032eb26069 100644 --- a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs +++ b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs @@ -185,8 +185,14 @@ public void GetAttributesForParameter_NoAttributes() .GetParameters()[0]); // Assert - // Not exactly "no attributes" due to SerializableAttribute on object. - Assert.IsType(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.Empty(attributes.ParameterAttributes); Assert.Null(attributes.PropertyAttributes); Assert.Equal(attributes.Attributes, attributes.TypeAttributes); From 0222c7c4ccf02f2e451e7903b54f14547e9307ac Mon Sep 17 00:00:00 2001 From: Medha Tiwari Date: Wed, 23 Jul 2025 15:44:45 +0200 Subject: [PATCH 2/4] Replace hardcoded attribute count checks and specific attribute type assertions Signed-off-by: Medha Tiwari --- .../Metadata/DefaultModelMetadataProviderTest.cs | 16 ++++++++-------- .../ModelBinding/Metadata/ModelAttributesTest.cs | 16 +++++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs index cf688c930bd3..68c0bc23114b 100644 --- a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs +++ b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs @@ -211,14 +211,14 @@ public void GetMetadataForParameter_SuppliesEmptyAttributes_WhenParameterHasNoAt // Assert var defaultMetadata = Assert.IsType(metadata); - // 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"); + // The parameter itself has no attributes + Assert.Empty(defaultMetadata.Attributes.ParameterAttributes); + + // Type attributes exist (but we don't care what they are - that's CoreCLR's business) + Assert.NotEmpty(defaultMetadata.Attributes.TypeAttributes); + + // Combined attributes = ParameterAttributes + TypeAttributes (when parameter has no attributes) + Assert.Equal(defaultMetadata.Attributes.TypeAttributes, defaultMetadata.Attributes.Attributes); } [Fact] diff --git a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs index 07032eb26069..fdffca770246 100644 --- a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs +++ b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs @@ -185,17 +185,15 @@ public void GetAttributesForParameter_NoAttributes() .GetParameters()[0]); // Assert - // 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"); + // The parameter itself has no attributes Assert.Empty(attributes.ParameterAttributes); Assert.Null(attributes.PropertyAttributes); - Assert.Equal(attributes.Attributes, attributes.TypeAttributes); + + // Type attributes exist (but we don't care what they are - that's CoreCLR's business) + Assert.NotEmpty(attributes.TypeAttributes); + + // Combined attributes = ParameterAttributes + TypeAttributes (when parameter has no attributes) + Assert.Equal(attributes.TypeAttributes, attributes.Attributes); } [Fact] From 4eabce6fbb06a688c78819685389577f3efe44b6 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 23 Jul 2025 06:59:23 -0700 Subject: [PATCH 3/4] Update src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs --- .../ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs index 68c0bc23114b..9b6662d2f15b 100644 --- a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs +++ b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs @@ -214,7 +214,7 @@ public void GetMetadataForParameter_SuppliesEmptyAttributes_WhenParameterHasNoAt // The parameter itself has no attributes Assert.Empty(defaultMetadata.Attributes.ParameterAttributes); - // Type attributes exist (but we don't care what they are - that's CoreCLR's business) + // Type attributes exist (but we don't care what they are - that's runtime implementation detail) Assert.NotEmpty(defaultMetadata.Attributes.TypeAttributes); // Combined attributes = ParameterAttributes + TypeAttributes (when parameter has no attributes) From efd8183477c23619b2feb2fcfb884fff5b2b28d2 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 23 Jul 2025 06:59:58 -0700 Subject: [PATCH 4/4] Update src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs --- .../Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs index fdffca770246..5db7c1f45ece 100644 --- a/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs +++ b/src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs @@ -189,7 +189,7 @@ public void GetAttributesForParameter_NoAttributes() Assert.Empty(attributes.ParameterAttributes); Assert.Null(attributes.PropertyAttributes); - // Type attributes exist (but we don't care what they are - that's CoreCLR's business) + // Type attributes exist (but we don't care what they are - that's runtime implementation detail) Assert.NotEmpty(attributes.TypeAttributes); // Combined attributes = ParameterAttributes + TypeAttributes (when parameter has no attributes)