/// <summary> /// Builds a <see cref="ValidateOp"/>. /// </summary> /// <param name="steps">The individual validation steps/checks.</param> /// <param name="endMessageOp">OPTIONAL operation to execute to get the message that should be emitted when all <paramref name="steps"/> have been evaluated and none have stopped the validation (we've reached the end of the chain). DEFAULT is to omit this message.</param> /// <param name="endValidity">OPTIONAL value that specifies the validity of the subject when all <paramref name="steps"/> have been evaluated and none have stopped the validation (we've reached the end of the chain). DEFAULT is to determine that the subject is valid.</param> /// <returns> /// The operation. /// </returns> public static ValidateOp Validate( this IReadOnlyList <ValidationStep> steps, IReturningOperation <string> endMessageOp = null, Validity endValidity = Validity.Valid) { var validationChain = new ValidationChain(steps, endMessageOp, endValidity); var result = new ValidateOp(validationChain); return(result); }
/// <inheritdoc /> public async Task <ValidationResult> ExecuteAsync( ValidateOp operation) { // NOTE: THIS CODE IS A NEAR DUPLICATE OF THE SYNC METHOD ABOVE; NO GOOD WAY TO D.R.Y. IT OUT if (operation == null) { throw new ArgumentNullException(nameof(operation)); } ValidationResult result = null; var validationChain = operation.ValidationChain; foreach (var validationStep in validationChain.Steps) { var operationResult = await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <bool>(validationStep.Operation); var validationStepAction = operationResult ? validationStep.TrueAction : validationStep.FalseAction; if (validationStepAction == ValidationStepAction.NextStep) { continue; } var validity = GetValidity(validationStepAction); result = new ValidationResult(Op.Const(validity), validationStep.StopMessageOp); break; } if (result == null) { result = new ValidationResult(Op.Const(validationChain.EndValidity), validationChain.EndMessageOp); } return(result); }