public static void GetValidationResult_returns_DefaultErrorMessage_if_ErrorMessage_is_not_set() { var attribute = new ValidatePhoneAttribute(); var toBeTested = new PhoneClassToBeTested(); var validationContext = new ValidationContext(toBeTested) { MemberName = "PhonePropertyToBeTested" }; attribute.GetValidationResult(toBeTested, validationContext); }
public static void GetValidationResult_returns_ErrorMessage_if_ErrorMessage_overrides_default() { var attribute = new ValidatePhoneAttribute { ErrorMessage = "SomeErrorMessage" }; var toBeTested = new PhoneClassToBeTested(); var validationContext = new ValidationContext(toBeTested) { MemberName = "PhonePropertyToBeTested" }; var validationResult = attribute.GetValidationResult(toBeTested, validationContext); Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage); }
public static void GetValidationResult_returns_ErrorMessage_from_resource_if_ErrorMessageResourceName_and_ErrorMessageResourceType_both_set() { var attribute = new ValidatePhoneAttribute { ErrorMessage = string.Empty, ErrorMessageResourceName = "number_phone", ErrorMessageResourceType = typeof(I18n.Error) }; var toBeTested = new PhoneClassToBeTested(); var validationContext = new ValidationContext(toBeTested) { MemberName = "PhonePropertyToBeTested" }; var validationResult = attribute.GetValidationResult(toBeTested, validationContext); Assert.Equal( "Given value is not a valid phone number.", validationResult.ErrorMessage); }