public void FalseScalarExpression() { Inventor tesla = new Inventor(); tesla.Name = "Soltan Gris"; ConditionValidator validator = new ConditionValidator(Expression.Parse("Name == 'Nikola Tesla'"), null); validator.Actions = new ErrorMessageAction[] {new ErrorMessageAction("Wrong name", "InventorValidator") }; IValidationErrors errors = new ValidationErrors(); Assert.IsFalse(validator.Validate(tesla, errors)); Assert.IsFalse(errors.IsEmpty); IList<string> namedErrors = errors.GetResolvedErrors("InventorValidator", new NullMessageSource()); Assert.AreEqual(1, namedErrors.Count); string error = (string) namedErrors[0]; Assert.AreEqual("Wrong name", error); }
public void StraightTrue() { ConditionValidator validator = new ConditionValidator(); validator.Test = Expression.Parse("true"); Assert.IsTrue(validator.Validate(null, new ValidationErrors())); }
static int Validate(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 3) { ConditionValidator obj = (ConditionValidator)LuaScriptMgr.GetNetObjectSelf(L, 1, "ConditionValidator"); ConditionType arg0 = (ConditionType)LuaScriptMgr.GetNetObject(L, 2, typeof(ConditionType)); string arg1 = LuaScriptMgr.GetLuaString(L, 3); bool o = obj.Validate(arg0, arg1); LuaScriptMgr.Push(L, o); return(1); } else if (count == 4) { ConditionValidator obj = (ConditionValidator)LuaScriptMgr.GetNetObjectSelf(L, 1, "ConditionValidator"); List <ConditionType> arg0 = (List <ConditionType>)LuaScriptMgr.GetNetObject(L, 2, typeof(List <ConditionType>)); List <string> arg1 = (List <string>)LuaScriptMgr.GetNetObject(L, 3, typeof(List <string>)); bool arg2 = LuaScriptMgr.GetBoolean(L, 4); bool o = obj.Validate(arg0, arg1, arg2); LuaScriptMgr.Push(L, o); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: ConditionValidator.Validate"); } return(0); }
public void TrueScalarExpression() { Inventor tesla = new Inventor(); tesla.Name = "Nikola Tesla"; ConditionValidator validator = new ConditionValidator(Expression.Parse("Name == 'Nikola Tesla'"), null); Assert.IsTrue(validator.Validate(tesla, new ValidationErrors())); }
public void WhenValidatorIsNotEvaluatedBecauseWhenExpressionReturnsFalse() { ConditionValidator validator = new ConditionValidator(); validator.Test = Expression.Parse("false"); validator.When = Expression.Parse("false"); IValidationErrors errors = new ValidationErrors(); bool valid = validator.Validate(new object(), null, errors); Assert.IsTrue(valid, "Validation should succeed when condition validator is not evaluated."); Assert.AreEqual(0, errors.GetErrors("errors").Count); }
public void FalseScalarExpression() { Inventor tesla = new Inventor(); tesla.Name = "Soltan Gris"; ConditionValidator validator = new ConditionValidator(Expression.Parse("Name == 'Nikola Tesla'"), null); validator.Actions = new ErrorMessageAction[] { new ErrorMessageAction("Wrong name", "InventorValidator") }; IValidationErrors errors = new ValidationErrors(); Assert.IsFalse(validator.Validate(tesla, errors)); Assert.IsFalse(errors.IsEmpty); IList <string> namedErrors = errors.GetResolvedErrors("InventorValidator", new NullMessageSource()); Assert.AreEqual(1, namedErrors.Count); string error = (string)namedErrors[0]; Assert.AreEqual("Wrong name", error); }
public void StraightFalse() { ConditionValidator validator = new ConditionValidator("false", null); Assert.IsFalse(validator.Validate(null, new ValidationErrors())); }
public void ConditionValidatorTest() { var conditionValidator = new ConditionValidator(); var condition = new Condition(); ValidationResults result = conditionValidator.Validate(condition); }