public void ModelBase_ValidationTest2() { using (var verify = new Verify()) { var person = new SimplePerson(); var eventAssert = new PropertyChangedEventTest(verify, person); person.Validate(); Assert.IsTrue(person.HasErrors); eventAssert.ExpectEvent("HasErrors"); var errors = person.GetErrors("FirstName"); Assert.AreEqual(1, errors.Count); person.ClearErrors(); Assert.IsFalse(person.HasErrors); var errors2 = person.GetErrors("FirstName"); Assert.AreEqual(0, errors2.Count); } }
public void ModelBase_BasicValidation() { var person = new SimplePerson(); 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 }