public static void GetValidationResult_returns_DefaultErrorMessage_if_ErrorMessage_is_not_set() { var attribute = new EmailAddressAttribute(); var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = "EmailPropertyToBeTested"; AssertEx.DoesNotThrow(() => attribute.GetValidationResult(toBeTested, validationContext)); }
public static void GetValidationResult_ErrorMessageNotSet_ReturnsDefaultValue() { var attribute = new EmailAddressAttribute(); var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = nameof(EmailClassToBeTested.EmailPropertyToBeTested); attribute.GetValidationResult(toBeTested, validationContext); }
public static void GetValidationResult_returns_ErrorMessage_if_ErrorMessage_overrides_default() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessage = "SomeErrorMessage"; var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = "EmailPropertyToBeTested"; var validationResult = attribute.GetValidationResult(toBeTested, validationContext); Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage); }
public static void GetValidationResult_ErrorMessageSet_ReturnsOverridenValue() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessage = "SomeErrorMessage"; var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = nameof(EmailClassToBeTested.EmailPropertyToBeTested); var validationResult = attribute.GetValidationResult(toBeTested, validationContext); Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage); }
public static void GetValidationResult_ErrorMessageSetFromResource_ReturnsExpectedValue() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessageResourceName = "InternalErrorMessageTestProperty"; attribute.ErrorMessageResourceType = typeof(ErrorMessageResources); var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = nameof(EmailClassToBeTested.EmailPropertyToBeTested); var validationResult = attribute.GetValidationResult(toBeTested, validationContext); Assert.Equal("Error Message from ErrorMessageResources.InternalErrorMessageTestProperty", validationResult.ErrorMessage); }
public static void GetValidationResult_returns_ErrorMessage_from_resource_if_ErrorMessageResourceName_and_ErrorMessageResourceType_both_set() { var attribute = new EmailAddressAttribute(); attribute.ErrorMessageResourceName = "InternalErrorMessageTestProperty"; attribute.ErrorMessageResourceType = typeof(ErrorMessageResources); var toBeTested = new EmailClassToBeTested(); var validationContext = new ValidationContext(toBeTested); validationContext.MemberName = "EmailPropertyToBeTested"; var validationResult = attribute.GetValidationResult(toBeTested, validationContext); Assert.Equal( "Error Message from ErrorMessageResources.InternalErrorMessageTestProperty", validationResult.ErrorMessage); }