Ejemplo n.º 1
0
        public async Task <IEnumerable <ErrorMessage> > ValidateAsync(ValidationContext context)
        {
            var result = Array.Empty <ErrorMessage>();

            var property = context.WorkItem.Properties.FirstOrDefault(p => p.Name == PropertyDescriptor.Name);

            if (property != null)
            {
                var propertyContext = new PropertyValidationContext(context, property);
                var(success, code, message) = await ValidatePropertyAsync(propertyContext);

                if (!success)
                {
                    result = new ErrorMessage[] {
                        new ErrorMessage(Source, code, message, context.WorkItem.ProjectCode, context.WorkItem.Id, property.Name),
                    };
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
 protected virtual Task <(bool success, string code, string message)> ValidatePropertyAsync(PropertyValidationContext context)
 => Task.FromResult(ValidateProperty(context));
Ejemplo n.º 3
0
        protected override (bool success, string code, string message) ValidateProperty(PropertyValidationContext context)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            string code    = string.Empty;
            string message = string.Empty;

            var hasValue = !string.IsNullOrWhiteSpace(context.Property?.Value);

            if (!hasValue)
            {
                code    = string.Empty;
                message = $"Property {PropertyDescriptor.Name} cannot be empty";
            }

            return(hasValue, code, message);
        }
Ejemplo n.º 4
0
        protected override (bool success, string code, string message) ValidateProperty(PropertyValidationContext context)
        {
            var code    = string.Empty;
            var message = string.Empty;

            bool result = true;

            var property = context.Property;

            if (property.DataType == "String")
            {
                property.Value(out string valueAsString);

                int length = valueAsString.Length;

                if (length < ValidatorDescriptor.Min || length > ValidatorDescriptor.Max)
                {
                    code    = string.Empty;
                    message = $"Property {PropertyDescriptor.Name} cannot be empty";

                    result = false;
                }
            }

            return(result, code, message);
        }
Ejemplo n.º 5
0
        protected override async Task <(bool success, string code, string message)> ValidatePropertyAsync(PropertyValidationContext context)
        {
            var success = true;
            var code    = string.Empty;
            var message = string.Empty;

            foreach (var value in MultiValues(PropertyDescriptor, context.Property))
            {
                if (value != Property.NullValue) // null values are not checked against a value provider. MandatoryValidator is used for that.
                {
                    if (!ValueProvider.IsValidEncoding(value))
                    {
                        success = false;
                        code    = string.Empty;
                        message = $"Property {PropertyDescriptor.Name} value '{value}' does not match allowed encoding for ValueProvider '{ValueProvider.GetType().Name}'.";
                    }
                    else
                    {
                        var exists = await ValueProvider.ValueExistsAsync(value);

                        if (!exists)
                        {
                            success = false;
                            code    = string.Empty;
                            message = $"Property {PropertyDescriptor.Name} value '{value}' does not match one of the allowed values.";
                        }
                    }
                }
            }

            return(success, code, message);
        }