@@ -262,6 +262,42 @@ public void Test_ObservableValidator_ValidateProperty()
262262 Assert . IsFalse ( model . HasErrors ) ;
263263 }
264264
265+ [ TestCategory ( "Mvvm" ) ]
266+ [ TestMethod ]
267+ public void Test_ObservableValidator_ClearErrors ( )
268+ {
269+ var model = new Person ( ) ;
270+ var events = new List < DataErrorsChangedEventArgs > ( ) ;
271+
272+ model . ErrorsChanged += ( s , e ) => events . Add ( e ) ;
273+
274+ model . Age = - 2 ;
275+
276+ Assert . IsTrue ( model . HasErrors ) ;
277+ Assert . IsTrue ( model . GetErrors ( nameof ( Person . Age ) ) . Any ( ) ) ;
278+
279+ model . ClearErrors ( nameof ( Person . Age ) ) ;
280+
281+ Assert . IsFalse ( model . HasErrors ) ;
282+ Assert . IsTrue ( events . Count == 2 ) ;
283+
284+ model . Age = 200 ;
285+ model . Name = "Bo" ;
286+ events . Clear ( ) ;
287+
288+ Assert . IsTrue ( model . HasErrors ) ;
289+ Assert . IsTrue ( model . GetErrors ( nameof ( Person . Age ) ) . Any ( ) ) ;
290+ Assert . IsTrue ( model . GetErrors ( nameof ( Person . Name ) ) . Any ( ) ) ;
291+
292+ model . ClearErrors ( null ) ;
293+ Assert . IsFalse ( model . HasErrors ) ;
294+ Assert . IsFalse ( model . GetErrors ( nameof ( Person . Age ) ) . Any ( ) ) ;
295+ Assert . IsFalse ( model . GetErrors ( nameof ( Person . Name ) ) . Any ( ) ) ;
296+ Assert . IsTrue ( events . Count == 2 ) ;
297+ Assert . IsTrue ( events [ 0 ] . PropertyName == nameof ( Person . Age ) ) ;
298+ Assert . IsTrue ( events [ 1 ] . PropertyName == nameof ( Person . Name ) ) ;
299+ }
300+
265301 public class Person : ObservableValidator
266302 {
267303 private string name ;
@@ -288,6 +324,11 @@ public int Age
288324 get => this . age ;
289325 set => SetProperty ( ref this . age , value , true ) ;
290326 }
327+
328+ public new void ClearErrors ( string propertyName )
329+ {
330+ base . ClearErrors ( propertyName ) ;
331+ }
291332 }
292333
293334 /// <summary>
0 commit comments