예제 #1
0
 /// <summary> Collects all rule messages associated with the
 /// specified <paramref name="items"/> </summary>
 /// <typeparam name="TItem">The type of the item to run the rules against.</typeparam>
 /// <param name="items">The item to run the rules against.</param>
 /// <param name="name">The name of the scope.</param>
 /// <param name="rules">The rules to execute.</param>
 /// <returns>read-only collection of <see cref="RuleMessage"/></returns>
 public static RuleMessages GetMessagesForMany <TItem>(IEnumerable <TItem> items, string name, params Rule <TItem>[] rules)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     return(SimpleScope.GetMessages(name, scope => scope.ValidateInScope(items, rules)));
 }
        public void Test_Raise_Modifier()
        {
            var levels = new List<RuleLevel>();
            var scope = new SimpleScope("T", (path, level, message) => levels.Add(level)).Raise();

            _levels.ForEach(l => scope.Write(l, "test"));
            Assert.AreEqual(RuleLevel.Error, scope.Level);
            Assert.AreEqual(_levels.Length, levels.Count);

            CollectionAssert.DoesNotContain(levels, RuleLevel.None);
        }
        public void Test_Raise_Modifier()
        {
            var levels = new List <RuleLevel>();
            var scope  = new SimpleScope("T", (path, level, message) => levels.Add(level)).Raise();

            _levels.ForEach(l => scope.Write(l, "test"));
            Assert.AreEqual(RuleLevel.Error, scope.Level);
            Assert.AreEqual(_levels.Length, levels.Count);

            CollectionAssert.DoesNotContain(levels, RuleLevel.None);
        }
예제 #4
0
        /// <summary>
        /// Gets the messages created by action being executed against the scope.
        /// </summary>
        /// <param name="name">The name for the scope.</param>
        /// <param name="scopeAction">The scope action.</param>
        /// <returns>read-only collection of <see cref="RuleMessage"/></returns>
        public static RuleMessages GetMessages([NotNull] string name, [NotNull] Action <IScope> scopeAction)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (scopeAction == null)
            {
                throw new ArgumentNullException("scopeAction");
            }

            return(SimpleScope.GetMessages(name, scopeAction));
        }
        public void Nesting_Works()
        {
            IScope t = new SimpleScope("Test", (path, level, message) =>
                {
                    Assert.AreEqual("Test.Child", path);
                    Assert.AreEqual(RuleLevel.Error, level);
                    Assert.AreEqual("Message", message);
                }, level => { });

            using (var scope = t.Create("Child"))
            {
                scope.Error("Message");
                Assert.AreEqual(RuleLevel.Error, scope.Level);
            }
            Assert.AreEqual(RuleLevel.Error, t.Level);
        }
        public void Nesting_Works()
        {
            IScope t = new SimpleScope("Test", (path, level, message) =>
            {
                Assert.AreEqual("Test.Child", path);
                Assert.AreEqual(RuleLevel.Error, level);
                Assert.AreEqual("Message", message);
            }, level => { });

            using (var scope = t.Create("Child"))
            {
                scope.Error("Message");
                Assert.AreEqual(RuleLevel.Error, scope.Level);
            }
            Assert.AreEqual(RuleLevel.Error, t.Level);
        }
예제 #7
0
 /// <summary> Collects all rule messages associated with the
 /// specified <paramref name="item"/> </summary>
 /// <typeparam name="TItem">The type of the item to run the rules against.</typeparam>
 /// <param name="item">The item to run the rules against.</param>
 /// <param name="rules">The rules to execute.</param>
 /// <returns>read-only collection of <see cref="RuleMessage"/></returns>
 public static RuleMessages GetMessages <TItem>(TItem item, params Rule <TItem>[] rules)
 {
     return(SimpleScope.GetMessages(typeof(TItem).Name, scope => scope.ValidateInScope(item, rules)));
 }