/// <summary> /// Tries the add data error info. /// </summary> /// <param name="dataErrorInfo">The data error info.</param> public void TryAddDataErrorInfo(DataErrorInfo dataErrorInfo) { if (!DataErrorInfoCollection.Contains(dataErrorInfo)) { AddDataErrorInfo(dataErrorInfo); } }
public void AddDataErrorInfo_AddsPropertyLevelError_Succeeds() { var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "PropertyLevelError", ErrorLevel.Error, "FirstName" ); personDto.AddDataErrorInfo ( dataErrorInfo ); IList referenceCollection = new ArrayList { dataErrorInfo }; CollectionAssert.AreEqual ( referenceCollection, personDto.DataErrorInfoCollection.ToList () ); }
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 ); }
/// <summary> /// Adds the data error info. /// </summary> /// <param name="dataErrorInfo"> /// The data error info. /// </param> public void AddDataErrorInfo(DataErrorInfo dataErrorInfo) { if (dataErrorInfo.DataErrorInfoType != DataErrorInfoType.ObjectLevel) { foreach (var propertyName in dataErrorInfo.Properties) { ValidatePropertyExists(propertyName); } } _dataErrorInfoCollection.Add(dataErrorInfo); ReportErrorsChanged(dataErrorInfo); }
/// <summary> /// Reports when errors have changed. /// </summary> /// <param name="dataErrorInfo">Error Info.</param> partial void ReportErrorsChanged(DataErrorInfo dataErrorInfo) { if (dataErrorInfo.DataErrorInfoType == DataErrorInfoType.ObjectLevel) { ReportErrorsChanged(string.Empty); } else { foreach (var propertyName in dataErrorInfo.Properties) { ReportErrorsChanged(propertyName); } } }
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 ClearAllDataErrorInfo_HasObjectLevelErrorsAndPropertyLevelErrorsAndCrossPropertyLevelErrors_ClearsAllErrors() { var personDto = new PersonDto{ FirstName = "John", LastName = "Wayne" }; var dataErrorInfo1 = new DataErrorInfo("SomeErrorMessage1", ErrorLevel.Error, "FirstName", "LastName"); var dataErrorInfo2 = new DataErrorInfo("SomeErrorMessage2", ErrorLevel.Error); var dataErrorInfo3 = new DataErrorInfo("SomeErrorMessage3", ErrorLevel.Error, "FirstName" ); personDto.AddDataErrorInfo(dataErrorInfo1); personDto.AddDataErrorInfo(dataErrorInfo2); personDto.AddDataErrorInfo(dataErrorInfo3); personDto.ClearAllDataErrorInfo (); Assert.IsTrue(personDto.DataErrorInfoCollection.Count() == 0); }
/// <summary> /// Removes the data error info. /// </summary> /// <param name="dataErrorInfo">The data error info.</param> public void RemoveDataErrorInfo(DataErrorInfo dataErrorInfo) { ISet <string> propertyNames = new HashSet <string> (); _dataErrorInfoCollection.Remove(dataErrorInfo); if (dataErrorInfo.DataErrorInfoType == DataErrorInfoType.ObjectLevel) { propertyNames.Add(string.Empty); } else { foreach (string name in dataErrorInfo.Properties) { propertyNames.Add(name); } } foreach (string reportablePropertyName in propertyNames) { ReportErrorsChanged(reportablePropertyName); } }
public void DataTransferObject_NonExistingCrossProperty_ThrowsPropertyNotFoundException() { var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "NonExistingCrossProperty", ErrorLevel.Error, "FirstName", "Foo" ); personDto.AddDataErrorInfo ( dataErrorInfo ); }
public void AddDataErrorInfo_NonExistingSingleProperty_ThrowsPropertyNotFoundException() { var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "NonExistingProperty", ErrorLevel.Error, "Foo" ); personDto.AddDataErrorInfo ( dataErrorInfo ); }
public void DataErrorInfo_ObjectLevelError_DataErrorInfoTypeIsObjectLevel() { var dataErrorInfo = new DataErrorInfo("ErrorMessage", ErrorLevel.Error); Assert.AreEqual ( dataErrorInfo.DataErrorInfoType, DataErrorInfoType.ObjectLevel ); }
/// <summary> /// Reports when errors have changed. /// </summary> /// <param name="dataErrorInfo">Error Info.</param> partial void ReportErrorsChanged(DataErrorInfo dataErrorInfo) { if ( dataErrorInfo.DataErrorInfoType == DataErrorInfoType.ObjectLevel ) { ReportErrorsChanged ( string.Empty ); } else { foreach ( var propertyName in dataErrorInfo.Properties ) { ReportErrorsChanged ( propertyName ); } } }
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 DataErrorInfo_PropertyLevelWithEmptyPropertyNameError_ThrowsArgumentException() { var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error, "" ); }
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 DataErrorInfo_ObjectLevelError_Succeeds() { var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error ); }
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 ); }
/// <summary> /// Reports the errors changed. /// </summary> /// <param name="dataErrorInfo">The data error info.</param> partial void ReportErrorsChanged(DataErrorInfo dataErrorInfo);
public void DataErrorInfo_PropertyLevelError_DataErrorInfoTypeIsPropertyLevel() { var dataErrorInfo = new DataErrorInfo("ErrorMessage", ErrorLevel.Error, "PropertyName"); Assert.AreEqual(dataErrorInfo.DataErrorInfoType, DataErrorInfoType.PropertyLevel); }
public void DataErrorInfo_PropertyLevelWithNullPropertyNameError_ThrowsArgumentException() { string[] s = new string[] { null }; var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error, s ); }
public void DataErrorInfo_CrossPropertyLevelWithNullPropertyNameError_ThrowsArgumentException() { var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error, "FirstName", "LastName", null ); }
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_HasPropertyLevelAndObjectLevelErrors_RemovesObjectLevelErrors() { var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; var propertyDataErrorInfo = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "FirstName" ); var objectDataErrorInfo = new DataErrorInfo ( "SomeErrorMessage2", ErrorLevel.Error ); personDto.AddDataErrorInfo ( propertyDataErrorInfo ); personDto.AddDataErrorInfo ( objectDataErrorInfo ); personDto.RemoveDataErrorInfo ( "" ); IList referenceCollection = new ArrayList { propertyDataErrorInfo }; CollectionAssert.AreEqual ( referenceCollection, personDto.DataErrorInfoCollection.ToList () ); }
public void DataErrorInfo_PropertyLevelError_Succeeds() { var dataErrorInfo = new DataErrorInfo ( "ErrorMessage", ErrorLevel.Error, "PropertyName" ); }
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 RemoveDataErrorInfo_MoreThanOneObjectLevelError_RemovesObjectLevelErrors() { var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo1 = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error ); var dataErrorInfo2 = new DataErrorInfo ( "SomeErrorMessage2", ErrorLevel.Error ); personDto.AddDataErrorInfo ( dataErrorInfo1 ); personDto.AddDataErrorInfo ( dataErrorInfo2 ); personDto.RemoveDataErrorInfo ( "" ); Assert.IsTrue ( personDto.DataErrorInfoCollection.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 RemoveDataErrorInfo_OnePropertyLevelError_RemovesPropertyLevelError() { var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "FirstName" ); personDto.AddDataErrorInfo ( dataErrorInfo ); personDto.RemoveDataErrorInfo ( "FirstName" ); Assert.IsTrue ( personDto.DataErrorInfoCollection.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_PropertyLevelErrorAndCrossPropertyLevelError_RemovesAllErrorsWithSamePropertyName() { var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo1 = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "FirstName" ); var dataErrorInfo2 = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "FirstName", "LastName" ); var dataErrorInfo3 = new DataErrorInfo ( "SomeErrorMessage1", ErrorLevel.Error, "LastName" ); personDto.AddDataErrorInfo ( dataErrorInfo1 ); personDto.AddDataErrorInfo ( dataErrorInfo2 ); personDto.AddDataErrorInfo ( dataErrorInfo3 ); personDto.RemoveDataErrorInfo ( "FirstName" ); IList referenceCollection = new ArrayList { dataErrorInfo3 }; CollectionAssert.AreEqual ( referenceCollection, personDto.DataErrorInfoCollection.ToList () ); }
public void RemoveDataErrorInfo_ProvidedAnEmptyProperty_RemovesObjectLevelErrors() { var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "SomeErrorMessage", ErrorLevel.Error ); personDto.AddDataErrorInfo ( dataErrorInfo ); personDto.RemoveDataErrorInfo ( "" ); Assert.IsTrue ( personDto.DataErrorInfoCollection.Count() == 0 ); }
public void RemoveDataErrorInfo_ProvidedANonExistentProperty_ThrowAPropertyNotFoundException() { var personDto = new PersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo ( "SomeErrorMessage", ErrorLevel.Error ); personDto.AddDataErrorInfo ( dataErrorInfo ); personDto.RemoveDataErrorInfo ( "Foo" ); Assert.IsTrue ( personDto.DataErrorInfoCollection.Count() == 0 ); }
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 ); }
/// <summary> /// Tries the add data error info. /// </summary> /// <param name="dataErrorInfo">The data error info.</param> public void TryAddDataErrorInfo ( DataErrorInfo dataErrorInfo ) { if ( !DataErrorInfoCollection.Contains ( dataErrorInfo ) ) { AddDataErrorInfo ( dataErrorInfo ); } }