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); }
public void TestCopy_TestPersonDto_Succeeds() { var personPersonDto = new TestPersonDto { BirthDate = DateTime.Today.AddDays(-1), FirstName = "Donald", LastName = "Duck" }; var phoneDto = new TestPhoneDto { PhoneNumber = "123-456-7890" }; personPersonDto.Phones.Add(phoneDto); var copyPersonDto = personPersonDto.DeepCopy(); Assert.AreEqual(personPersonDto.FirstName, copyPersonDto.FirstName); Assert.AreEqual(personPersonDto.LastName, copyPersonDto.LastName); Assert.AreEqual(personPersonDto.BirthDate, copyPersonDto.BirthDate); Assert.AreEqual(personPersonDto.Phones.Count, copyPersonDto.Phones.Count); Assert.AreNotEqual(personPersonDto.Phones[0].GetHashCode(), copyPersonDto.Phones[0].GetHashCode()); //change the phone number object var newPhoneDto = new TestPhoneDto { PhoneNumber = "987-654-3210" }; personPersonDto.Phones[0] = newPhoneDto; Assert.AreEqual("123-456-7890", copyPersonDto.Phones[0].PhoneNumber); }
public void RaiseErrorsChanged_GivenAnInvalidPropertyName_RaisesPropertyNotFoundException() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; personDto.RaiseErrorsChanged("Dummy"); }
public void RaiseErrorsChanged_GivenAValidPropertyName_ErrorsChangedEventReportsPropertyChange() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; string name = string.Empty; personDto.ErrorsChanged += (s, e) => name = e.PropertyName; personDto.RaiseErrorsChanged("FirstName"); Assert.AreSame(name, "FirstName"); }
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_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_ErrorsChangedEventShouldFire() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo("EntityLevelError", ErrorLevel.Error); string propertyName = "Dummy"; personDto.AddDataErrorInfo(dataErrorInfo); personDto.ErrorsChanged += (s, e) => { propertyName = e.PropertyName; }; personDto.RemoveDataErrorInfo(String.Empty); Assert.IsTrue(string.IsNullOrEmpty(propertyName)); }
public void RemoveDataErrorInfo_RemovingACrossPropertyLevelErrorLastName_GetErrorsShouldReturEmptySet() { var personDto = new TestPersonDto { FirstName = "John", LastName = "Wayne" }; var dataErrorInfo = new DataErrorInfo("PropertyLevelError", ErrorLevel.Error, "FirstName", "LastName"); personDto.AddDataErrorInfo(dataErrorInfo); personDto.RemoveDataErrorInfo("FirstName"); IEnumerable <DataErrorInfo> errors = personDto.GetErrors("LastName") as IEnumerable <DataErrorInfo>; List <DataErrorInfo> returnedList = new List <DataErrorInfo> (errors); Assert.IsTrue(returnedList.Count() == 0); }
RemoveDataErrorInfo_RemovingACrossPropertyLevelError_ErrorsChangedEventShouldFireWhenFirstNameRemoved() { 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.AddDataErrorInfo(dataErrorInfo); personDto.ErrorsChanged += (s, e) => RemoveFromList(propertyNames, e.PropertyName); personDto.RemoveDataErrorInfo("FirstName"); 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 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 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 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); }