public void Validation_Method_Invalid_Bad_Params_Throws() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = { "LongerThan5Chars", 2.0 }; // legal params ExceptionHelper.ExpectValidationException(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "The field FirstParameterDisplayName must be a string with a maximum length of 5.", typeof(StringLengthAttribute), "LongerThan5Chars"); }
// Method level validator public static ValidationResult IsValTestMethodValid(object vtcObject, ValidationContext context) { ValidationResult validationResult = null; ValTestClass vtc = vtcObject as ValTestClass; bool result = vtc != null && vtc._failMethod == false; if (!result) { validationResult = new ValidationResult("-" + context.DisplayName); } return(validationResult ?? ValidationResult.Success); }
public void Validation_Method_Invalid_Good_Params_Throws() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = { "hello", 2.0 }; // legal params vtc._failMethod = true; // tells validation method below to fail the IsValid ExceptionHelper.ExpectValidationException(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "-MethodDisplayName", typeof(CustomValidationAttribute), vtc); }
public void Validation_Method_Valid_No_Parameters() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = null; bool isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithNoParameters", context, parameters, null); Assert.IsTrue(isValid); List<ValidationResult> output = new List<ValidationResult>(); isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithNoParameters", context, parameters, output); Assert.IsTrue(isValid); Assert.AreEqual(0, output.Count); }
// Cross-field validation -- 2 properties must be non-null and equal public static ValidationResult IsValTestValid(object vtcObject, ValidationContext context) { ValidationResult validationResult = null; ValTestClass vtc = vtcObject as ValTestClass; bool result = vtc != null && vtc.RequiredProperty != null && vtc.StringLengthProperty != null && vtc.StringLengthProperty.Equals(vtc.RequiredProperty, StringComparison.Ordinal); if (!result) { validationResult = new ValidationResult("!" + context.DisplayName); } return(validationResult ?? ValidationResult.Success); }
public void Validation_Method_Valid_No_Parameters() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = null; bool isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithNoParameters", context, parameters, null); Assert.IsTrue(isValid); List <ValidationResult> output = new List <ValidationResult>(); isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithNoParameters", context, parameters, output); Assert.IsTrue(isValid); Assert.AreEqual(0, output.Count); }
public void Validation_Method_Invalid_No_Params() { ValTestClass vtc = new ValTestClass(); vtc._failMethod = true; // forces failure ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); ExceptionHelper.ExpectException <MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, null, null); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters' accepting zero parameters could not be found."); ExceptionHelper.ExpectException <MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, null, new List <ValidationResult>()); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters' accepting zero parameters could not be found."); }
public void Validation_Method_Invalid_Null_Required_Nullable() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); string message = "The doubleParam field is required."; object[] parameters = { null }; // param is nullable but marked [Required] ExceptionHelper.ExpectValidationException(delegate { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithRequiredNullableParameter", context, parameters, null); }, message, typeof(RequiredAttribute), parameters[0]); List <ValidationResult> output = new List <ValidationResult>(); bool isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithRequiredNullableParameter", context, parameters, output); Assert.IsFalse(isValid); Assert.AreEqual(1, output.Count); UnitTestHelper.AssertListContains(output, message); }
public void Validation_Fail_Method_Null_ValueType() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = { "xxx", null }; // 2nd param should be double // IsValid entry point ExceptionHelper.ExpectException <MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters('System.String', null)' could not be found. Parameter count: 2."); // Validate entry point ExceptionHelper.ExpectException <MissingMethodException>(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters('System.String', null)' could not be found. Parameter count: 2."); }
public void Validation_Method_Invalid_Null_Params() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = null; // actually requires 2 params // IsValid entry point ExceptionHelper.ExpectException <MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters' accepting zero parameters could not be found."); // Validate entry point ExceptionHelper.ExpectException <MissingMethodException>(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters' accepting zero parameters could not be found."); }
public void Validation_Method_Invalid_Bad_Params() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); string message = "The field FirstParameterDisplayName must be a string with a maximum length of 5."; object[] parameters = { "LongerThan5Chars", 2.0 }; // legal params ExceptionHelper.ExpectValidationException(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, message, typeof(StringLengthAttribute), parameters[0]); List <ValidationResult> output = new List <ValidationResult>(); bool isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, output); Assert.IsFalse(isValid); Assert.AreEqual(1, output.Count); UnitTestHelper.AssertListContains(output, message); }
public void Validation_Fail_Method_Too_Many_Params() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = { "xxx", 2.0, 5 }; // actually requires 2 params // IsValid entry point ExceptionHelper.ExpectException <MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters('System.String', 'System.Double', 'System.Int32')' could not be found. Parameter count: 3."); // Validate entry point ExceptionHelper.ExpectException <MissingMethodException>(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters('System.String', 'System.Double', 'System.Int32')' could not be found. Parameter count: 3."); }
public void Validation_Method_Errors_Must_Match_Expected_Method_Description() { ValTestClass instance = new ValTestClass() { _failMethod = true }; ValidationContext context = new ValidationContext(instance, null, null); MethodInfo method = typeof(ValTestClass).GetMethod("MethodWithNoParameters"); List <ValidationResult> results = new List <ValidationResult>(); ExceptionHelper.ExpectException <ValidationException>(delegate { ValidationUtilities.ValidateMethodCall("MethodWithNoParameters", context, null); }, "-MethodWithNoParameters"); bool result = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithNoParameters", context, null, results); Assert.AreEqual(1, results.Count); Assert.AreEqual("-MethodWithNoParameters", results[0].ErrorMessage); }
public void Validation_Method_Invalid_Good_Params() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); string message = "-MethodDisplayName"; vtc._failMethod = true; // tells validation method below to fail the IsValid object[] parameters = { "hello", 2.0 }; // legal params ExceptionHelper.ExpectValidationException(delegate { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, message, typeof(CustomValidationAttribute), vtc); List<ValidationResult> output = new List<ValidationResult>(); bool isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, output); Assert.IsFalse(isValid); Assert.AreEqual(1, output.Count); UnitTestHelper.AssertListContains(output, message); // hyphen means it came from default formatter }
public void Validation_Method_Invalid_Good_Params() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); string message = "-MethodDisplayName"; vtc._failMethod = true; // tells validation method below to fail the IsValid object[] parameters = { "hello", 2.0 }; // legal params ExceptionHelper.ExpectValidationException(delegate { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, message, typeof(CustomValidationAttribute), vtc); List <ValidationResult> output = new List <ValidationResult>(); bool isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, output); Assert.IsFalse(isValid); Assert.AreEqual(1, output.Count); UnitTestHelper.AssertListContains(output, message); // hyphen means it came from default formatter }
public void Validation_Method_Invalid_Bad_Params() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); string message = "The field FirstParameterDisplayName must be a string with a maximum length of 5."; object[] parameters = { "LongerThan5Chars", 2.0 }; // legal params ExceptionHelper.ExpectValidationException(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, message, typeof(StringLengthAttribute), parameters[0]); List<ValidationResult> output = new List<ValidationResult>(); bool isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, output); Assert.IsFalse(isValid); Assert.AreEqual(1, output.Count); UnitTestHelper.AssertListContains(output, message); }
public void Validation_Method_Invalid_Good_Params_Throws() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = { "hello", 2.0 }; // legal params vtc._failMethod = true; // tells validation method below to fail the IsValid ExceptionHelper.ExpectValidationException(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "-MethodDisplayName", typeof(CustomValidationAttribute), vtc); }
public void Validation_Method_Invalid_Bad_Params_Throws() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = { "LongerThan5Chars", 2.0 }; // legal params ExceptionHelper.ExpectValidationException(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "The field FirstParameterDisplayName must be a string with a maximum length of 5.", typeof(StringLengthAttribute), "LongerThan5Chars"); }
public void Validation_Method_Errors_Must_Match_Expected_Method_Description() { ValTestClass instance = new ValTestClass() { _failMethod = true }; ValidationContext context = new ValidationContext(instance, null, null); MethodInfo method = typeof(ValTestClass).GetMethod("MethodWithNoParameters"); List<ValidationResult> results = new List<ValidationResult>(); ExceptionHelper.ExpectException<ValidationException>(delegate { ValidationUtilities.ValidateMethodCall("MethodWithNoParameters", context, null); }, "-MethodWithNoParameters"); bool result = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithNoParameters", context, null, results); Assert.AreEqual(1, results.Count); Assert.AreEqual("-MethodWithNoParameters", results[0].ErrorMessage); }
public void Validation_Fail_Method_Too_Many_Params() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = { "xxx", 2.0, 5 }; // actually requires 2 params // IsValid entry point ExceptionHelper.ExpectException<MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters('System.String', 'System.Double', 'System.Int32')' could not be found. Parameter count: 3."); // Validate entry point ExceptionHelper.ExpectException<MissingMethodException>(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters('System.String', 'System.Double', 'System.Int32')' could not be found. Parameter count: 3."); }
public void Validation_Fail_Method_Null_ValueType() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = { "xxx", null }; // 2nd param should be double // IsValid entry point ExceptionHelper.ExpectException<MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters('System.String', null)' could not be found. Parameter count: 2."); // Validate entry point ExceptionHelper.ExpectException<MissingMethodException>(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters('System.String', null)' could not be found. Parameter count: 2."); }
public void Validation_Method_Invalid_Null_Required_Nullable() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); string message = "The doubleParam field is required."; object[] parameters = { null }; // param is nullable but marked [Required] ExceptionHelper.ExpectValidationException(delegate { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithRequiredNullableParameter", context, parameters, null); }, message, typeof(RequiredAttribute), parameters[0]); List<ValidationResult> output = new List<ValidationResult>(); bool isValid = ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithRequiredNullableParameter", context, parameters, output); Assert.IsFalse(isValid); Assert.AreEqual(1, output.Count); UnitTestHelper.AssertListContains(output, message); }
public void Validation_Method_Invalid_No_Params() { ValTestClass vtc = new ValTestClass(); vtc._failMethod = true; // forces failure ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); ExceptionHelper.ExpectException<MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, null, null); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters' accepting zero parameters could not be found."); ExceptionHelper.ExpectException<MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, null, new List<ValidationResult>()); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters' accepting zero parameters could not be found."); }
public void Validation_Method_Invalid_Null_Params() { ValTestClass vtc = new ValTestClass(); ValidationContext context = ValidationUtilities.CreateValidationContext(vtc, null); object[] parameters = null; // actually requires 2 params // IsValid entry point ExceptionHelper.ExpectException<MissingMethodException>(delegate() { ValidationUtilities.TryValidateCustomUpdateMethodCall("MethodWithParameters", context, parameters, null); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters' accepting zero parameters could not be found."); // Validate entry point ExceptionHelper.ExpectException<MissingMethodException>(delegate() { ValidationUtilities.ValidateMethodCall("MethodWithParameters", context, parameters); }, "Method 'OpenRiaServices.DomainServices.Hosting.Test.ValidationUtilitiesTests+ValTestClass.MethodWithParameters' accepting zero parameters could not be found."); }