Exemple #1
0
        public static void ShouldValidate <T>(this ICommandScope <T> @this, T model, IValidationContext context, bool?shouldExecuteInfo, Action <IValidationContext> callsAssertions)
        {
            @this.Validate(model, context);

            var shouldExecute = !shouldExecuteInfo.HasValue || shouldExecuteInfo.Value;

            Received.InOrder(() =>
            {
                if (shouldExecute)
                {
                    context.EnterPath(Arg.Is(@this.Path));

                    if (@this.ErrorId.HasValue)
                    {
                        context.EnableErrorDetectionMode(Arg.Is(@this.ErrorMode), Arg.Is(@this.ErrorId.Value));
                    }

                    callsAssertions(context);

                    context.LeavePath();
                }
            });

            if (!shouldExecute)
            {
                context.DidNotReceiveWithAnyArgs().EnterPath(default);
Exemple #2
0
        public void Validate(T model, IValidationContext context)
        {
            var shouldExecute = ExecutionCondition?.Invoke(model) ?? true;

            if (!shouldExecute)
            {
                return;
            }

            context.EnterPath(Path);

            if (ErrorId.HasValue)
            {
                context.EnableErrorDetectionMode(ErrorMode, ErrorId.Value);
            }

            RunValidation(model, context);

            context.LeavePath();
        }