Example #1
0
        /// <summary>
        /// Gets the messages reported by the specified action to the scope.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="action">The action.</param>
        /// <returns>array of rule messages reported</returns>
        public static RuleMessages GetMessages(string name, Action <IScope> action)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            var messages = RuleMessages.Empty;

            using (var scope = ScopeFactory.ForMessages(name, m => messages = m))
            {
                action(scope);
            }
            return(messages);
        }
        public void Test()
        {
            var Test = 1;

            try
            {
                using (var t = ScopeFactory.ForEnforce(() => Test, Scope.WhenError))
                {
                    ScopeTestHelper.FireErrors(t);
                }
            }
            catch (RuleException ex)
            {
                ScopeTestHelper.ShouldBeClean(ex);
                ScopeTestHelper.ShouldHave(ex, "ErrA");
                ScopeTestHelper.ShouldNotHave(ex, "ErrB", "ErrC");
                throw;
            }
        }
Example #3
0
 /// <summary>
 /// Creates scope that throws <see cref="RuleException"/> as soon as
 /// first message matching <paramref name="predicate"/> is received.
 /// </summary>
 /// <param name="scopeName">Name of the scope.</param>
 /// <param name="predicate">The predicate.</param>
 /// <returns>new scope instance</returns>
 public static IScope ForEnforce(string scopeName, Predicate <RuleLevel> predicate)
 {
     return(ScopeFactory.ForEnforce(scopeName, predicate));
 }
Example #4
0
 /// <summary>
 /// Creates scope that runs full check and then fails with
 /// <see cref="RuleException"/>, if the resulting
 /// <see cref="RuleLevel"/>  matches the <paramref name="predicate"/>
 /// </summary>
 /// <param name="name">The name for the scope.</param>
 /// <param name="predicate">The predicate.</param>
 /// <returns>new scope instance</returns>
 public static IScope ForValidation(string name, Predicate <RuleLevel> predicate)
 {
     return(ScopeFactory.ForValidation(name, predicate));
 }