public static void GetValidationResult_returns_DefaultErrorMessage_if_ErrorMessage_is_not_set()
        {
            var attribute         = new UrlAttribute();
            var toBeTested        = new UrlClassToBeTested();
            var validationContext = new ValidationContext(toBeTested);

            validationContext.MemberName = "UrlPropertyToBeTested";
            AssertEx.DoesNotThrow(() => attribute.GetValidationResult(toBeTested, validationContext));
        }
Esempio n. 2
0
 public static void GetValidationResult_returns_ErrorMessage_if_ErrorMessage_overrides_default()
 {
     var attribute = new UrlAttribute();
     attribute.ErrorMessage = "SomeErrorMessage";
     var toBeTested = new UrlClassToBeTested();
     var validationContext = new ValidationContext(toBeTested);
     validationContext.MemberName = "UrlPropertyToBeTested";
     var validationResult = attribute.GetValidationResult(toBeTested, validationContext);
     Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage);
 }
        public void ErrorMessageTest()
        {
            var attribute = new UrlAttribute();
            attribute.ErrorMessage = "SampleErrorMessage";

            const string invalidValue = "a";

            var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null));

            Assert.AreEqual("SampleErrorMessage", result.ErrorMessage);
        }
        public void ErrorResourcesTest()
        {
            var attribute = new UrlAttribute();
            attribute.ErrorMessageResourceName = "ErrorMessage";
            attribute.ErrorMessageResourceType = typeof(ErrorResources);

            const string invalidValue = "a";

            var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null));

            Assert.AreEqual("error message", result.ErrorMessage);
        }
        public static void GetValidationResult_returns_ErrorMessage_if_ErrorMessage_overrides_default()
        {
            var attribute = new UrlAttribute();

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

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

            Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage);
        }
        public void GlobalizedErrorResourcesTest()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX");

            var attribute = new UrlAttribute();
            attribute.ErrorMessageResourceName = "ErrorMessage";
            attribute.ErrorMessageResourceType = typeof(ErrorResources);

            const string invalidValue = "a";

            var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null));

            Assert.AreEqual("mensaje de error", result.ErrorMessage);
        }
        public static void GetValidationResultWithErrorMessageResourceNameAndType()
        {
            var attribute = new UrlAttribute();

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

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

            Assert.Equal(
                "Error Message from ErrorMessageResources.InternalErrorMessageTestProperty",
                validationResult.ErrorMessage);
        }
Esempio n. 8
0
 public static void GetValidationResultWithErrorMessageResourceNameAndType()
 {
     var attribute = new UrlAttribute();
     attribute.ErrorMessageResourceName = "InternalErrorMessageTestProperty";
     attribute.ErrorMessageResourceType = typeof(ErrorMessageResources);
     var toBeTested = new UrlClassToBeTested();
     var validationContext = new ValidationContext(toBeTested);
     validationContext.MemberName = "UrlPropertyToBeTested";
     var validationResult = attribute.GetValidationResult(toBeTested, validationContext);
     Assert.Equal(
         "Error Message from ErrorMessageResources.InternalErrorMessageTestProperty",
         validationResult.ErrorMessage);
 }
Esempio n. 9
0
 public static void GetValidationResult_returns_DefaultErrorMessage_if_ErrorMessage_is_not_set()
 {
     var attribute = new UrlAttribute();
     var toBeTested = new UrlClassToBeTested();
     var validationContext = new ValidationContext(toBeTested);
     validationContext.MemberName = "UrlPropertyToBeTested";
     AssertEx.DoesNotThrow(() => attribute.GetValidationResult(toBeTested, validationContext));
 }