This class provides an implementation for the IDataErrorInfo interface which uses the validation classes found in the System.ComponentModel.DataAnnotations namespace.
Inheritance: IDataErrorInfo
        public void InvalidArgumentsTest()
        {
            AssertHelper.ExpectedException<ArgumentNullException>(() => new DataErrorInfoSupport(null));

            DataErrorInfoSupport dataErrorInfoSupport = new DataErrorInfoSupport(new MockEntity());
            string message;
            AssertHelper.ExpectedException<ArgumentException>(() => message = dataErrorInfoSupport["InvalidMember"]);
        }
        public Person()
        {
            // SQL Server Compact does not support entities with server-generated keys or values when it is used
            // with the Entity Framework. Therefore, we need to create the keys ourselves.
            // See also: http://technet.microsoft.com/en-us/library/cc835494.aspx
            Id = Guid.NewGuid();

            dataErrorInfoSupport = new DataErrorInfoSupport(this);
        }
        public void ValidateTest()
        {
            MockEntity mockEntity = new MockEntity();
            DataErrorInfoSupport dataErrorInfoSupport = new DataErrorInfoSupport(mockEntity);

            Assert.AreEqual("The Firstname field is required.", dataErrorInfoSupport["Firstname"]);
            Assert.AreEqual("The Lastname field is required.", dataErrorInfoSupport["Lastname"]);
            Assert.AreEqual("", dataErrorInfoSupport["Email"]);
            Assert.AreEqual("The Firstname field is required." + Environment.NewLine + "The Lastname field is required.",
                dataErrorInfoSupport.Error);

            mockEntity.Firstname = "Harry";
            mockEntity.Lastname = "Potter";
            Assert.AreEqual("", dataErrorInfoSupport["Lastname"]);
            Assert.AreEqual("", dataErrorInfoSupport.Error);

            mockEntity.Email = "InvalidEmailAddress";
            Assert.AreEqual("", dataErrorInfoSupport["Lastname"]);
            Assert.AreEqual(@"The field Email must match the regular expression '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$'.",
                dataErrorInfoSupport["Email"]);
            Assert.AreEqual(@"The field Email must match the regular expression '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$'.",
                dataErrorInfoSupport.Error);
        }
示例#4
0
 private void Initialize()
 {
     dataErrorInfoSupport = new DataErrorInfoSupport(this);
 }
示例#5
0
 public ValidationModel()
 {
     _dataErrorInfoSupport = new DataErrorInfoSupport(this);
 }