Пример #1
0
        public void SingleObjectPassesValidation()
        {
            string configurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"ConfigurableObjectValidatorFixture.config");

            TheClass a = new TheClass();

            a.Property = "valid";

            Validator validator = ValidationFactory.CreateValidatorFromConfiguration(typeof(TheClass),
                                                                                     "Rule Set",
                                                                                     new FileConfigurationSource(configurationFile));
            ValidationResults result = validator.Validate(a);

            Assert.IsTrue(result.IsValid);
        }
Пример #2
0
        public void SingleObjectFailsValidation()
        {
            string configurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"ConfigurableObjectValidatorFixture.config");

            TheClass a = new TheClass();

            a.Property = "bad";

            Validator validator = ValidationFactory.CreateValidatorFromConfiguration(typeof(TheClass),
                                                                                     "Rule Set",
                                                                                     new FileConfigurationSource(configurationFile));
            ValidationResults       result  = validator.Validate(a);
            List <ValidationResult> results = new List <ValidationResult>(result);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("Invalid property", results[0].Message);
        }