public void ConfigurationModelValidator_TryValidateObject__when__no_errors__then__returns_false()
        {
            ConfigurationModelValidator v = new ConfigurationModelValidator();

            IEnumerable <ConfigurationModelValidationError> errors;
            bool isValid = v.TryValidateModel(
                new MyModel()
            {
                Max5Characters = "1234"
            }, out errors);

            Assert.IsTrue(isValid);
            Assert.IsNotNull(errors);
            Assert.AreEqual(0, errors.Count());
        }
        public void ConfigurationModelValidator_TryValidateObject__when__single_error__then__returns_false_and_well_formed_error()
        {
            ConfigurationModelValidator v = new ConfigurationModelValidator();

            IEnumerable <ConfigurationModelValidationError> errors;
            bool isValid = v.TryValidateModel(
                new MyModel()
            {
                Max5Characters = "123456789"
            }, out errors);

            Assert.IsFalse(isValid); // !
            Assert.IsNotNull(errors);
            Assert.AreEqual(1, errors.Count());
            Assert.AreEqual("The field Max5Characters must be a string with a maximum length of 5.", errors.First().ErrorMessage);
            Assert.AreEqual(nameof(MyModel.Max5Characters), errors.First().MemberNames.First());
        }
        public void ConfigurationModelValidator_TryValidateObject__when__a_nested_object_is_invalid__then__returns_false_and_well_formed_error()
        {
            ConfigurationModelValidator v = new ConfigurationModelValidator();

            IEnumerable <ConfigurationModelValidationError> errors;
            bool isValid = v.TryValidateModel(
                new MyModel()
            {
                Max5Characters = "12345",
                SingleLetter   = "a",
                AnotherModel   = new AnotherModel()
                {
                    SingleLetter = "Oops"
                }
            }, out errors);

            Assert.IsFalse(isValid); // !
            Assert.IsNotNull(errors);
            Assert.AreEqual(1, errors.Count());
            Assert.AreEqual("The field AnotherModel references an object that failed validation.", errors.First().ErrorMessage);
            Assert.AreEqual(nameof(MyModel.AnotherModel), errors.First().MemberNames.First());
        }