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 StringIsNotEmptySpaceRuleIsValid() { string target = "Matt"; StringIsNotEmptySpace rule = new StringIsNotEmptySpace("StringIsNotEmptySpace", "The string cannot be empty space.", target); 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 StringIsNotEmptySpace(RuleName, FailMessage, (string)target); return Rule; }