コード例 #1
0
        public void AsyncValidationTest()
        {
            var a1 = new A {
                name = "a1"
            };
            var validator = new AsyncValidator();

            var vEngine = new ValidationEngine {
                RulesProvider = new SimpleValidationRulesProvider <ValidationResult> {
                    validator
                }
            };

            EnqueueConditional(() => vEngine.EntitiesInError.Count() != 0);
            vEngine.Validate(new List <Entity> {
                a1
            });

            EnqueueCallback(
                () =>
            {
                Assert.IsTrue(vEngine.EntitiesInError.Single() == a1);
                Assert.IsTrue(a1.ValidationErrors.Count == 1);
            });
            Assert.IsFalse(a1.ValidationErrors.Count == 1);
            EnqueueTestComplete();
        }
コード例 #2
0
        public void PermutationsThreeParameterNamesValidatorTest2()
        {
            var a1 = new A {
                name = "a1"
            };
            var a2 = new A {
                name = "a2"
            };
            var a3 = new A {
                name = "a3"
            };
            var validator = new ValidationEngine {
                RulesProvider = new SimpleValidationRulesProvider <ValidationResult> {
                    new PermutationsThreeParameterNamesValidator()
                }
            };

            validator.Validate(new List <Entity> {
                a1, a2, a3
            });
            Assert.IsTrue(a1.ValidationErrors.Count == 6);
            Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a1a2a3"));
            Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a1a3a2"));
            Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a2a1a3"));
            Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a2a3a1"));
            Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a3a1a2"));
            Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a3a2a1"));

            Assert.IsTrue(a2.ValidationErrors.Count == 6);
            Assert.IsTrue(a3.ValidationErrors.Count == 6);
        }
コード例 #3
0
        public void AValidatorTest2()
        {
            AValidator.TestResult = ValidationResult.Success;
            b.name = "hello";
            var validator = new ValidationEngine {
                RulesProvider = new MEFValidationRulesProvider <ValidationResult>()
            };

            validator.Validate(b, "name", new List <Entity> {
                a, b, c, d
            });
            Assert.IsFalse(AValidator.TestResult == ValidationResult.Success);
            c.name = b.name;
            validator.Validate(c, "name", new List <Entity> {
                a, b, c, d
            });
            Assert.IsTrue(AValidator.TestResult == ValidationResult.Success);
        }
コード例 #4
0
 public IList <IValidationRule> BrokenEntryRules(IDictionary <string, object> variables)
 {
     if (EntryRules != null && variables != null)
     {
         var engine = new ValidationEngine(EntryRules, variables);
         engine.Validate();
         return(engine.BrokenRules);
     }
     return(new List <IValidationRule>());
 }
コード例 #5
0
        public void ValidationEngine_Validate_Inactive_ShouldFail()
        {
            ValidationRule <Customer> rule1 = new ValidationRule <Customer>(x => x != null, "Item cannot be null");
            ValidationRule <Customer> rule2 = new ValidationRule <Customer>(x => x.IsActive, "IsActive needs to be true");

            ValidationEngine <Customer> engine    = new ValidationEngine <Customer>(rule1, rule2);
            ValidationResult            runResult = engine.Validate(new Customer());

            Assert.IsTrue(!runResult.IsValid);
            Assert.IsTrue(runResult.Messages.Count() == 1);
            Assert.IsTrue(runResult.Messages.ElementAt(0) == "IsActive needs to be true");
        }
コード例 #6
0
        public void SingleEntityValidation1()
        {
            var validator = new ValidationEngine {
                RulesProvider = new SimpleValidationRulesProvider <ValidationResult> {
                    new AValidator()
                }
            };

            AValidator.TestResult = ValidationResult.Success;
            validator.Validate(a, "name");
            Assert.IsTrue(AValidator.TestResult == ValidationResult.Success);
        }
コード例 #7
0
        public void SingleEntityValidation2()
        {
            var a         = new A();
            var validator = new ValidationEngine {
                RulesProvider = new SimpleValidationRulesProvider <ValidationResult> {
                    new PermutationsOneParameterValidator()
                }
            };

            AValidator.TestResult = ValidationResult.Success;
            validator.Validate(a, "name");
            Assert.IsTrue(a.ValidationErrors.Count() == 1);
        }
        public void RegisterTest()
        {
            var validator = new ValidationEngine {
                RulesProvider = new MEFValidationRulesProvider <ValidationResult>()
            };

            RegisterUnregisterValidation.visited = false;

            validator.Validate(a, "B", new List <Entity> {
                a
            });
            Assert.IsTrue(RegisterUnregisterValidation.visited);
        }
コード例 #9
0
        public void ValidationEngine_ValidData_ShouldPass()
        {
            ValidationRule <Customer> rule1 = new ValidationRule <Customer>(x => x != null, "Item cannot be null");
            ValidationRule <Customer> rule2 = new ValidationRule <Customer>(x => x.IsActive, "IsActive needs to be true");

            ValidationEngine <Customer> engine    = new ValidationEngine <Customer>(rule1, rule2);
            ValidationResult            runResult = engine.Validate(new Customer {
                IsActive = true
            });

            Assert.IsTrue(runResult.IsValid);
            Assert.IsTrue(!runResult.Messages.Any());
        }
コード例 #10
0
        public void SignatureMatchTest()
        {
            var a = new A();

            a.B = new B();
            var validator = new ValidationEngine
            {
                RulesProvider = new SimpleValidationRulesProvider <ValidationResult> {
                    new SignatureValidator()
                }
            };

            validator.Validate(a, "name");
            Assert.IsFalse(a.HasValidationErrors);
        }
コード例 #11
0
        static void Main(string[] args)
        {
            var engine = new ValidationEngine();

            Users users = new Users
            {
                UserID = "fulano[at]site.com",
                UserName = "******",
                UserCountry = "Supercalifragilisticexpialidocious"
            };

            engine.Validate(users);

            foreach (var prop in engine.Error)
                foreach (var msg in prop.Value)
                    Console.WriteLine(string.Format("{0} {1}", prop.Key.Name, msg));

            Console.ReadKey();
        }
コード例 #12
0
        public void PermutationsThreeParameterNamesValidatorTest1()
        {
            var a1 = new A {
                name = "a1"
            };
            var a2 = new A {
                name = "a2"
            };
            var validator = new ValidationEngine {
                RulesProvider = new SimpleValidationRulesProvider <ValidationResult> {
                    new PermutationsThreeParameterNamesValidator()
                }
            };

            validator.Validate(new List <Entity> {
                a1, a2
            });
            Assert.IsTrue(a1.ValidationErrors.Count == 0);
            Assert.IsTrue(a2.ValidationErrors.Count == 0);
        }
コード例 #13
0
        private void InitializeHelper()
        {
            //Whenever the Value changes, validate this entity
            //DistinctUntilChanged to prevent StackOverflow on continuous validation
            Observable2.FromPropertyChangedPattern(this, x => x.LocationId).DistinctUntilChanged().ObserveOnDispatcher()
                .Subscribe(_ =>
                {
                    this.ValidationErrors.Clear();
                    var validator = new ValidationEngine { RulesProvider = new MEFValidationRulesProvider<ValidationResult>() };
                    validator.Validate(this);
                });

            Observable2.FromPropertyChangedPattern(this, x => x.Value).DistinctUntilChanged().ObserveOnDispatcher()
                 .Subscribe(_ =>
                 {
                     //When a LocationField's value is set automatically set the parent Service's
                     if (Value != null && Value.Client != null && OwnerServiceTemplate != null && OwnerServiceTemplate.OwnerService != null)
                     {
                         OwnerServiceTemplate.OwnerService.Client = Value.Client;
                     }
                 });
        }
コード例 #14
0
        static void Main(string[] args)
        {
            var engine = new ValidationEngine();

            Users users = new Users
            {
                UserID      = "fulano[at]site.com",
                UserName    = "******",
                UserCountry = "Supercalifragilisticexpialidocious"
            };

            engine.Validate(users);

            foreach (var prop in engine.Error)
            {
                foreach (var msg in prop.Value)
                {
                    Console.WriteLine(string.Format("{0} {1}", prop.Key.Name, msg));
                }
            }

            Console.ReadKey();
        }
コード例 #15
0
 public void ContinueValidation(ValidationContext context)
 {
     ValidationEngine.Validate(ValidationElementState.LinkedElement, context, this);
 }
コード例 #16
0
 private void OnValidate(ValidationContext context)
 {
     ValidationEngine.Validate(ValidationElementState.FirstElement, context, this);
 }
コード例 #17
0
 public void TestEngineInstance()
 {
     engine.Validate(this);
 }
コード例 #18
0
        public SchemaValidationResult Validate(Package package, TrustSchemaValidationOptions options = TrustSchemaValidationOptions.Full)
        {
            var engine = new ValidationEngine(_packageBinary, _derivationServiceFactory, _merkleStrategyFactory, _hashAlgorithmFactory, options, _validatorFactory);

            return(engine.Validate(package));
        }
コード例 #19
0
        public void ValidateWithNullInputTest()
        {
            // Act
            var result = _classUnderTest.Validate(null);

            // Assert
            result.IsValid.Should().BeFalse();
            result.ValidationError.Should().Be("model should not be null.");
        }