public static void TestNoThrowIfOverrideIsValid05()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            Assert.Throws <ValidationException>(() => attribute.Validate("Valid 1-Arg Value", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("Valid 2-Args Value", s_testValidationContext));
        }
        public static void TestNoThrowIfOverrideIsValid04()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.Validate("Valid 1-Arg Value", "Name to put in error message does not matter - no error");
            Assert.Throws <ValidationException>(
                () => attribute.Validate("Valid 2-Args Value", "Name to put in error message does not matter - no error"));
        }
        public static void TestThrowWithValidationResultErrorMessage01()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = string.Empty;
            attribute.ErrorMessageResourceName = "PublicErrorMessageTestPropertyWithName";
            attribute.ErrorMessageResourceType = typeof(ValidationAttributeOverrideBothIsValids);
            var exception = Assert.Throws <ValidationException>(() => attribute.Validate("Invalid Value", "Error Message Name"));

            Assert.Equal("Invalid Value", exception.Value);
            Assert.Equal(
                string.Format(
                    ValidationAttributeOverrideBothIsValids.PublicErrorMessageTestPropertyWithName,
                    "Error Message Name"),
                exception.ValidationResult.ErrorMessage);
        }
        public static void TestThrowWithValidationResultErrorMessage()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = "SomeErrorMessage with name <{0}> here";
            attribute.ErrorMessageResourceName = null;
            attribute.ErrorMessageResourceType = null;
            var exception = Assert.Throws <ValidationException>(() => attribute.Validate("Invalid Value", "Error Message Name"));

            Assert.Equal("Invalid Value", exception.Value);
            Assert.Equal(
                string.Format(
                    "SomeErrorMessage with name <{0}> here",
                    "Error Message Name"),
                exception.ValidationResult.ErrorMessage);
        }
 public static void Validate_NullValidationContext_ThrowsArgumentNullException()
 {
     ValidationAttributeOverrideBothIsValids attribute = new ValidationAttributeOverrideBothIsValids();
     Assert.Throws<ArgumentNullException>("validationContext", () => attribute.Validate("Any", validationContext: null));
 }
 public static void TestThrowWithValidationResultErrorMessage01()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.ErrorMessage = string.Empty;
     attribute.ErrorMessageResourceName = "PublicErrorMessageTestPropertyWithName";
     attribute.ErrorMessageResourceType = typeof(ValidationAttributeOverrideBothIsValids);
     var exception = Assert.Throws<ValidationException>(() => attribute.Validate("Invalid Value", "Error Message Name"));
     Assert.Equal("Invalid Value", exception.Value);
     Assert.Equal(
         string.Format(
             ValidationAttributeOverrideBothIsValids.PublicErrorMessageTestPropertyWithName,
             "Error Message Name"),
         exception.ValidationResult.ErrorMessage);
 }
 public static void TestThrowWithValidationResultErrorMessage()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.ErrorMessage = "SomeErrorMessage with name <{0}> here";
     attribute.ErrorMessageResourceName = null;
     attribute.ErrorMessageResourceType = null;
     var exception = Assert.Throws<ValidationException>(() => attribute.Validate("Invalid Value", "Error Message Name"));
     Assert.Equal("Invalid Value", exception.Value);
     Assert.Equal(
         string.Format(
             "SomeErrorMessage with name <{0}> here",
             "Error Message Name"),
         exception.ValidationResult.ErrorMessage);
 }
 public static void TestNoThrowIfOverrideIsValid05()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     Assert.Throws<ValidationException>(() => attribute.Validate("Valid 1-Arg Value", s_testValidationContext));
     attribute.Validate("Valid 2-Args Value", s_testValidationContext);
 }
 public static void TestNoThrowIfOverrideIsValid04()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.Validate("Valid 1-Arg Value", "Name to put in error message does not matter - no error");
     Assert.Throws<ValidationException>(
         () => attribute.Validate("Valid 2-Args Value", "Name to put in error message does not matter - no error"));
 }
        public static void Validate_NullValidationContext_ThrowsArgumentNullException()
        {
            ValidationAttributeOverrideBothIsValids attribute = new ValidationAttributeOverrideBothIsValids();

            AssertExtensions.Throws <ArgumentNullException>("validationContext", () => attribute.Validate("Any", validationContext: null));
        }