Skip to content

Commit 90236e1

Browse files
medhatiwarijkotas
andauthored
Fix MVC Core tests for CoreCLR GetCustomAttributes consistency (#62872)
Co-authored-by: Jan Kotas <[email protected]>
1 parent 3ff4b84 commit 90236e1

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Mvc/Mvc.Core/test/ModelBinding/Metadata/DefaultModelMetadataProviderTest.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,14 @@ public void GetMetadataForParameter_SuppliesEmptyAttributes_WhenParameterHasNoAt
211211
// Assert
212212
var defaultMetadata = Assert.IsType<DefaultModelMetadata>(metadata);
213213

214-
// Not exactly "no attributes" due to SerializableAttribute on object.
215-
Assert.IsType<SerializableAttribute>(Assert.Single(defaultMetadata.Attributes.Attributes));
214+
// The parameter itself has no attributes
215+
Assert.Empty(defaultMetadata.Attributes.ParameterAttributes);
216+
217+
// Type attributes exist (but we don't care what they are - that's runtime implementation detail)
218+
Assert.NotEmpty(defaultMetadata.Attributes.TypeAttributes);
219+
220+
// Combined attributes = ParameterAttributes + TypeAttributes (when parameter has no attributes)
221+
Assert.Equal(defaultMetadata.Attributes.TypeAttributes, defaultMetadata.Attributes.Attributes);
216222
}
217223

218224
[Fact]

src/Mvc/Mvc.Core/test/ModelBinding/Metadata/ModelAttributesTest.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,15 @@ public void GetAttributesForParameter_NoAttributes()
185185
.GetParameters()[0]);
186186

187187
// Assert
188-
// Not exactly "no attributes" due to SerializableAttribute on object.
189-
Assert.IsType<SerializableAttribute>(Assert.Single(attributes.Attributes));
188+
// The parameter itself has no attributes
190189
Assert.Empty(attributes.ParameterAttributes);
191190
Assert.Null(attributes.PropertyAttributes);
192-
Assert.Equal(attributes.Attributes, attributes.TypeAttributes);
191+
192+
// Type attributes exist (but we don't care what they are - that's runtime implementation detail)
193+
Assert.NotEmpty(attributes.TypeAttributes);
194+
195+
// Combined attributes = ParameterAttributes + TypeAttributes (when parameter has no attributes)
196+
Assert.Equal(attributes.TypeAttributes, attributes.Attributes);
193197
}
194198

195199
[Fact]

0 commit comments

Comments
 (0)