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 TestFormatErrorMessage02()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessageResourceName = "NonExistentErrorMessageTestProperty";
            attribute.ErrorMessageResourceType = typeof(ValidationAttributeOverrideBothIsValids);
            Assert.Throws <InvalidOperationException>(() => attribute.FormatErrorMessage("Name to put in error message does not matter"));
        }
        public static void TestFormatErrorMessageThrow01()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessageResourceName = string.Empty;
            attribute.ErrorMessageResourceType = typeof(string);
            Assert.Throws <InvalidOperationException>(() => attribute.FormatErrorMessage("Name to put in error message does not matter"));
        }
        public static void TestThrowIfErrorMessageAndNameBothSet()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = "SomeErrorMessage";
            attribute.ErrorMessageResourceName = "SomeErrorMessageResourceName";
            Assert.Throws <InvalidOperationException>(() => attribute.FormatErrorMessage("Name to put in error message does not matter"));
        }
        public void FormatErrorMessage_InvalidResourceNameAndResourceType_ThrowsInvalidOperationException(string resourceName, Type resourceType)
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessageResourceName = resourceName;
            attribute.ErrorMessageResourceType = resourceType;
            Assert.Throws <InvalidOperationException>(() => attribute.FormatErrorMessage("Name to put in error message does not matter"));
        }
        public void FormatErrorMessage_BothErrorMessageAndResourceType_ThrowsInvalidOperationException()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = "SomeErrorMessage";
            attribute.ErrorMessageResourceType = typeof(int);
            Assert.Throws <InvalidOperationException>(() => attribute.FormatErrorMessage("Name to put in error message does not matter"));
        }
        public void FormatErrorMessage_NullOrEmptyErrorMessageAndName_ThrowsInvalidOperationException(string value)
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = value;
            attribute.ErrorMessageResourceName = value;
            Assert.Throws <InvalidOperationException>(() => attribute.FormatErrorMessage("name"));
        }
        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 TestFormatErrorMessage()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = "SomeErrorMessage";
            attribute.ErrorMessageResourceName = null;
            attribute.ErrorMessageResourceType = null;
            Assert.Equal("SomeErrorMessage", attribute.FormatErrorMessage("Name to put in error message does not matter - no placeholder"));
        }
        public void FormatErrorMessage_HasResourceProperty_ReturnsExpected(string resourceName, Type resourceType, string expected)
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = string.Empty;
            attribute.ErrorMessageResourceName = resourceName;
            attribute.ErrorMessageResourceType = resourceType;
            Assert.Equal(expected, attribute.FormatErrorMessage("name"));
        }
        public void FormatErrorMessage_HasErrorMessage_ReturnsExpected(string errorMessage, string expected)
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = errorMessage;
            attribute.ErrorMessageResourceName = null;
            attribute.ErrorMessageResourceType = null;
            Assert.Equal(expected, attribute.FormatErrorMessage("name"));
        }
        public static void TestFormatErrorMessage03()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = string.Empty;
            attribute.ErrorMessageResourceName = "PublicErrorMessageTestProperty";
            attribute.ErrorMessageResourceType = typeof(ValidationAttributeOverrideBothIsValids);
            Assert.Equal(ValidationAttributeOverrideBothIsValids.PublicErrorMessageTestProperty,
                         attribute.FormatErrorMessage("Name to put in error message does not matter - no placeholder"));
        }
        public static void TestFormatErrorMessage01()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = "SomeErrorMessage with name <{0}> here";
            attribute.ErrorMessageResourceName = null;
            attribute.ErrorMessageResourceType = null;
            Assert.Equal(
                string.Format("SomeErrorMessage with name <{0}> here", "Error Message Name"),
                attribute.FormatErrorMessage("Error Message Name"));
        }
        public static void TestFormatErrorMessage05()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids()
            {
                ErrorMessageResourceName = "InternalErrorMessageTestProperty",
                ErrorMessageResourceType = typeof(ErrorMessageResources)
            };

            Assert.Equal(
                ErrorMessageResources.InternalErrorMessageTestProperty,
                attribute.FormatErrorMessage("Ignored by this error message"));
        }
        public static void TestFormatErrorMessage04()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            attribute.ErrorMessage             = string.Empty;
            attribute.ErrorMessageResourceName = "PublicErrorMessageTestPropertyWithName";
            attribute.ErrorMessageResourceType = typeof(ValidationAttributeOverrideBothIsValids);
            Assert.Equal(
                string.Format(
                    ValidationAttributeOverrideBothIsValids.PublicErrorMessageTestPropertyWithName,
                    "Error Message Name"),
                attribute.FormatErrorMessage("Error Message Name"));
        }
        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 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 Validate_NullValidationContext_ThrowsArgumentNullException()
 {
     ValidationAttributeOverrideBothIsValids attribute = new ValidationAttributeOverrideBothIsValids();
     Assert.Throws<ArgumentNullException>("validationContext", () => attribute.Validate("Any", validationContext: null));
 }
        public static void TestFormatErrorMessage05()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids()
            {
                ErrorMessageResourceName = "InternalErrorMessageTestProperty",
                ErrorMessageResourceType = typeof(ErrorMessageResources)
            };

            Assert.Equal(
                ErrorMessageResources.InternalErrorMessageTestProperty,
                attribute.FormatErrorMessage("Ignored by this error message"));
        }
 public static void TestThrowIfNullValidationContext()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     Assert.Throws<ArgumentNullException>(() => attribute.GetValidationResult("Does not matter", validationContext: null));
 }
 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 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 TestFormatErrorMessage03()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.ErrorMessage = string.Empty;
     attribute.ErrorMessageResourceName = "PublicErrorMessageTestProperty";
     attribute.ErrorMessageResourceType = typeof(ValidationAttributeOverrideBothIsValids);
     Assert.Equal(ValidationAttributeOverrideBothIsValids.PublicErrorMessageTestProperty,
         attribute.FormatErrorMessage("Name to put in error message does not matter - no placeholder"));
 }
 public static void TestFormatErrorMessage04()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.ErrorMessage = string.Empty;
     attribute.ErrorMessageResourceName = "PublicErrorMessageTestPropertyWithName";
     attribute.ErrorMessageResourceType = typeof(ValidationAttributeOverrideBothIsValids);
     Assert.Equal(
         string.Format(
             ValidationAttributeOverrideBothIsValids.PublicErrorMessageTestPropertyWithName,
             "Error Message Name"),
         attribute.FormatErrorMessage("Error Message Name"));
 }
 public static void TestFormatErrorMessage01()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.ErrorMessage = "SomeErrorMessage with name <{0}> here";
     attribute.ErrorMessageResourceName = null;
     attribute.ErrorMessageResourceType = null;
     Assert.Equal(
         string.Format("SomeErrorMessage with name <{0}> here", "Error Message Name"),
         attribute.FormatErrorMessage("Error Message Name"));
 }
 public static void TestFormatErrorMessage02()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.ErrorMessageResourceName = "NonExistentErrorMessageTestProperty";
     attribute.ErrorMessageResourceType = typeof(ValidationAttributeOverrideBothIsValids);
     Assert.Throws<InvalidOperationException>(() => attribute.FormatErrorMessage("Name to put in error message does not matter"));
 }
 public static void TestFormatErrorMessageThrow01()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.ErrorMessageResourceName = string.Empty;
     attribute.ErrorMessageResourceType = typeof(string);
     Assert.Throws<InvalidOperationException>(() => attribute.FormatErrorMessage("Name to put in error message does not matter"));
 }
 public static void TestFormatErrorMessage()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.ErrorMessage = "SomeErrorMessage";
     attribute.ErrorMessageResourceName = null;
     attribute.ErrorMessageResourceType = null;
     Assert.Equal("SomeErrorMessage", attribute.FormatErrorMessage("Name to put in error message does not matter - no placeholder"));
 }
 public static void TestThrowIfErrorMessageAndNameBothSet()
 {
     var attribute = new ValidationAttributeOverrideBothIsValids();
     attribute.ErrorMessage = "SomeErrorMessage";
     attribute.ErrorMessageResourceName = "SomeErrorMessageResourceName";
     Assert.Throws<InvalidOperationException>(() => attribute.FormatErrorMessage("Name to put in error message does not matter"));
 }
 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 TestThrowIfNullValidationContext()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids();

            Assert.Throws <ArgumentNullException>(() => attribute.GetValidationResult("Does not matter", validationContext: null));
        }
        public static void Validate_NullValidationContext_ThrowsArgumentNullException()
        {
            ValidationAttributeOverrideBothIsValids attribute = new ValidationAttributeOverrideBothIsValids();

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