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; } }
/// <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)); }