示例#1
0
        public static void GetValidationResult_returns_DefaultErrorMessage_if_ErrorMessage_is_not_set()
        {
            var attribute = new FileExtensionsAttribute();

            attribute.Extensions = "";
            var toBeTested        = new FileExtensionsClassToBeTested();
            var validationContext = new ValidationContext(toBeTested);

            validationContext.MemberName = "FileExtensionsPropertyToBeTested";
            AssertEx.DoesNotThrow(() => attribute.GetValidationResult(toBeTested, validationContext));
        }
示例#2
0
        public static void GetValidationResult_returns_ErrorMessage_if_ErrorMessage_overrides_default()
        {
            var attribute = new FileExtensionsAttribute();

            attribute.ErrorMessage = "SomeErrorMessage";
            var toBeTested        = new FileExtensionsClassToBeTested();
            var validationContext = new ValidationContext(toBeTested);

            validationContext.MemberName = "FileExtensionsPropertyToBeTested";
            var validationResult = attribute.GetValidationResult(toBeTested, validationContext);

            Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage);
        }
示例#3
0
        public static void GetValidationResult_returns_ErrorMessage_from_resource_if_ErrorMessageResourceName_and_ErrorMessageResourceType_both_set()
        {
            var attribute = new FileExtensionsAttribute();

            attribute.ErrorMessageResourceName = "InternalErrorMessageTestProperty";
            attribute.ErrorMessageResourceType = typeof(ErrorMessageResources);
            var toBeTested        = new FileExtensionsClassToBeTested();
            var validationContext = new ValidationContext(toBeTested);

            validationContext.MemberName = "FileExtensionsPropertyToBeTested";
            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 FileExtensionsAttribute();
     attribute.ErrorMessageResourceName = "InternalErrorMessageTestProperty";
     attribute.ErrorMessageResourceType = typeof(ErrorMessageResources);
     var toBeTested = new FileExtensionsClassToBeTested();
     var validationContext = new ValidationContext(toBeTested);
     validationContext.MemberName = "FileExtensionsPropertyToBeTested";
     var validationResult = attribute.GetValidationResult(toBeTested, validationContext);
     Assert.Equal(
         "Error Message from ErrorMessageResources.InternalErrorMessageTestProperty",
         validationResult.ErrorMessage);
 }
 public static void GetValidationResult_returns_DefaultErrorMessage_if_ErrorMessage_is_not_set()
 {
     var attribute = new FileExtensionsAttribute();
     attribute.Extensions = "";
     var toBeTested = new FileExtensionsClassToBeTested();
     var validationContext = new ValidationContext(toBeTested);
     validationContext.MemberName = "FileExtensionsPropertyToBeTested";
     AssertEx.DoesNotThrow(() => attribute.GetValidationResult(toBeTested, validationContext));
 }
 public static void GetValidationResult_returns_ErrorMessage_if_ErrorMessage_overrides_default()
 {
     var attribute = new FileExtensionsAttribute();
     attribute.ErrorMessage = "SomeErrorMessage";
     var toBeTested = new FileExtensionsClassToBeTested();
     var validationContext = new ValidationContext(toBeTested);
     validationContext.MemberName = "FileExtensionsPropertyToBeTested";
     var validationResult = attribute.GetValidationResult(toBeTested, validationContext);
     Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage);
 }