public CodeSnippetValidator(ILanguageValidator languageValidator, ITagValidator tagValidator)
 {
     this.RuleFor(x => x.Description).MaximumLength(CodeSnippet.DescriptionMaxLength);
     this.RuleFor(x => x.Description).NotEmpty().WithMessage(RequiredErrorMessage);
     // TODO: decide if we want to add validation logic for the largest size for Code sample (2 GBs).
     this.RuleFor(x => x.CodeSample).NotEmpty().WithMessage(RequiredErrorMessage);
     this.RuleFor(x => x.Language).NotNull().WithMessage("Please select a '{PropertyName}'.");
     this.RuleFor(x => x.Language).SetValidator(languageValidator).When(x => x.Language != null, ApplyConditionTo.CurrentValidator);
     this.RuleForEach(x => x.Tags).SetValidator(tagValidator).When(x => x.Tags != null, ApplyConditionTo.CurrentValidator);
 }
        //Validate LanguageID
        protected virtual ValidationResult ValidateLanguageID(Int16 idLanguage, string languageID)
        {
            ValidationResult validationResult = new ValidationResult(true);

            try
            {
                //Create Validator based on its Key name : 'Keywords.UpdateLanguage'.
                //The validator factory will create the validator object based on its key.
                ILanguageValidator validator = (ILanguageValidator)ValidatorFactory.Create(Keywords.UpdateLanguage);

                //Execute validation process
                validationResult = validator.ValidateLanguageID(idLanguage, languageID);
            }
            catch
            {
                //The program will throw error if the validation object doesn't exist. And the default of validation result is true.
            }
            return(validationResult);
        }
Example #3
0
 public TranslationRequestValidator(ILogger logger, ILanguageValidator languageValidator)
 {
     _languageValidator = languageValidator ?? throw new ArgumentNullException("languageValidator");
     _logger            = logger ?? throw new ArgumentNullException("logger");
 }