public void AddDataErrorInfo_AddingACrossPropertyLevelError_GetErrorsShouldReturnGivenErrorForLastNameProperty() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "PropertyLevelError", ErrorLevel.Error, "FirstName", "LastName" ); personDto.AddDataErrorInfo ( dataErrorInfo ); IEnumerable<DataErrorInfo> errors = personDto.GetErrors ( "LastName" ) as IEnumerable<DataErrorInfo>; List<DataErrorInfo> returnedList = new List<DataErrorInfo> ( errors ); List<DataErrorInfo> referenceList = new List<DataErrorInfo> { dataErrorInfo }; CollectionAssert.AreEqual ( returnedList, referenceList ); }
public void AddDataErrorInfo_AddingAnObjectLevelError_GetErrorsShouldReturnGivenError() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error ); IEnumerable<DataErrorInfo> errors = new List<DataErrorInfo> (); personDto.ErrorsChanged += ( s, e ) => { errors = personDto.GetErrors ( e.PropertyName ) as IEnumerable<DataErrorInfo>; }; personDto.AddDataErrorInfo ( dataErrorInfo ); List<DataErrorInfo> returnedList = new List<DataErrorInfo> ( errors ); List<DataErrorInfo> referenceList = new List<DataErrorInfo> { dataErrorInfo }; CollectionAssert.AreEqual ( returnedList, referenceList ); }
public void RemoveDataErrorInfo_RemovingAPropertyLevelError_GetErrorsShouldReturnGivenError() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "PropertyLevelError", ErrorLevel.Error, "FirstName" ); personDto.AddDataErrorInfo ( dataErrorInfo ); personDto.RemoveDataErrorInfo ( "FirstName" ); IEnumerable<DataErrorInfo> errors = personDto.GetErrors ( "FirstName" ) as IEnumerable<DataErrorInfo>; List<DataErrorInfo> returnedList = new List<DataErrorInfo> ( errors ); Assert.IsTrue ( returnedList.Count == 0 ); }
public void RemoveDataErrorInfo_RemovingAnObjectLevelError_GetErrorsShouldReturnGivenError() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error ); IEnumerable<DataErrorInfo> errors = new List<DataErrorInfo> (); personDto.AddDataErrorInfo ( dataErrorInfo ); personDto.ErrorsChanged += ( s, e ) => { errors = personDto.GetErrors ( e.PropertyName ) as IEnumerable<DataErrorInfo>; }; personDto.RemoveDataErrorInfo ( String.Empty ); List<DataErrorInfo> returnedList = new List<DataErrorInfo> ( errors ); Assert.IsTrue ( returnedList.Count == 0 ); }
public void GetErrors_WithAPropertyNameButOnlyAnObjectLevelErrorExists_ReturnAnEmptyList() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; DataErrorInfo dataErrorInfo = new DataErrorInfo ( "Error", ErrorLevel.Error ); personDto.AddDataErrorInfo ( dataErrorInfo ); IEnumerable<DataErrorInfo> errors = personDto.GetErrors ( "FirstName" ) as IEnumerable<DataErrorInfo>; IList<DataErrorInfo> errorList = new List<DataErrorInfo> ( errors ); Assert.IsTrue ( errorList.Count() == 0 ); }
public void ClearAllDataErrorInfo_GetErrorsShouldReturnEmptySet() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var objectDataErrorInfo1 = new DataErrorInfo ( "ObjectLevelError1", ErrorLevel.Error ); var objectDataErrorInfo2 = new DataErrorInfo ( "ObjectLevelError2", ErrorLevel.Error ); var propertyDataErrorInfo = new DataErrorInfo ( "PropertyLevelError", ErrorLevel.Error, "FirstName" ); var crossDataErrorInfo = new DataErrorInfo ( "CrossPropertyLevelError", ErrorLevel.Error, "FirstName", "LastName" ); personDto.AddDataErrorInfo ( objectDataErrorInfo1 ); personDto.AddDataErrorInfo ( objectDataErrorInfo2 ); personDto.AddDataErrorInfo ( propertyDataErrorInfo ); personDto.AddDataErrorInfo ( crossDataErrorInfo ); personDto.ClearAllDataErrorInfo (); IEnumerable<DataErrorInfo> errors = personDto.GetErrors ( null ) as IEnumerable<DataErrorInfo>; List<DataErrorInfo> returnedList = new List<DataErrorInfo> ( errors ); Assert.IsTrue ( returnedList.Count () == 0 ); }