Exemplo n.º 1
0
        public void PropertyCannotBeCompared()
        {
            var model = new ModelPropertyDifferentType {
                P1 = "Foo", P2 = 2
            };

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

            Assert.Equal("'P2' and 'P1' cannot be compared.", ex.Message);
        }
Exemplo n.º 2
0
        public void PropertyDifferentTypeAreEqualValue()
        {
            var model = new ModelPropertyDifferentType {
                P1 = "2", P2 = 2
            };

            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);
        }
Exemplo n.º 3
0
        public void PropertyDifferentTypeAreNotEqualValue()
        {
            var model = new ModelPropertyDifferentType {
                P1 = "22", P2 = 2
            };

            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("'P2' and 'P1' do not match.", vr[0].ErrorMessage);
        }