Ejemplo n.º 1
0
        public void CustomAttributeValue()
        {
            var model = new ModelProperty2 {
                P1 = "Foo", P2 = "Foo"
            };

            var vc1 = new ValidationContext(model, null, null);
            var vr  = new List <ValidationResult>();
            var r   = Validator.TryValidateObject(model, vc1, vr, true);

            Assert.True(r);
            Assert.Equal(0, vr.Count);
        }
Ejemplo n.º 2
0
        public void CustomAttributeValue2()
        {
            var model = new ModelProperty2 {
                P1 = "Foo", P2 = "Bar"
            };

            var vc1 = new ValidationContext(model, null, null);
            var vr  = new List <ValidationResult>();
            var r   = Validator.TryValidateObject(model, vc1, vr, true);

            Assert.False(r);
            Assert.Equal(1, vr.Count);
            Assert.Equal("Test", vr[0].ErrorMessage);
        }