public void Validate(ValidationType validationType, string value, bool expected) { var validator = _dataValidatorFactory.CreateValidator(validationType); var result = validator.CheckValue(value); Assert.AreEqual(expected, result.IsSuccess); }
public void CreateValidator_ShouldReturnTypeFileNotNullValidatorAsFirstValidator() { // Act var result = _validatorFactory.CreateValidator(); // Assert result.Should().BeOfType <FileNotNullValidator>(); }
public IReadOnlyCollection <InteractiveErrorItem> Validate(Range range, ValidationType validationType) { var validator = validatorFactory.CreateValidator(validationType); var errors = new List <InteractiveErrorItem>(); range.ForEachCell(c => CheckCell(c, validator, errors, range.Worksheet.Name)); return(errors.ToArray()); }
public IActionResult ObterDescricaoV1(DescricaoGet descricaoGet) { IValidator <DescricaoGet> validator = _validatorFactory.CreateValidator <DescricaoGet>(); var validationResult = validator.Validate(descricaoGet); if (!validationResult.IsValid) { return(BadRequest(validationResult)); } try { var mensagem = _evolutionService.ObterDescricaoV1(descricaoGet); return(Ok(mensagem.Descricao)); } catch (CoreException ex) { return(NotFound(ex.Validation)); } }
private void GenerateChildRules(ValidationModel model, Type validatorType, string prefix) { var validators = _validatorFactory.CreateValidator(validatorType); if (validators == null) { return; } foreach (var validatorRule in validators) { var propertyRule = validatorRule as PropertyRule; if (propertyRule?.PropertyName == null) { continue; } var property = _propertyResolver.GetPropertyName(prefix + propertyRule.PropertyName); var field = model.GetOrCreateValidationProperty(property); foreach (var propertyValidator in propertyRule.Validators) { if (_validationRuleFactory.IsSupportedValidator(propertyValidator)) { GenerateSingleRule(field, propertyValidator, propertyRule.Member.DeclaringType, prefix); } else if (_validationRuleFactory.IsChildCollectionValidator(propertyValidator)) { var childCollectionValidator = propertyValidator as ChildValidatorAdaptor; if (childCollectionValidator == null) { return; } GenerateChildRules(model, childCollectionValidator.ValidatorType, property.ToPrefix()); } } } }
/// <summary> /// Initializes a new instance of the <see cref="Validator{T}"/> class. /// </summary> /// <param name="factory">The <see cref="IValidatorFactory"/> used to create the validator.</param> /// <exception cref="ArgumentNullException">Argument <paramref name="factory"/> must not be <c>null</c>.</exception> public Validator(IValidatorFactory factory) { Ensure.Arg.NotNull(factory, nameof(factory)); _validator = factory.CreateValidator(typeof(T)); }