public void Clear_SinglePropViaGroupLeavingOneBad_ErrorsUpdated() { // Let's pretend these are the values our properties are currently bound to from our View ToName.Value = "XX"; // bad Rating.Value = 0; // bad var testClassInstance = new TestClass { ToName = ToName.Value, Rating = Rating.Value }; _ = Validator.Validate(testClassInstance).ApplyResultsTo(ValidatableProps); Assert.IsFalse(ValidatableProps.AreValid); Assert.AreEqual(5, ValidatableProps.Errors.Count); Assert.IsFalse(Rating.IsValid); Assert.AreEqual(1, Rating.Errors.Count); ValidatableProps.Clear(forClassPropertyNames: nameof(TestClass.ToName)); Assert.AreEqual("XX", ToName.Value); Assert.IsTrue(ToName.IsValid); Assert.IsEmpty(ToName.Errors); Assert.IsEmpty(ToName.FirstError); Assert.IsFalse(Rating.IsValid); Assert.AreEqual(1, Rating.Errors.Count); Assert.IsNotEmpty(Rating.FirstError); Assert.IsFalse(ValidatableProps.AreValid); Assert.AreEqual(3, ValidatableProps.Errors.Count); // count drops to 3 failed errors only ValidatableProps.Clear(onlyValidation: false); Assert.IsEmpty(ToName.Value); Assert.IsNull(Rating.Value); }
public void ApplyResultsToThenClear_MultipleProps_ResultAccuracy() { // Let's pretend these are the values our properties are currently bound to from our View FromEmail.Value = "LOL_I_AM_NOT_AN_EMAIL!"; // bad ToName.Value = "X"; // bad MessageHtml.Value = "NOPE"; // bad Rating.Value = 5; // good var testClassInstance = new TestClass { FromEmail = FromEmail.Value, ToName = ToName.Value, MessageHtml = MessageHtml.Value, Rating = Rating.Value }; var result = Validator.Validate(testClassInstance).ApplyResultsTo(ValidatableProps); Assert.IsFalse(result.IsValidOverall); Assert.AreEqual(4, result.AllErrors.Count); Assert.IsTrue(result.IsValidForNonSplitErrors); Assert.AreEqual(0, result.NonSplitErrors.Count); Assert.IsFalse(ValidatableProps.AreValid); Assert.AreEqual(4, ValidatableProps.Errors.Count); Assert.IsFalse(FromEmail.IsValid); Assert.AreEqual(1, FromEmail.Errors.Count); Assert.IsFalse(ToName.IsValid); Assert.AreEqual(2, ToName.Errors.Count); Assert.IsFalse(MessageHtml.IsValid); Assert.AreEqual(1, MessageHtml.Errors.Count); // only 1 error expected because of CascadeMode set to StopOnFirstFailure Assert.IsTrue(Rating.IsValid); Assert.AreEqual(0, Rating.Errors.Count); ValidatableProps.Clear(); Assert.IsTrue(ValidatableProps.AreValid); Assert.IsEmpty(ValidatableProps.Errors); Assert.IsEmpty(ValidatableProps.FirstError); Assert.AreEqual("LOL_I_AM_NOT_AN_EMAIL!", FromEmail.Value); Assert.IsTrue(FromEmail.IsValid); Assert.IsEmpty(FromEmail.Errors); Assert.IsEmpty(FromEmail.FirstError); Assert.AreEqual("X", ToName.Value); Assert.IsTrue(ToName.IsValid); Assert.IsEmpty(ToName.Errors); Assert.IsEmpty(ToName.FirstError); Assert.AreEqual("NOPE", MessageHtml.Value); Assert.IsTrue(MessageHtml.IsValid); Assert.IsEmpty(MessageHtml.Errors); Assert.IsEmpty(MessageHtml.FirstError); Assert.AreEqual(5, Rating.Value); Assert.IsTrue(Rating.IsValid); Assert.IsEmpty(Rating.Errors); Assert.IsEmpty(Rating.FirstError); ValidatableProps.Clear(onlyValidation: false); Assert.IsEmpty(FromEmail.Value); Assert.IsEmpty(ToName.Value); Assert.IsEmpty(MessageHtml.Value); Assert.IsNull(Rating.Value); }