public void EditableObjectModelBase_MultiFieldValidation() { var person = new EditablePerson(); person.FirstName = "Tom"; person.LastName = "Tom"; var errors = person.GetErrors("FirstName"); Assert.AreEqual(1, errors.Count); Assert.IsTrue(errors[0].MemberNames.Contains("FirstName")); Assert.IsFalse(string.IsNullOrEmpty(errors[0].ErrorMessage)); errors = person.GetErrors("LastName"); Assert.AreEqual(1, errors.Count); Assert.IsTrue(errors[0].MemberNames.Contains("LastName")); Assert.IsFalse(string.IsNullOrEmpty(errors[0].ErrorMessage)); errors = person.GetErrors(); Assert.AreEqual(1, errors.Count); Assert.IsTrue(errors[0].MemberNames.Contains("FirstName")); Assert.IsTrue(errors[0].MemberNames.Contains("LastName")); Assert.IsFalse(string.IsNullOrEmpty(errors[0].ErrorMessage)); #if !WINDOWS_UWP var interfacePerson = (IDataErrorInfo)person; Assert.IsTrue(!string.IsNullOrEmpty(interfacePerson.Error)); Assert.IsTrue(!string.IsNullOrEmpty(interfacePerson["FirstName"])); Assert.IsTrue(!string.IsNullOrEmpty(interfacePerson["LastName"])); #endif }
public void EditableObjectModelBase_ValidationTest() { var person = new EditablePerson(); person.Validate(); Assert.IsTrue(person.HasErrors); var errors = person.GetErrors("FirstName"); Assert.AreEqual(1, errors.Count); person.FirstName = "John"; Assert.IsFalse(person.HasErrors); var errors2 = person.GetErrors("FirstName"); Assert.AreEqual(0, errors2.Count); }
public void EditableObjectModelBase_BasicValidation() { var person = new EditablePerson(); Assert.IsFalse(person.HasErrors); var errors = person.GetErrors(); Assert.AreEqual(0, errors.Count); errors = person.GetErrors(""); Assert.AreEqual(0, errors.Count); errors = person.GetErrors(null); Assert.AreEqual(0, errors.Count); person.Validate(); Assert.IsTrue(person.HasErrors); errors = person.GetErrors(); Assert.AreEqual(0, errors.Count); errors = person.GetErrors("FirstName"); Assert.AreEqual(1, errors.Count); Assert.AreEqual("FirstName", errors[0].MemberNames.First()); Assert.IsFalse(string.IsNullOrEmpty(errors[0].ErrorMessage)); #if !WINDOWS_UWP var interfacePerson = (IDataErrorInfo)person; Assert.IsFalse(!string.IsNullOrEmpty(interfacePerson.Error)); Assert.IsTrue(!string.IsNullOrEmpty(interfacePerson["FirstName"])); #endif person.FirstName = "Tom"; Assert.IsFalse(person.HasErrors); errors = person.GetErrors(); Assert.AreEqual(0, errors.Count); errors = person.GetErrors("FirstName"); Assert.AreEqual(0, errors.Count); #if !WINDOWS_UWP Assert.IsFalse(!string.IsNullOrEmpty(interfacePerson.Error)); Assert.IsFalse(!string.IsNullOrEmpty(interfacePerson["FirstName"])); #endif }