public static void Validate_InvalidArguments_ThrowsValidationException(string method, object value, Type exceptionType) { CustomValidationAttribute attribute = new CustomValidationAttribute(typeof(CustomValidator), method); Assert.Throws(exceptionType, () => attribute.Validate(value, s_testValidationContext)); Assert.NotEmpty(attribute.FormatErrorMessage("name")); }
public static void FormatErrorMessage_BadlyFormed_ThrowsInvalidOperationException(Type validatorType, string method) { CustomValidationAttribute attribute = new CustomValidationAttribute(validatorType, method); Assert.Throws<InvalidOperationException>(() => attribute.FormatErrorMessage("name")); }
public void FormatErrorMessage () { var attr = new CustomValidationAttribute (null, null); string msg = null; AssertExtensions.Throws<InvalidOperationException> (() => { // MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage: // System.InvalidOperationException : The CustomValidationAttribute.ValidatorType was not specified. // // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.ThrowIfAttributeNotWellFormed() // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.FormatErrorMessage(String name) // at MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\CustomValidationAttributeTest.cs:line 88 msg = attr.FormatErrorMessage (null); }, "#A1"); attr = new CustomValidationAttribute (typeof (string), null); AssertExtensions.Throws<InvalidOperationException> (() => { // MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage: // System.InvalidOperationException : The CustomValidationAttribute.Method was not specified. // // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.ThrowIfAttributeNotWellFormed() // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.FormatErrorMessage(String name) // at MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\CustomValidationAttributeTest.cs:line 102 msg = attr.FormatErrorMessage (null); }, "#A2"); attr = new CustomValidationAttribute (typeof (string), String.Empty); AssertExtensions.Throws<InvalidOperationException> (() => { // MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage: // System.InvalidOperationException : The CustomValidationAttribute.Method was not specified. // // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.ThrowIfAttributeNotWellFormed() // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.FormatErrorMessage(String name) // at MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\CustomValidationAttributeTest.cs:line 117 msg = attr.FormatErrorMessage (null); }, "#A3"); attr = new CustomValidationAttribute (typeof (string), "NoSuchMethod"); AssertExtensions.Throws<InvalidOperationException> (() => { // MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage: // System.InvalidOperationException : The CustomValidationAttribute method 'NoSuchMethod' does not exist in type 'String' or is not public and static. // // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.ThrowIfAttributeNotWellFormed() // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.FormatErrorMessage(String name) // at MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\CustomValidationAttributeTest.cs:line 126 msg = attr.FormatErrorMessage (null); }, "#A4"); attr = new CustomValidationAttribute (typeof (PrivateValidatorMethodContainer), "MethodOne"); AssertExtensions.Throws<InvalidOperationException> (() => { // MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage: // System.InvalidOperationException : The custom validation type 'PrivateValidatorMethodContainer' must be public. // // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.ThrowIfAttributeNotWellFormed() // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.FormatErrorMessage(String name) // at MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\CustomValidationAttributeTest.cs:line 138 msg = attr.FormatErrorMessage (null); }, "#A5"); attr = new CustomValidationAttribute (typeof (PublicValidatorMethodContainer), "MethodOne"); AssertExtensions.Throws<InvalidOperationException> (() => { // MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage: // System.InvalidOperationException : The CustomValidationAttribute method 'MethodOne' in type 'PublicValidatorMethodContainer' // must return System.ComponentModel.DataAnnotations.ValidationResult. Use System.ComponentModel.DataAnnotations.ValidationResult.Success // to represent success. // // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.ThrowIfAttributeNotWellFormed() // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.FormatErrorMessage(String name) // at MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\CustomValidationAttributeTest.cs:line 150 msg = attr.FormatErrorMessage (null); }, "#A6"); attr = new CustomValidationAttribute (typeof (PublicValidatorMethodContainer), "MethodTwo"); AssertExtensions.Throws<InvalidOperationException> (() => { // MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage: // System.InvalidOperationException : The CustomValidationAttribute method 'MethodTwo' in type 'PublicValidatorMethodContainer' must match the expected signature: public static ValidationResult MethodTwo(object value, ValidationContext context). The value can be strongly typed. The ValidationContext parameter is optional. // // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.ThrowIfAttributeNotWellFormed() // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.FormatErrorMessage(String name) // at MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\CustomValidationAttributeTest.cs:line 163 msg = attr.FormatErrorMessage (null); }, "#A7"); attr = new CustomValidationAttribute (typeof (PublicValidatorMethodContainer), "MethodThree"); msg = attr.FormatErrorMessage (null); Assert.IsNotNull (msg, "#A8-1"); Assert.IsTrue (msg.Length > 0, "#A8-2"); Assert.AreEqual (" is not valid.", msg, "#A8-3"); attr = new CustomValidationAttribute (typeof (PublicValidatorMethodContainer), "MethodFour"); msg = attr.FormatErrorMessage ("test"); Assert.IsNotNull (msg, "#A9-1"); Assert.IsTrue (msg.Length > 0, "#A9-2"); Assert.AreEqual ("test is not valid.", msg, "#A9-3"); attr = new CustomValidationAttribute (typeof (PublicValidatorMethodContainer), "MethodFive"); AssertExtensions.Throws<InvalidOperationException> (() => { // MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage: // System.InvalidOperationException : The CustomValidationAttribute method 'MethodFive' in type 'PublicValidatorMethodContainer' must match the expected signature: public static ValidationResult MethodFive(object value, ValidationContext context). The value can be strongly typed. The ValidationContext parameter is optional. // // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.ThrowIfAttributeNotWellFormed() // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.FormatErrorMessage(String name) // at MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\CustomValidationAttributeTest.cs:line 180 msg = attr.FormatErrorMessage (null); }, "#A10"); attr = new CustomValidationAttribute (typeof (PublicValidatorMethodContainer), "MethodSix"); AssertExtensions.Throws<InvalidOperationException> (() => { // MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage: // System.InvalidOperationException : The CustomValidationAttribute method 'MethodSix' in type 'PublicValidatorMethodContainer' must match the expected signature: public static ValidationResult MethodSix(object value, ValidationContext context). The value can be strongly typed. The ValidationContext parameter is optional. // // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.ThrowIfAttributeNotWellFormed() // at System.ComponentModel.DataAnnotations.CustomValidationAttribute.FormatErrorMessage(String name) // at MonoTests.System.ComponentModel.DataAnnotations.CustomValidationAttributeTest.FormatErrorMessage() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\CustomValidationAttributeTest.cs:line 191 msg = attr.FormatErrorMessage (null); }, "#A11"); }
public static void FormatErrorMessage_BadlyFormed_ThrowsInvalidOperationException(Type validatorType, string method) { CustomValidationAttribute attribute = new CustomValidationAttribute(validatorType, method); Assert.Throws <InvalidOperationException>(() => attribute.FormatErrorMessage("name")); }