public void AddDataErrorInfo_AddingACrossPropertyLevelError_ErrorsChangedEventShouldFire() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error, "FirstName", "LastName" ); List<string> propertyNames = new List<string> { "FirstName", "LastName" }; personDto.ErrorsChanged += ( s, e ) => RemoveFromList ( propertyNames, e.PropertyName ); personDto.AddDataErrorInfo ( dataErrorInfo ); Assert.IsTrue ( propertyNames.Count == 0 ); }
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 AddDataErrorInfo_AddingAnObjectLevelError_ErrorsChangedEventShouldFire() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error ); string propertyName = "Dummy"; personDto.ErrorsChanged += ( s, e ) => { propertyName = e.PropertyName; }; personDto.AddDataErrorInfo ( dataErrorInfo ); Assert.IsTrue ( string.IsNullOrEmpty ( propertyName ) ); }
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_RemovingAPropertyLevelError_ErrorsChangedEventShouldFire() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "EntityLevelError", ErrorLevel.Error, "FirstName" ); string propertyName = "Dummy"; personDto.AddDataErrorInfo ( dataErrorInfo ); personDto.ErrorsChanged += ( s, e ) => { propertyName = e.PropertyName; }; personDto.RemoveDataErrorInfo ( "FirstName" ); Assert.AreEqual ( propertyName, "FirstName" ); }
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 ); }
public void ClearAllDataErrorInfo_ErrorsChangedEventShouldFire() { 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" ); HashSet<string> referenceNames = new HashSet<string> { "FirstName", "", "LastName" }; HashSet<string> propertyNames = new HashSet<string> (); personDto.AddDataErrorInfo ( objectDataErrorInfo1 ); personDto.AddDataErrorInfo ( objectDataErrorInfo2 ); personDto.AddDataErrorInfo ( propertyDataErrorInfo ); personDto.AddDataErrorInfo ( crossDataErrorInfo ); personDto.ErrorsChanged += ( s, e ) => propertyNames.Add ( e.PropertyName ); personDto.ClearAllDataErrorInfo (); AssertSetsEqual ( referenceNames, propertyNames ); }