public void Validation_Nested_List_Null()
        {
            var obj = new NestedListValidationObject();

            obj.NestedObject = null;
            obj.GuidID       = Guid.NewGuid().ToString();

            var r     = new List <ValidationResult>();
            var valid = _validator(obj, new ValidationContext(obj), r, true);

            Assert.IsFalse(valid);
        }
示例#2
0
        public void Validate_NestedListObject_Invalid()
        {
            var obj = new NestedListValidationObject();

            obj.NestedObject = new List <BasicValidationObject>();
            obj.NestedObject.Add(BasicValidationObject.Valid);
            obj.NestedObject.Add(BasicValidationObject.Invalid);
            obj.NestedObject.Add(BasicValidationObject.Valid);
            var r = ValidationHandler.Validate(obj);

            Assert.IsTrue(r.Count() > 0);
            Assert.AreEqual(4, r.Count());
            Assert.IsNotNull(r.FirstOrDefault(x => x.MemberNames.Any(y => y == "NestedObject[1].EmailProperty")));
        }
        public void Validation_Nested_List_Cast_To_BaseType()
        {
            var input = "This is a long string that should not pass validation so we are going to continue rambling on and on for a while meow";
            var obj   = new NestedListValidationObject();

            obj.NestedObject.Add(new BasicValidationObject()
            {
                StringProperty = input, EmailProperty = "invalid email", IntegerProperty = 45
            });
            obj.NestedObject.Add(new ExtendedBasicValidationObject()
            {
                StringProperty = input, EmailProperty = "invalid email", IntegerProperty = 45
            });
            obj.GuidID = "Not A Guid";

            var results = ValidationHandler.Validate(obj);

            Assert.AreEqual("NestedObject[1].ExtendedProperty", results[4].MemberNames.First());
        }
        public void Validation_Nested_List_Invalid()
        {
            var input = "This is a long string that should not pass validation so we are going to continue rambling on and on for a while meow";
            var obj   = new NestedListValidationObject();

            obj.NestedObject.Add(new BasicValidationObject()
            {
                StringProperty = input, EmailProperty = "invalid email", IntegerProperty = 45
            });
            obj.GuidID = Guid.NewGuid().ToString();

            var r     = new List <ValidationResult>();
            var valid = _validator(obj, new ValidationContext(obj), r, true);

            if (this.GetType() == typeof(SystemValidationTests))
            {
                Assert.IsTrue(valid);
            }
            else
            {
                Assert.IsFalse(valid);
            }
        }