Example #1
0
        private static Validity GetValidity(
            ValidationStepAction validationStepAction)
        {
            Validity result;

            switch (validationStepAction)
            {
            case ValidationStepAction.StopAsInvalid:
                result = Validity.Invalid;
                break;

            case ValidationStepAction.StopAsNotApplicable:
                result = Validity.NotApplicable;
                break;

            case ValidationStepAction.StopAsValid:
                result = Validity.Valid;
                break;

            case ValidationStepAction.StopToAbort:
                result = Validity.Aborted;
                break;

            default:
                throw new NotSupportedException(Invariant($"This {nameof(ValidationStepAction)} is not supported: {validationStepAction}."));
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationStep"/> class.
        /// </summary>
        /// <param name="operation">The operation to execute whose result determines what to do as specified by <paramref name="trueAction"/> and <paramref name="falseAction"/>.</param>
        /// <param name="stopMessageOp">OPTIONAL operation to execute to get the message that should be emitted when this validation step stops the validation (prevents the next step in the chain from executing).  DEFAULT is to omit this message.</param>
        /// <param name="trueAction">OPTIONAL action to perform when executing <paramref name="operation"/> returns true.  DEFAULT is to move on and execute the next step in the chain.</param>
        /// <param name="falseAction">OPTIONAL action to perform when executing <paramref name="operation"/> returns false.  DEFAULT is to stop the validation (do not execute the next step in the chain) and determine that the subject is invalid.</param>
        /// <param name="details">OPTIONAL details about this validation step.  DEFAULT is to omit any details.</param>
        public ValidationStep(
            IReturningOperation <bool> operation,
            IReturningOperation <string> stopMessageOp = null,
            ValidationStepAction trueAction            = ValidationStepAction.NextStep,
            ValidationStepAction falseAction           = ValidationStepAction.StopAsInvalid,
            string details = null)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            if (trueAction == ValidationStepAction.Unknown)
            {
                throw new ArgumentOutOfRangeException(Invariant($"{nameof(trueAction)} is {nameof(ValidationStepAction.Unknown)}."));
            }

            if (falseAction == ValidationStepAction.Unknown)
            {
                throw new ArgumentOutOfRangeException(Invariant($"{nameof(falseAction)} is {nameof(ValidationStepAction.Unknown)}."));
            }

            this.Operation     = operation;
            this.StopMessageOp = stopMessageOp;
            this.TrueAction    = trueAction;
            this.FalseAction   = falseAction;
            this.Details       = details;
        }
        public ValidationStep DeepCloneWithFalseAction(ValidationStepAction falseAction)
        {
            var result = new ValidationStep(
                this.Operation?.DeepClone(),
                this.StopMessageOp?.DeepClone(),
                this.TrueAction.DeepClone(),
                falseAction,
                this.Details?.DeepClone());

            return(result);
        }