@@ -290,6 +290,32 @@ public void Test_ObservablePropertyWithValueNamedField_WithValidationAttributesA
290
290
Assert . AreEqual ( errors [ 1 ] . PropertyName , nameof ( ModelWithValuePropertyWithAutomaticValidationWithClassLevelAttribute . Value ) ) ;
291
291
}
292
292
293
+ [ TestMethod ]
294
+ public void Test_ObservablePropertyWithValueNamedField_WithValidationAttributesAndValidation_InheritingClassLevelAttribute ( )
295
+ {
296
+ ModelWithValuePropertyWithAutomaticValidationInheritingClassLevelAttribute model = new ( ) ;
297
+
298
+ List < string ? > propertyNames = new ( ) ;
299
+
300
+ model . PropertyChanged += ( s , e ) => propertyNames . Add ( e . PropertyName ) ;
301
+
302
+ List < DataErrorsChangedEventArgs > errors = new ( ) ;
303
+
304
+ model . ErrorsChanged += ( s , e ) => errors . Add ( e ) ;
305
+
306
+ model . Value2 = "Bo" ;
307
+
308
+ Assert . IsTrue ( model . HasErrors ) ;
309
+ Assert . AreEqual ( errors . Count , 1 ) ;
310
+ Assert . AreEqual ( errors [ 0 ] . PropertyName , nameof ( ModelWithValuePropertyWithAutomaticValidationInheritingClassLevelAttribute . Value2 ) ) ;
311
+
312
+ model . Value2 = "Hello world" ;
313
+
314
+ Assert . IsFalse ( model . HasErrors ) ;
315
+ Assert . AreEqual ( errors . Count , 2 ) ;
316
+ Assert . AreEqual ( errors [ 1 ] . PropertyName , nameof ( ModelWithValuePropertyWithAutomaticValidationInheritingClassLevelAttribute . Value2 ) ) ;
317
+ }
318
+
293
319
// See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4184
294
320
[ TestMethod ]
295
321
public void Test_GeneratedPropertiesWithValidationAttributesOverFields ( )
@@ -1058,6 +1084,14 @@ public partial class ModelWithValuePropertyWithAutomaticValidationWithClassLevel
1058
1084
private string ? value ;
1059
1085
}
1060
1086
1087
+ public partial class ModelWithValuePropertyWithAutomaticValidationInheritingClassLevelAttribute : ModelWithValuePropertyWithAutomaticValidationWithClassLevelAttribute
1088
+ {
1089
+ [ ObservableProperty ]
1090
+ [ Required ]
1091
+ [ MinLength ( 5 ) ]
1092
+ private string ? value2 ;
1093
+ }
1094
+
1061
1095
public partial class ViewModelWithValidatableGeneratedProperties : ObservableValidator
1062
1096
{
1063
1097
[ Required ]
0 commit comments