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

            attribute.ErrorMessage             = null;
            attribute.ErrorMessageResourceName = null;
            Assert.Throws <InvalidOperationException>(() => attribute.FormatErrorMessage("Name to put in error message does not matter"));

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

            attribute.ErrorMessageResourceName = "SomeErrorMessageResourceName";
            attribute.ErrorMessageResourceType = null;
            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 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 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 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_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"));
        }
Exemplo n.º 14
0
        public static void TestFormatErrorMessage05()
        {
            var attribute = new ValidationAttributeOverrideBothIsValids()
            {
                ErrorMessageResourceName = "InternalErrorMessageTestProperty",
                ErrorMessageResourceType = typeof(ErrorMessageResources)
            };

            Assert.Equal(
                ErrorMessageResources.InternalErrorMessageTestProperty,
                attribute.FormatErrorMessage("Ignored by this error message"));
        }
Exemplo n.º 15
0
 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"));
 }
Exemplo n.º 16
0
 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"));
 }
Exemplo n.º 17
0
 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"));
 }
Exemplo n.º 18
0
 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"));
 }
Exemplo n.º 19
0
 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"));
 }
Exemplo n.º 20
0
 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"));
 }
Exemplo n.º 21
0
 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"));
 }