예제 #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);
예제 #2
0
        protected override void RunValidation(T model, IValidationContext context)
        {
            var i = 0;

            foreach (var item in model)
            {
                context.EnterCollectionItemPath(i);

                context.EnterScope(ScopeId, item);

                context.LeavePath();

                if (context.ShouldFallBack)
                {
                    break;
                }

                ++i;
            }
        }
예제 #3
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();
        }