상속: System.ComponentModel.DataAnnotations.ValidationAttribute
예제 #1
0
        public void FormatErrorMessage()
        {
            var attr = new ValidateFooAttribute();

            Assert.IsNotNull(attr.FormatErrorMessage("SomeField"), "#A1-1");
            Assert.AreEqual("The field SomeField is invalid.", attr.FormatErrorMessage("SomeField"), "#A1-2");

            attr.ErrorMessage = "Test: {0}";
            Assert.IsNotNull(attr.FormatErrorMessage("SomeField"), "#A2-1");
            Assert.AreEqual("Test: SomeField", attr.FormatErrorMessage("SomeField"), "#A2-2");
#if !NET_4_0
            attr = new ValidateFooAttribute();
#else
            attr.ErrorMessage = null;
#endif
            attr.ErrorMessageResourceName = "ErrorProperty1";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            Assert.IsNotNull(attr.FormatErrorMessage("SomeField"), "#B1-1");
            Assert.AreEqual("Error Message 1", attr.FormatErrorMessage("SomeField"), "#B1-2");
#if !NET_4_0
            attr = new ValidateFooAttribute();
#endif
            attr.ErrorMessageResourceName = "ErrorProperty6";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            Assert.IsNotNull(attr.FormatErrorMessage("SomeField"), "#B2-1");
            Assert.AreEqual("Error Message 6: SomeField", attr.FormatErrorMessage("SomeField"), "#B2-2");
#if !NET_4_0
            attr = new ValidateFooAttribute();
#endif
            attr.ErrorMessageResourceName = "ErrorProperty6";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            Assert.IsNotNull(attr.FormatErrorMessage("SomeField"), "#B3-1");
            Assert.AreEqual("Error Message 6: ", attr.FormatErrorMessage(null), "#B3-2");
        }
예제 #2
0
		public void Constructor ()
		{
			var attr = new ValidateFooAttribute ();

			Assert.IsNull (attr.ErrorMessage, "#A1");
			Assert.IsNull (attr.ErrorMessageResourceName, "#A2");
			Assert.IsNull (attr.ErrorMessageResourceType, "#A3");
			Assert.IsNotNull (attr.GetErrorMessageString (), "#A4");
		}
예제 #3
0
        public void Constructor()
        {
            var attr = new ValidateFooAttribute();

            Assert.IsNull(attr.ErrorMessage, "#A1");
            Assert.IsNull(attr.ErrorMessageResourceName, "#A2");
            Assert.IsNull(attr.ErrorMessageResourceType, "#A3");
            Assert.IsNotNull(attr.GetErrorMessageString(), "#A4");
        }
예제 #4
0
        public void ErrorMessageResourceType()
        {
            var attr = new ValidateFooAttribute();

            Assert.IsNull(attr.ErrorMessageResourceType, "#A1");

            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            Assert.IsNotNull(attr.ErrorMessageResourceType, "#A2-1");
            Assert.AreEqual(typeof(FooErrorMessageProvider), attr.ErrorMessageResourceType, "#A2-2");
        }
예제 #5
0
        public void Constructor_Func()
        {
            var attr = new ValidateFooAttribute(ErrorMessageAccessor);

            Assert.IsNull(attr.ErrorMessage, "#A1");
            Assert.IsNull(attr.ErrorMessageResourceName, "#A2");
            Assert.IsNull(attr.ErrorMessageResourceType, "#A3");
            Assert.IsNotNull(attr.GetErrorMessageString(), "#A4");
            Assert.AreEqual(TEST_ERROR_MESSAGE, attr.GetErrorMessageString(), "#A4");
        }
예제 #6
0
		public void Constructor_Func ()
		{
			var attr = new ValidateFooAttribute (ErrorMessageAccessor);

			Assert.IsNull (attr.ErrorMessage, "#A1");
			Assert.IsNull (attr.ErrorMessageResourceName, "#A2");
			Assert.IsNull (attr.ErrorMessageResourceType, "#A3");
			Assert.IsNotNull (attr.GetErrorMessageString (), "#A4");
			Assert.AreEqual (TEST_ERROR_MESSAGE, attr.GetErrorMessageString (), "#A4");
		}
예제 #7
0
        public void Constructor_String()
        {
            var attr = new ValidateFooAttribute("Another Test Error Message");

            Assert.IsNull(attr.ErrorMessage, "#A1");
            Assert.IsNull(attr.ErrorMessageResourceName, "#A2");
            Assert.IsNull(attr.ErrorMessageResourceType, "#A3");
            Assert.IsNotNull(attr.GetErrorMessageString(), "#A4");
            Assert.IsNotNull(attr.GetErrorMessageString(), "#A4-1");
            Assert.AreEqual("Another Test Error Message", attr.GetErrorMessageString(), "#A4-2");
        }
예제 #8
0
		public void Constructor_String ()
		{
			var attr = new ValidateFooAttribute ("Another Test Error Message");

			Assert.IsNull (attr.ErrorMessage, "#A1");
			Assert.IsNull (attr.ErrorMessageResourceName, "#A2");
			Assert.IsNull (attr.ErrorMessageResourceType, "#A3");
			Assert.IsNotNull (attr.GetErrorMessageString (), "#A4");
			Assert.IsNotNull (attr.GetErrorMessageString (), "#A4-1");
			Assert.AreEqual ("Another Test Error Message", attr.GetErrorMessageString (), "#A4-2");
		}
예제 #9
0
        public void ErrorMessageResourceName()
        {
            var attr = new ValidateFooAttribute();

            Assert.IsNull(attr.ErrorMessageResourceName, "#A1");

            attr.ErrorMessageResourceName = "Test";
            Assert.IsNotNull(attr.ErrorMessageResourceName, "#A2-1");
            Assert.AreEqual("Test", attr.ErrorMessageResourceName, "#A2-2");
#if NET_4_0
            attr.ErrorMessageResourceName = String.Empty;
            Assert.IsNotNull(attr.ErrorMessageResourceName, "#A3-1");
            Assert.AreEqual(String.Empty, attr.ErrorMessageResourceName, "#A3-2");

            attr.ErrorMessageResourceName = null;
            Assert.IsNull(attr.ErrorMessageResourceName, "#A3-1");
#else
            try {
                attr.ErrorMessageResourceName = String.Empty;
                Assert.Fail("#A3-1");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute("Test");
            try {
                attr.ErrorMessageResourceName = String.Empty;
                Assert.Fail("#A3-2");
            } catch (ArgumentException) {
                // success
            }

            attr = new ValidateFooAttribute("Test");
            try {
                attr.ErrorMessageResourceName = null;
                Assert.Fail("#A3-3");
            } catch (ArgumentException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);

            try {
                attr.ErrorMessageResourceName = "NoSuchProperty";
                Assert.Fail("#A3-4");
            } catch (InvalidOperationException) {
                // success
            }
#endif
        }
예제 #10
0
        public void ErrorMessage()
        {
            var attr = new ValidateFooAttribute();

            Assert.IsNull(attr.ErrorMessage, "#A1");

            attr.ErrorMessage = "Test";
            Assert.AreEqual("Test", attr.ErrorMessage, "#A2");
            attr.ErrorMessage = String.Empty;
            Assert.AreEqual(String.Empty, attr.ErrorMessage, "#A3");

            attr.ErrorMessage = null;
            Assert.IsNull(attr.ErrorMessage, "#A4");
        }
예제 #11
0
		public void ErrorMessage ()
		{
			var attr = new ValidateFooAttribute ();

			Assert.IsNull (attr.ErrorMessage, "#A1");

			attr.ErrorMessage = "Test";
			Assert.AreEqual ("Test", attr.ErrorMessage, "#A2");
#if NET_4_0
			attr.ErrorMessage = String.Empty;
			Assert.AreEqual (String.Empty, attr.ErrorMessage, "#A3");

			attr.ErrorMessage = null;
			Assert.IsNull (attr.ErrorMessage, "#A4");
#else
			try {
				attr.ErrorMessage = String.Empty;
				Assert.Fail ("#A3");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ("Test");
			try {
				attr.ErrorMessage = null;
				Assert.Fail ("#A4");
			} catch (ArgumentException) {
				// success
			}

			attr = new ValidateFooAttribute ("Test");
			try {
				attr.ErrorMessage = String.Empty;
				Assert.Fail ("#A4");
			} catch (ArgumentException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "ErrorProperty1";

			try {
				attr.ErrorMessage = "Test Message";
				Assert.Fail ("#E1");
			} catch (InvalidOperationException) {
				// success
			}
#endif
			
		}
예제 #12
0
        public void ErrorMessage()
        {
            var attr = new ValidateFooAttribute();

            Assert.IsNull(attr.ErrorMessage, "#A1");

            attr.ErrorMessage = "Test";
            Assert.AreEqual("Test", attr.ErrorMessage, "#A2");
#if NET_4_0
            attr.ErrorMessage = String.Empty;
            Assert.AreEqual(String.Empty, attr.ErrorMessage, "#A3");

            attr.ErrorMessage = null;
            Assert.IsNull(attr.ErrorMessage, "#A4");
#else
            try {
                attr.ErrorMessage = String.Empty;
                Assert.Fail("#A3");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute("Test");
            try {
                attr.ErrorMessage = null;
                Assert.Fail("#A4");
            } catch (ArgumentException) {
                // success
            }

            attr = new ValidateFooAttribute("Test");
            try {
                attr.ErrorMessage = String.Empty;
                Assert.Fail("#A4");
            } catch (ArgumentException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "ErrorProperty1";

            try {
                attr.ErrorMessage = "Test Message";
                Assert.Fail("#E1");
            } catch (InvalidOperationException) {
                // success
            }
#endif
        }
예제 #13
0
		public void ErrorMessage ()
		{
			var attr = new ValidateFooAttribute ();

			Assert.IsNull (attr.ErrorMessage, "#A1");

			attr.ErrorMessage = "Test";
			Assert.AreEqual ("Test", attr.ErrorMessage, "#A2");
			attr.ErrorMessage = String.Empty;
			Assert.AreEqual (String.Empty, attr.ErrorMessage, "#A3");

			attr.ErrorMessage = null;
			Assert.IsNull (attr.ErrorMessage, "#A4");
			
		}
예제 #14
0
        public void ErrorMessageResourceName()
        {
            var attr = new ValidateFooAttribute();

            Assert.IsNull(attr.ErrorMessageResourceName, "#A1");

            attr.ErrorMessageResourceName = "Test";
            Assert.IsNotNull(attr.ErrorMessageResourceName, "#A2-1");
            Assert.AreEqual("Test", attr.ErrorMessageResourceName, "#A2-2");
            attr.ErrorMessageResourceName = String.Empty;
            Assert.IsNotNull(attr.ErrorMessageResourceName, "#A3-1");
            Assert.AreEqual(String.Empty, attr.ErrorMessageResourceName, "#A3-2");

            attr.ErrorMessageResourceName = null;
            Assert.IsNull(attr.ErrorMessageResourceName, "#A3-1");
        }
예제 #15
0
        public void IsValid_Object()
        {
            var attr = new ValidateFooAttribute();

            AssertExtensions.Throws <NotImplementedException> (() => {
                // It calls IsValid (object, validationContext) which throws the NIEX, but when that overload is called directly, there's
                // no exception.
                //
                // at System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value, ValidationContext validationContext)
                // at System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value)
                // at MonoTests.System.ComponentModel.DataAnnotations.ValidationAttributeTest.IsValid_Object() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\ValidationAttributeTest.cs:line 450
                attr.IsValid(null);
            }, "#A1-1");

            AssertExtensions.Throws <NotImplementedException> (() => {
                attr.IsValid("stuff");
            }, "#A1-2");
        }
예제 #16
0
        public void IsValid_Object()
        {
            var attr = new ValidateFooAttribute();

            try {
                attr.IsValid(null);
                Assert.Fail("#A1-1");
            } catch (NotImplementedException) {
                // success
            }

            try {
                attr.IsValid("stuff");
                Assert.Fail("#A1-2");
            } catch (NotImplementedException) {
                // success
            }
        }
예제 #17
0
        public void ErrorMessageResourceType()
        {
            var attr = new ValidateFooAttribute();

            Assert.IsNull(attr.ErrorMessageResourceType, "#A1");

            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            Assert.IsNotNull(attr.ErrorMessageResourceType, "#A2-1");
            Assert.AreEqual(typeof(FooErrorMessageProvider), attr.ErrorMessageResourceType, "#A2-2");
#if !NET_4_0
            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "NoSuchProperty";

            try {
                attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
                Assert.Fail("#A3");
            } catch (InvalidOperationException) {
                // success
            }
#endif
        }
예제 #18
0
		public void ErrorMessageResourceName ()
		{
			var attr = new ValidateFooAttribute ();

			Assert.IsNull (attr.ErrorMessageResourceName, "#A1");

			attr.ErrorMessageResourceName = "Test";
			Assert.IsNotNull (attr.ErrorMessageResourceName, "#A2-1");
			Assert.AreEqual ("Test", attr.ErrorMessageResourceName, "#A2-2");
			attr.ErrorMessageResourceName = String.Empty;
			Assert.IsNotNull (attr.ErrorMessageResourceName, "#A3-1");
			Assert.AreEqual (String.Empty, attr.ErrorMessageResourceName, "#A3-2");

			attr.ErrorMessageResourceName = null;
			Assert.IsNull (attr.ErrorMessageResourceName, "#A3-1");
		}
예제 #19
0
        public void ErrorMessageString()
        {
            var attr = new ValidateFooAttribute();

            Assert.IsNotNull(attr.GetErrorMessageString(), "#A1-1");
            Assert.IsTrue(attr.GetErrorMessageString().Length > 0, "#A1-2");

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "TestResource";
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#A2-1");
            } catch (InvalidOperationException) {
                // success
            }
#if NET_4_0
            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = String.Empty;
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#A2-1");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            attr.ErrorMessageResourceName = null;

            try {
                attr.GetErrorMessageString();
                Assert.Fail("#A3-1");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = String.Empty;
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            try {
                string s = attr.GetErrorMessageString();
                Assert.Fail("#A3-2");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "NoSuchProperty";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#A4");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "ErrorProperty2";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#A5");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "ErrorProperty3";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#A5");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "ErrorProperty4";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#A6");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "ErrorProperty5";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#A7");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "ErrorField1";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#B1");
            } catch (InvalidOperationException) {
                // success
            }

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "ErrorField2";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#B2");
            } catch (InvalidOperationException) {
                // success
            }
#endif

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "ErrorProperty1";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            Assert.IsNotNull(attr.GetErrorMessageString(), "#C1-1");
            Assert.AreEqual("Error Message 1", attr.GetErrorMessageString(), "#C1-2");

            attr = new ValidateFooAttribute(ErrorMessageAccessor);
            Assert.IsNotNull(attr.GetErrorMessageString(), "#D1-1");
            Assert.AreEqual(TEST_ERROR_MESSAGE, attr.GetErrorMessageString(), "#D1-2");

            attr = new ValidateFooAttribute();
            attr.ErrorMessageResourceName = "ErrorProperty1";
            attr.ErrorMessageResourceType = typeof(FooErrorMessageProvider);
            Assert.IsNotNull(attr.GetErrorMessageString(), "#D1-3");
            Assert.AreEqual("Error Message 1", attr.GetErrorMessageString(), "#D1-4");
#if NET_4_0
            attr.ErrorMessage = "Test Message";
            try {
                attr.GetErrorMessageString();
                Assert.Fail("#E1");
            } catch (InvalidOperationException) {
                // success
            }
#endif
        }
예제 #20
0
		public void IsValid_Object ()
		{
			var attr = new ValidateFooAttribute ();

			try {
				attr.IsValid (null);
				Assert.Fail ("#A1-1");
			} catch (NotImplementedException) {
				// success
			}

			try {
				attr.IsValid ("stuff");
				Assert.Fail ("#A1-2");
			} catch (NotImplementedException) {
				// success
			}
		}
예제 #21
0
		public void ErrorMessageResourceType ()
		{
			var attr = new ValidateFooAttribute ();

			Assert.IsNull (attr.ErrorMessageResourceType, "#A1");

			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			Assert.IsNotNull (attr.ErrorMessageResourceType, "#A2-1");
			Assert.AreEqual (typeof (FooErrorMessageProvider), attr.ErrorMessageResourceType, "#A2-2");
		}
예제 #22
0
		public void FormatErrorMessage ()
		{
			var attr = new ValidateFooAttribute ();

			Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#A1-1");
			Assert.AreEqual ("The field SomeField is invalid.", attr.FormatErrorMessage ("SomeField"), "#A1-2");

			attr.ErrorMessage = "Test: {0}";
			Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#A2-1");
			Assert.AreEqual ("Test: SomeField", attr.FormatErrorMessage ("SomeField"), "#A2-2");
#if !NET_4_0
			attr = new ValidateFooAttribute ();
#else
			attr.ErrorMessage = null;
#endif
			attr.ErrorMessageResourceName = "ErrorProperty1";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#B1-1");
			Assert.AreEqual ("Error Message 1", attr.FormatErrorMessage ("SomeField"), "#B1-2");
#if !NET_4_0
			attr = new ValidateFooAttribute ();
#endif
			attr.ErrorMessageResourceName = "ErrorProperty6";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#B2-1");
			Assert.AreEqual ("Error Message 6: SomeField", attr.FormatErrorMessage ("SomeField"), "#B2-2");
#if !NET_4_0
			attr = new ValidateFooAttribute ();
#endif
			attr.ErrorMessageResourceName = "ErrorProperty6";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#B3-1");
			Assert.AreEqual ("Error Message 6: ", attr.FormatErrorMessage (null), "#B3-2");
		}
예제 #23
0
		public void ErrorMessageString ()
		{
			var attr = new ValidateFooAttribute ();

			Assert.IsNotNull (attr.GetErrorMessageString (), "#A1-1");
			Assert.IsTrue (attr.GetErrorMessageString ().Length > 0, "#A1-2");

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "TestResource";
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#A2-1");
			} catch (InvalidOperationException) {
				// success
			}
#if NET_4_0
			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = String.Empty;
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#A2-1");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			attr.ErrorMessageResourceName = null;
			
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#A3-1");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = String.Empty;
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			try {
				string s = attr.GetErrorMessageString ();
				Assert.Fail ("#A3-2");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "NoSuchProperty";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#A4");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "ErrorProperty2";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#A5");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "ErrorProperty3";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#A5");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "ErrorProperty4";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#A6");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "ErrorProperty5";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#A7");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "ErrorField1";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#B1");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "ErrorField2";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#B2");
			} catch (InvalidOperationException) {
				// success
			}
#endif

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "ErrorProperty1";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			Assert.IsNotNull (attr.GetErrorMessageString (), "#C1-1");
			Assert.AreEqual ("Error Message 1", attr.GetErrorMessageString (), "#C1-2");

			attr = new ValidateFooAttribute (ErrorMessageAccessor);
			Assert.IsNotNull (attr.GetErrorMessageString (), "#D1-1");
			Assert.AreEqual (TEST_ERROR_MESSAGE, attr.GetErrorMessageString (), "#D1-2");

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "ErrorProperty1";
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			Assert.IsNotNull (attr.GetErrorMessageString (), "#D1-3");
			Assert.AreEqual ("Error Message 1", attr.GetErrorMessageString (), "#D1-4");
#if NET_4_0
			attr.ErrorMessage = "Test Message";
			try {
				attr.GetErrorMessageString ();
				Assert.Fail ("#E1");
			} catch (InvalidOperationException) {
				// success
			}
#endif
		}
예제 #24
0
		public void ErrorMessageResourceType ()
		{
			var attr = new ValidateFooAttribute ();

			Assert.IsNull (attr.ErrorMessageResourceType, "#A1");

			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
			Assert.IsNotNull (attr.ErrorMessageResourceType, "#A2-1");
			Assert.AreEqual (typeof (FooErrorMessageProvider), attr.ErrorMessageResourceType, "#A2-2");
#if !NET_4_0
			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceName = "NoSuchProperty";
			
			try {
				attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
				Assert.Fail ("#A3");
			} catch (InvalidOperationException) {
				// success
			}
#endif
		}
예제 #25
0
		public void ErrorMessageResourceName ()
		{
			var attr = new ValidateFooAttribute ();

			Assert.IsNull (attr.ErrorMessageResourceName, "#A1");

			attr.ErrorMessageResourceName = "Test";
			Assert.IsNotNull (attr.ErrorMessageResourceName, "#A2-1");
			Assert.AreEqual ("Test", attr.ErrorMessageResourceName, "#A2-2");
#if NET_4_0
			attr.ErrorMessageResourceName = String.Empty;
			Assert.IsNotNull (attr.ErrorMessageResourceName, "#A3-1");
			Assert.AreEqual (String.Empty, attr.ErrorMessageResourceName, "#A3-2");

			attr.ErrorMessageResourceName = null;
			Assert.IsNull (attr.ErrorMessageResourceName, "#A3-1");
#else
			try {
				attr.ErrorMessageResourceName = String.Empty;
				Assert.Fail ("#A3-1");
			} catch (InvalidOperationException) {
				// success
			}

			attr = new ValidateFooAttribute ("Test");
			try {
				attr.ErrorMessageResourceName = String.Empty;
				Assert.Fail ("#A3-2");
			} catch (ArgumentException) {
				// success
			}

			attr = new ValidateFooAttribute ("Test");
			try {
				attr.ErrorMessageResourceName = null;
				Assert.Fail ("#A3-3");
			} catch (ArgumentException) {
				// success
			}

			attr = new ValidateFooAttribute ();
			attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);

			try {
				attr.ErrorMessageResourceName = "NoSuchProperty";
				Assert.Fail ("#A3-4");
			} catch (InvalidOperationException) {
				// success
			}
#endif
		}
예제 #26
0
		public void IsValid_Object ()
		{
			var attr = new ValidateFooAttribute ();

			AssertExtensions.Throws <NotImplementedException> (() => {
				// It calls IsValid (object, validationContext) which throws the NIEX, but when that overload is called directly, there's
				// no exception.
				//
				// at System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value, ValidationContext validationContext)
				// at System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value)
				// at MonoTests.System.ComponentModel.DataAnnotations.ValidationAttributeTest.IsValid_Object() in C:\Users\grendel\Documents\Visual Studio 2010\Projects\System.Web.Test\System.Web.Test\System.ComponentModel.DataAnnotations\ValidationAttributeTest.cs:line 450
				attr.IsValid (null);
			}, "#A1-1");
			
			AssertExtensions.Throws <NotImplementedException> (() => {
				attr.IsValid ("stuff");
			}, "#A1-2");
		}