public void TestAddValidationRule_True() { //act var actual = _validationRule.Check("*****@*****.**"); //assert Assert.AreEqual(true, actual); Assert.AreEqual("Value cannot be null", _validationRule.ValidationMessage); }
public void TestAddValidationRule_True() { //act var actual = _validatableObject.Check("*****@*****.**"); //assert Assert.AreEqual(true, actual); Assert.AreEqual("Invalid Email address", _validatableObject.ValidationMessage); }
private static Task <bool> ToTask <T>( this IValidationRule <T> forRule, T target, ConcurrentDictionary <IValidationRule <T>, Task <bool> > tasks, ValidationScope scope, TaskCreationOptions options = TaskCreationOptions.PreferFairness) { // if the rule is inherently capable of async, let it build the task var asyncRule = forRule as AsyncValidationRule <T>; if (asyncRule != null) { return(asyncRule.TaskFor(target, scope)); } // otherwise, build a task from its tree var task = new Task <bool>( () => { var rule = forRule as ValidationRule <T>; // there are preconditions, so each will need its own task, and main task must wait on them all rule?.preconditions .ForEach(pre => tasks.GetOrAdd(rule, _ => pre.ToTask(target, tasks, scope, TaskCreationOptions.AttachedToParent))); using (var innerScope = new ValidationScope(scope)) { return(forRule.Check(target, innerScope)); } }, options); return(task); }