コード例 #1
0
        public void Validate(ValidationType validationType, string value, bool expected)
        {
            var validator = _dataValidatorFactory.CreateValidator(validationType);

            var result = validator.CheckValue(value);

            Assert.AreEqual(expected, result.IsSuccess);
        }
コード例 #2
0
        public void CreateValidator_ShouldReturnTypeFileNotNullValidatorAsFirstValidator()
        {
            // Act
            var result = _validatorFactory.CreateValidator();

            // Assert
            result.Should().BeOfType <FileNotNullValidator>();
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
        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());
                    }
                }
            }
        }
コード例 #6
0
 /// <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));
 }