public void ValidatingCustomValidationPropertyFailOnPersonWithCustomValidationReturnsValidationError()
        {
            var person = new PersonWithCustomValidation();

            person.Name        = "Edgar";
            person.Description = "some description";
            person.Age         = 42;

            // property under test
            person.CustomValidationPropertyFail = "some contents that will fail";

            var validationResults = new List <ValidationResult>();
            var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(person);
            var result            = false;

            result = Validator.TryValidateObject(person, validationContext, validationResults, true);
            Assert.IsFalse(result);
            Assert.AreEqual(1, validationResults.Count());
            var validationResult = validationResults[0];

            Assert.AreEqual(1, validationResult.MemberNames.Count());
            var memberName = validationResult.MemberNames.First();

            Assert.AreEqual("CustomValidationPropertyFail", memberName);
        }
        public void ValidatingCustomValidationPropertyPassOnPersonWithCustomValidationReturnsTrue()
        {
            var person = new PersonWithCustomValidation();

            person.Name        = "Edgar";
            person.Description = "some description";
            person.Age         = 42;

            // property under test
            person.CustomValidationPropertyPass = "******";

            var validationResults = new List <ValidationResult>();
            var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(person);
            var result            = false;

            result = Validator.TryValidateObject(person, validationContext, validationResults, true);
            Assert.IsTrue(result);
        }
        public void ValidatingCustomValidationPropertyPassOnPersonWithCustomValidationReturnsTrue()
        {
            var person = new PersonWithCustomValidation();
            person.Name = "Edgar";
            person.Description = "some description";
            person.Age = 42;

            // property under test
            person.CustomValidationPropertyPass = "******";

            var validationResults = new List<ValidationResult>();
            var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(person);
            var result = false;
            result = Validator.TryValidateObject(person, validationContext, validationResults, true);
            Assert.IsTrue(result);
        }
        public void ValidatingCustomValidationPropertyFailOnPersonWithCustomValidationReturnsValidationError()
        {
            var person = new PersonWithCustomValidation();
            person.Name = "Edgar";
            person.Description = "some description";
            person.Age = 42;

            // property under test
            person.CustomValidationPropertyFail = "some contents that will fail";

            var validationResults = new List<ValidationResult>();
            var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(person);
            var result = false;
            result = Validator.TryValidateObject(person, validationContext, validationResults, true);
            Assert.IsFalse(result);
            Assert.AreEqual(1, validationResults.Count());
            var validationResult = validationResults[0];
            Assert.AreEqual(1, validationResult.MemberNames.Count());
            var memberName = validationResult.MemberNames.First();
            Assert.AreEqual("CustomValidationPropertyFail", memberName);
        }