public static void ValidateProperty_succeeds_if_null_passed_to_nullable_property() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = "NullableProperty"; AssertEx.DoesNotThrow(() => Validator.ValidateProperty(null, validationContext)); }
public static void ValidateProperty_succeeds_if_all_attributes_are_valid() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = "PropertyWithRequiredAttribute"; AssertEx.DoesNotThrow( () => Validator.ValidateProperty("Valid Value", validationContext)); }
public static void ValidateProperty_succeeds_if_no_attributes_to_validate() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = "NoAttributesProperty"; AssertEx.DoesNotThrow( () => Validator.ValidateProperty("Any Value", validationContext)); }
public static void ValidatePropertyThrowsIf_ValidationContext_MemberName_is_for_a_public_indexer() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = "Item"; Assert.Throws <ArgumentException>( () => Validator.ValidateProperty(null, validationContext)); }
public static void ValidatePropertyThrowsIf_value_passed_is_of_wrong_type_to_be_assigned_to_property() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = "NoAttributesProperty"; Assert.Throws <ArgumentException>( () => Validator.ValidateProperty(123, validationContext)); }
public static void ValidatePropertyThrowsIf_ValidationContext_MemberName_does_not_exist_on_object() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = "NonExist"; Assert.Throws <ArgumentException>( () => Validator.ValidateProperty(null, validationContext)); }
public static void ValidateProperty_throws_ValidationException_if_Required_attribute_test_fails() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = "PropertyWithRequiredAttribute"; var exception = Assert.Throws <ValidationException>( () => Validator.ValidateProperty(null, validationContext)); AssertEx.IsType <RequiredAttribute>(exception.ValidationAttribute); // cannot check error message - not defined on ret builds Assert.Null(exception.Value); }
public static void ValidateProperty_throws_ValidationException_if_errors() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = "PropertyToBeTested"; var exception = Assert.Throws <ValidationException>( () => Validator.ValidateProperty("Invalid Value", validationContext)); AssertEx.IsType <ValidValueStringPropertyAttribute>(exception.ValidationAttribute); Assert.Equal("ValidValueStringPropertyAttribute.IsValid failed for value Invalid Value", exception.ValidationResult.ErrorMessage); Assert.Equal("Invalid Value", exception.Value); }
public static void ValidatePropertyThrowsIf_ValidationContext_MemberName_is_null_or_empty() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = null; Assert.Throws <ArgumentNullException>( () => Validator.ValidateProperty(null, validationContext)); validationContext.MemberName = string.Empty; Assert.Throws <ArgumentNullException>( () => Validator.ValidateProperty(null, validationContext)); }
public static void ValidatePropertyThrowsIf_null_passed_to_non_nullable_property() { var validationContext = new ValidationContext(new ToBeValidated()); // cannot assign null to a non-value-type property validationContext.MemberName = "EnumProperty"; Assert.Throws <ArgumentException>( () => Validator.ValidateProperty(null, validationContext)); // cannot assign null to a non-nullable property validationContext.MemberName = "NonNullableProperty"; Assert.Throws <ArgumentException>( () => Validator.ValidateProperty(null, validationContext)); }
public static void ValidatePropertyThrowsIf_ValidationContext_MemberName_is_not_public() { var validationContext = new ValidationContext(new ToBeValidated()); validationContext.MemberName = "InternalProperty"; Assert.Throws <ArgumentException>( () => Validator.ValidateProperty(null, validationContext)); validationContext.MemberName = "ProtectedProperty"; Assert.Throws <ArgumentException>( () => Validator.ValidateProperty(null, validationContext)); validationContext.MemberName = "PrivateProperty"; Assert.Throws <ArgumentException>( () => Validator.ValidateProperty(null, validationContext)); }
public static void ValidatePropertyThrowsIf_value_is_null() { Assert.Throws <ArgumentNullException>( () => Validator.ValidateProperty(null, s_estValidationContext)); }
public static void ValidatePropertyThrowsIf_ValidationContext_is_null() { Assert.Throws <ArgumentNullException>( () => Validator.ValidateProperty(new object(), validationContext: null)); }