protected override void ValidateSubject(AbstractValidator <EditMessageTemplate> validator) { validator.When(x => _messageTemplate.MessageDeliveryMethod == MessageDeliveryMethod.Email, () => validator.RuleFor(x => x.Subject) .NotEmpty() .WithMessage(MessagingValidationError.Required)); validator.When(x => _messageTemplate.MessageDeliveryMethod == MessageDeliveryMethod.Sms, () => validator.RuleFor(x => x.Subject) .Must(string.IsNullOrWhiteSpace) .WithMessage(MessagingValidationError.SubjectNotApplicable)); }
public static void ProductIdValidator <T>(this AbstractValidator <T> validator, IUnitOfWork unitOfWork) where T : IProductId { validator.When(c => c.ProductId.HasValue, () => { validator.RuleFor(c => c.ProductId) .NotEmpty() .MustAsync((productId, _) => unitOfWork.ProductRepository.Exist(productId.Value)) .WithMessage(command => "{PropertyName} does not exist"); }); }
static void AddAwsAccountRules(AbstractValidator <DeploymentActionValidationContext> validator) { bool AwsAccountSelected(DeploymentActionValidationContext a) { return(a.Properties.ContainsKey(TerraformSpecialVariables.Action.Terraform.ManagedAccount) && a.Properties[TerraformSpecialVariables.Action.Terraform.ManagedAccount] == TerraformSpecialVariables.AwsAccount); } bool ChosenToAssumeRole(DeploymentActionValidationContext a) { return(a.Properties.ContainsKey(TerraformSpecialVariables.Action.Aws.AssumeRole) && bool.TrueString.Equals(a.Properties[TerraformSpecialVariables.Action.Aws.AssumeRole], StringComparison.OrdinalIgnoreCase)); } bool ChosenToUseInstanceRole(DeploymentActionValidationContext a) { return(a.Properties.ContainsKey(TerraformSpecialVariables.Action.Aws.UseInstanceRole) && bool.TrueString.Equals(a.Properties[TerraformSpecialVariables.Action.Aws.UseInstanceRole], StringComparison.OrdinalIgnoreCase)); } validator.When(x => AwsAccountSelected(x) && ChosenToAssumeRole(x), () => { validator.RuleFor(a => a.Properties) .MustHaveProperty(TerraformSpecialVariables.Action.Aws.AssumedRoleArn, "Please provide the assumed role ARN."); validator.RuleFor(a => a.Properties) .MustHaveProperty(TerraformSpecialVariables.Action.Aws.AssumedRoleSession, "Please provide the assumed role session name."); }); validator.RuleFor(a => a.Properties) .MustHaveProperty(TerraformSpecialVariables.Action.Aws.AccountVariable, "Please specify an AWS account variable.") .When(x => AwsAccountSelected(x) && !ChosenToUseInstanceRole(x)); validator.RuleFor(a => a.Properties) .MustHaveProperty(TerraformSpecialVariables.Action.Aws.AwsRegion, "Please specify the AWS region.") .When(AwsAccountSelected); }