public void CreateExample(Example example) { //VALIDATE, throws error if not valid _valueValidator.Validate(example.value); //DO DATA ACCESS CALLS _exampleDataAccessor.CreateExample(example); //RETURN return; }
public void HasTrailingSpacesAndItsNotAllowed() { var result = ValueValidator.Validate("myvalue ", 1, (x, y) => { return(ValidationResponse.Success); }); Assert.IsFalse(result.IsValid); Assert.AreEqual("Unexpected trailing space, Value \"myvalue \" in Column 1.", result.ValidationErrors[0]); }
public void VerifyThatDateParameterTypeValidatesValue() { ValidationResult result; result = ValueValidator.Validate(this.dateParameterType, "-"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.dateParameterType, "1976-08-20"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.dateParameterType, "some text"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.AreEqual("some text is not a valid Date, valid dates are specified in ISO 8601 YYYY-MM-DD", result.Message); result = ValueValidator.Validate(this.dateParameterType, "2012-13-13"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.AreEqual("2012-13-13 is not a valid Date, valid dates are specified in ISO 8601 YYYY-MM-DD", result.Message); var date = new DateTime(2002, 12, 1); result = ValueValidator.Validate(this.dateParameterType, date); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); var dateTime = new DateTime(2002, 12, 1, 1, 0, 1); result = ValueValidator.Validate(this.dateParameterType, dateTime); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.IsNotEmpty(result.Message); }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Validate(object entity) { foreach (var _memberDescriptor in PropertyDescriptors) { var _isRequired = _memberDescriptor.ActionDescriptors.IsDeclared(x => x.IsRequired && x.PropertyDirection.HasFlag(DbQueryPropertyDirections.Input)); if (_isRequired) { var _value = _memberDescriptor.GetValue(entity); if (!ValueValidator.Validate(_value)) { if (null != Failed) { var _message = string.Format("The '{0}' property cannot be null.", _memberDescriptor.Name); var _exception = new DbQueryException(_message); Failed(this, new DbQueryFailedEventArgs(_exception)); } } if (null != Validated) { Validated(this, EventArgs.Empty); } } } return(true); }
public void VerifyThatDateParameterTypeValidatesValue_with_Z() { ValidationResult result = ValueValidator.Validate(this.dateParameterType, "1976-08-20Z"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.AreEqual("1976-08-20Z is not a valid Date, valid dates are specified in ISO 8601 YYYY-MM-DD", result.Message); }
public void VerifyThatEnumerationParameterTypeValidatesValue() { ValidationResult result; result = ValueValidator.Validate(this.enumerationParameterType, "-"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.enumerationParameterType, "low"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.enumerationParameterType, "medium"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.enumerationParameterType, "high"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.AreEqual("The test Enumeration Parametertype does not contain the following value definition high, allowed values are: low, medium", result.Message); this.enumerationParameterType.AllowMultiSelect = true; result = ValueValidator.Validate(this.enumerationParameterType, "low | medium"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); }
public void VerifyThatDateTimeParameterTypeValidatesValue() { ValidationResult result; result = ValueValidator.Validate(this.dateTimeParameterType, "-"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.dateTimeParameterType, "2010-01-02T07:59:00Z"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.dateTimeParameterType, "2009-10-23T16:04:23.332+02"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.dateTimeParameterType, "2012-13-13T12:01:01+02"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); var date = new DateTime(2002, 12, 1); result = ValueValidator.Validate(this.dateTimeParameterType, date); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); }
public void VerifyThatSimpleQuantityKindValidatesIntegerNumberSet() { ValidationResult result; this.ratioScale.NumberSet = NumberSetKind.INTEGER_NUMBER_SET; string stringValue = "-13"; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, stringValue); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); int intValue = -13; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, intValue); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); double intdoubleValue = -13d; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, intdoubleValue); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); double doubleValue = -13.001d; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, doubleValue); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.IsNotEmpty(result.Message); }
public void MinimumLengthNotMet() { var result = ValueValidator.Validate("123", 1, (x, y) => { return(ValidationResponse.Success); }, minLength: 4); Assert.IsFalse(result.IsValid); Assert.AreEqual("Minimum length 4 not met, Value \"123\" in Column 1.", result.ValidationErrors[0]); }
public void MaximumLengthExceeded() { var result = ValueValidator.Validate("123", 1, (x, y) => { return(ValidationResponse.Success); }, maxLength: 2); Assert.IsFalse(result.IsValid); Assert.AreEqual("Maximum length 2 exceeded, Value \"123\" in Column 1.", result.ValidationErrors[0]); }
public void VerifyThatBooleanParameterTypeValidatesValue() { ValidationResult result; result = ValueValidator.Validate(this.booleanParameterType, "-"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, true); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, false); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, 0); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, 1); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, -1); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.IsNotEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, "True"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, "False"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, "1"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, "0"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, "TRUE"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, "FALSE"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, "Falsch"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.AreEqual("Falsch is not a valid boolean, valid values are: -,true,false,True,False,1,0", result.Message); result = ValueValidator.Validate(this.booleanParameterType, "-1"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.AreEqual("-1 is not a valid boolean, valid values are: -,true,false,True,False,1,0", result.Message); }
public void VerifyThatSimpleQuantityKindValidatesNonDefaultValue() { ValidationResult result; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, "13"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); }
public void VerifyThatTextParameterTypeValidatesValue() { ValidationResult result; result = ValueValidator.Validate(this.textParameterType, "-"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); }
public void ValidateEmptyValueAndItsAllowed() { var result1 = ValueValidator.Validate("", 1, (x, y) => { return(ValidationResponse.Success); }, allowEmptyValue: true); var result2 = ValueValidator.Validate(null, 1, (x, y) => { return(ValidationResponse.Success); }, allowEmptyValue: true); Assert.IsTrue(result1.IsValid); Assert.IsTrue(result2.IsValid); }
public void VerifyThatSimpleQuantityKindInValidatesRealCommaSeparator() { ValidationResult result; this.ratioScale.NumberSet = NumberSetKind.REAL_NUMBER_SET; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, "131,1"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.IsNotEmpty(result.Message); }
/// <summary> /// Gets a value indicating whether the object is null or default. /// </summary> /// <param name="obj"></param> /// <param name="ignoreZero"></param> /// <returns></returns> public static bool IsNullOrDefault(object obj, bool ignoreZero = false) { if (null != obj) { return(!ValueValidator.Validate(obj, ignoreZero)); } return(true); }
public void VerifyThatSimpleQuantityKindValidatesInvalidValue() { ValidationResult result; this.ratioScale.NumberSet = NumberSetKind.REAL_NUMBER_SET; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, "a"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.AreEqual("String:\"a\" is not a member of the REAL NUMBER SET", result.Message); }
public void ValidateEmptyValueAndItsNotAllowed() { var result1 = ValueValidator.Validate("", 1, (x, y) => { return(ValidationResponse.Success); }); var result2 = ValueValidator.Validate(null, 1, (x, y) => { return(ValidationResponse.Success); }); Assert.IsFalse(result1.IsValid); Assert.IsFalse(result2.IsValid); Assert.AreEqual("Unexpected empty value, Value \"\" in Column 1.", result1.ValidationErrors[0]); Assert.AreEqual("Unexpected empty value, Value \"\" in Column 1.", result2.ValidationErrors[0]); }
public void ElementWaitForTimeoutTest5() { var element = new ElementWrapper(new MockIWebElement(), browser); element.WaitFor((elm) => { var valueValidator = new ValueValidator("asdasdasdasd"); var v = new OperationResultValidator(); var result = valueValidator.Validate(elm); v.Validate <UnexpectedElementException>(result); }, 2000, "test timeouted", checkInterval: 100); }
public void VerifyThatSimpleQuantityKindValidatesRealWithFrenchCulture() { var testCulture = new CultureInfo("fr-FR"); Thread.CurrentThread.CurrentCulture = testCulture; ValidationResult result; this.ratioScale.NumberSet = NumberSetKind.REAL_NUMBER_SET; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, "13.1e1"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); }
public void VerifyThatWithNumberFormatInfoSimpleQuantityKindValidatesRealCommaSeparator() { var excelNumberFormatInfo = new NumberFormatInfo { NumberDecimalSeparator = ",", NumberGroupSeparator = ".", }; ValidationResult result; this.ratioScale.NumberSet = NumberSetKind.REAL_NUMBER_SET; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, "131,1", excelNumberFormatInfo); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); }
public void VerifyThatBooleanValidatesWithFrenchCulture() { var testCulture = new CultureInfo("fr-FR"); Thread.CurrentThread.CurrentCulture = testCulture; ValidationResult result; result = ValueValidator.Validate(this.booleanParameterType, "-"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.booleanParameterType, "True"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); }
static void Main(string[] args) { Console.WriteLine("Give me a width of new rectangle: "); string width = Console.ReadLine(); double w = ValueValidator.Validate(width); Console.WriteLine("and height: "); string height = Console.ReadLine(); double h = ValueValidator.Validate(height); Rectangle rectangle = new Rectangle(); rectangle.SetObjectDetails(w, h); rectangle.ShowObjectInfo(); Console.ReadLine(); }
public void VerifyThatTimeOfDayParameterTypeValidatesValue() { ValidationResult result; result = ValueValidator.Validate(this.timeOfDayParameterType, "-"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.timeOfDayParameterType, "10:15:49"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.timeOfDayParameterType, "17:49:30.453Z"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.timeOfDayParameterType, "17:49:30.453+01:00"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.timeOfDayParameterType, "17:49:30.453+01"); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); result = ValueValidator.Validate(this.timeOfDayParameterType, "17:49:30.453Z+01:00"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.IsNotEmpty(result.Message); result = ValueValidator.Validate(this.timeOfDayParameterType, "25:23"); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.AreEqual("25:23 is not a valid Time of Day, for valid Time Of Day formats see http://www.w3.org/TR/xmlschema-2/#time.", result.Message); DateTime dateTime; var isDateTime = DateTime.TryParse("10:15:49", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind | DateTimeStyles.NoCurrentDateDefault, out dateTime); result = ValueValidator.Validate(this.timeOfDayParameterType, dateTime); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); result = ValueValidator.Validate(this.timeOfDayParameterType, false); Assert.AreEqual(ValidationResultKind.Invalid, result.ResultKind); Assert.IsNotEmpty(result.Message); }
public void VerifyThatSimpleQuantityKindValidatesRealNumberSet() { ValidationResult result; this.ratioScale.NumberSet = NumberSetKind.REAL_NUMBER_SET; string stringValue = "13.1e1"; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, stringValue); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); double doubleValue = 13d; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, doubleValue); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); int intValue = -13; result = ValueValidator.Validate(this.simpleQuantityKind, this.ratioScale, intValue); Assert.AreEqual(ValidationResultKind.Valid, result.ResultKind); Assert.IsEmpty(result.Message); }
public void MinimumLengthMet() { var result = ValueValidator.Validate("123", 1, (x, y) => { return(ValidationResponse.Success); }, minLength: 3); Assert.IsTrue(result.IsValid); }
public void MaximumLengthNotExceeded() { var result = ValueValidator.Validate("123", 1, (x, y) => { return(ValidationResponse.Success); }, maxLength: 3); Assert.IsTrue(result.IsValid); }
public void HasTrailingSpacesAndItsAllowed() { var result = ValueValidator.Validate("myvalue ", 1, (x, y) => { return(ValidationResponse.Success); }, allowTrailingSpaces: true); Assert.IsTrue(result.IsValid); }