public void CanRenderRuleSetAndExitOnFirstFalseEvaluation() { string target = null; ValidationContext context = new ValidationContext(); context.RenderType = RenderType.ExitOnFirstFalseEvaluation; StringIsNotNullEmptyRange compositeRule = new StringIsNotNullEmptyRange("TargetStringIsNotNullEmptyRange", "Target is not valid.", target, 5, 8); compositeRule.Priority = 20; compositeRule.RenderType = RenderType.ExitOnFirstFalseEvaluation; context.Rules.Add(compositeRule); StringIsNotEmptySpace emptySpaceRule = new StringIsNotEmptySpace("TestStringIsNotEmptySpace", "The target cannot be an empty string.", string.Empty); emptySpaceRule.Priority = 10; context.Rules.Add(emptySpaceRule); context.RenderRules(); Assert.IsFalse(context.IsValid); Assert.AreEqual(context.ExceptionResults.Count, 1); }
public void StringIsNotNullEmptyRangeRuleIsValid() { int maxLength = 10; int minLength = 1; object target = "Matt"; StringIsNotNullEmptyRange rule = new StringIsNotNullEmptyRange("StringIsNotNullEmptyRange", "The string cannot be null or empty - must be within specified range.", target, minLength, maxLength); Result result = rule.Execute(); Assert.IsTrue(result.IsValid); Assert.IsNotNullOrEmpty(result.Message); Assert.IsNotNull(result.RulePolicy); Assert.AreEqual(result.RulePolicy.Severity, Severity.Exception); }
/// <summary> /// Creates the rule. /// </summary> /// <param name="target"> </param> /// <returns> </returns> public override RulePolicy CreateRule(object target) { Rule = new StringIsNotNullEmptyRange(RuleName, FailMessage, target, minLength, maxLength); return Rule; }