public void ValidatorShouldUsePropertyMappings() { ValidatorBase validator = GetValidator(); var dictionary = new Dictionary <string, ICollection <string> > { { PropertyToValidate, new List <string> { PropertyToMap } } }; validator.Initialize(new ValidatorContext(new object(), dictionary, null, null, GetServiceProvider())); validator.IsValid.ShouldBeTrue(); validator.UpdateErrors(PropertyToValidate, ValidatorErrors, false); validator.IsValid.ShouldBeFalse(); validator.GetErrors(PropertyToValidate).ShouldBeEmpty(); string[] errors = validator.GetErrors(PropertyToMap).OfType <string>().ToArray(); errors.Length.ShouldEqual(1); errors.Contains(ValidatorError).ShouldBeTrue(); validator.UpdateErrors(PropertyToMap, null, false); validator.GetErrors(PropertyToMap).ShouldBeEmpty(); validator.IsValid.ShouldBeTrue(); }
public void ValidatorShouldUpdateErrors() { ValidatorBase validator = GetValidator(); validator.Initialize(new ValidatorContext(new object(), GetServiceProvider())); validator.UpdateErrors(PropertyToValidate, ValidatorErrors, false); validator.UpdateErrors(PropertyToMap, ValidatorErrors, false); validator.GetErrors(PropertyToValidate).OfType <object>().Single().ShouldEqual(ValidatorError); validator.GetErrors(PropertyToMap).OfType <object>().Single().ShouldEqual(ValidatorError); validator.ClearErrors(); validator.GetErrors(PropertyToValidate).OfType <object>().ShouldBeEmpty(); validator.GetErrors(PropertyToMap).OfType <object>().ShouldBeEmpty(); validator.IsValid.ShouldBeTrue(); }
public void GetErrorsShouldReturnValidatorErrors() { ValidatorBase validator = GetValidator(); validator.Initialize(new ValidatorContext(new object(), GetServiceProvider())); validator.GetErrors(PropertyToValidate).ShouldBeEmpty(); validator.UpdateErrors(PropertyToValidate, ValidatorErrors, false); validator.GetErrors(PropertyToValidate).OfType <object>().Single().ShouldEqual(ValidatorError); validator.UpdateErrors(PropertyToValidate, new object[] { ValidatorError, ValidatorError }, false); var errors = validator.GetErrors(PropertyToValidate).OfType <object>().ToArray(); errors.Length.ShouldEqual(2); errors.All(o => Equals(o, ValidatorError)).ShouldBeTrue(); }
public void ValidatorShouldUseIgnorePropertiesCollection() { ValidatorBase validator = GetValidator(); validator.Initialize(new ValidatorContext(new object(), null, new List <string> { PropertyToValidate }, null, GetServiceProvider())); validator.IsValid.ShouldBeTrue(); validator.UpdateErrors(PropertyToValidate, ValidatorErrors, false); validator.IsValid.ShouldBeTrue(); validator.GetErrors(PropertyToValidate).ShouldBeEmpty(); }
public void GetAllErrorsShouldReturnAllValidatorErrors() { ValidatorBase validator = GetValidator(); validator.Initialize(new ValidatorContext(new object(), GetServiceProvider())); validator.UpdateErrors(PropertyToValidate, ValidatorErrors, false); validator.UpdateErrors(PropertyToMap, ValidatorErrors, false); var allErrors = validator.GetErrors(); allErrors.Count.ShouldEqual(2); allErrors[PropertyToValidate].Single().ShouldEqual(ValidatorError); allErrors[PropertyToMap].Single().ShouldEqual(ValidatorError); }
public virtual void ValidatorShouldClearOldErrorsValidateAll() { ValidatorBase validator = GetValidator(); validator.Initialize(new ValidatorContext(new object(), GetServiceProvider())); validator.UpdateErrors(PropertyToValidate, ValidatorErrors, false); validator.ValidateAsync().Wait(); if (validator is ManualValidator) { var allErrors = validator.GetErrors(); allErrors.Count.ShouldEqual(1); allErrors[PropertyToValidate].Single().ShouldEqual(ValidatorErrors[0]); } else { validator.IsValid.ShouldBeTrue(); } }
public void NotInitializedValidatorShouldThrowErrorTest() { ValidatorBase validator = GetValidator(); ShouldThrow <InvalidOperationException>(() => validator.GetErrors(PropertyToValidate)); }