Esempio n. 1
0
        public ICommandScope Build(IScopeBuilderContext context)
        {
            ThrowHelper.NullArgument(context, nameof(context));

            var ruleCommandScope = new RuleCommandScope <T>
            {
                IsValid = _ruleCommand.Predicate
            };

            ruleCommandScope.Path = _path;
            ruleCommandScope.ExecutionCondition = _executionCondition;
            ruleCommandScope.ErrorMode          = _errorsBuilder.Mode;

            if (_errorsBuilder.IsEmpty)
            {
                ruleCommandScope.ErrorId = context.DefaultErrorId;
            }
            else
            {
                var error = _errorsBuilder.Build();

                ruleCommandScope.ErrorId = context.RegisterError(error);
            }

            return(ruleCommandScope);
        }
Esempio n. 2
0
        public void Should_Discover(bool?shouldExecuteInfo, int errorId, object errorModeBoxed, string path)
        {
            var commandScope = new RuleCommandScope <TestClass>();

            commandScope.ExecutionCondition = !shouldExecuteInfo.HasValue
                ? (Predicate <TestClass>)null
                : m =>
            {
                return(shouldExecuteInfo.Value);
            };

            commandScope.ErrorId = errorId;

            commandScope.ErrorMode = (ErrorMode)errorModeBoxed;

            commandScope.Path = path;

            var discoveryContext = Substitute.For <IDiscoveryContext>();

            commandScope.Discover(discoveryContext);

            Received.InOrder(() =>
            {
                discoveryContext.EnterPath(path);
                discoveryContext.AddError(errorId);
                discoveryContext.LeavePath();
            });

            discoveryContext.DidNotReceiveWithAnyArgs().EnterScope <TestClass>(default);